Skip to content
Ckblck edited this page Dec 17, 2021 · 4 revisions

1. The library must be initialized. Normally this is done within your plugin's onEnable method.

@Override
public void onEnable() {
    Armoury armoury = new Armoury(this);

    armoury.start();
}

2. You may listen to the events in two alternative ways:

  • By listening to the event:

    Listener listener = new Listener() {
        @EventHandler
        public void onArmorModification(PlayerArmorChangeEvent event) {
            Player player = event.getPlayer();
               
            // ... further code
        }
    };
    
    Bukkit.getPluginManager().registerEvents(listener, this);
  • By registering a hook:

    // ... previous code
    
    armoury.start();
    
    ApiDispatcher dispatcher = armoury.getDispatcher();
    
    dispatcher.hook(this, ((player, wornArmor) ->
            Bukkit.broadcastMessage(
                    String.format("Player %s has had his armor modified!",
                            player.getName()
                    )
            )
    ));

    Note: it is not needed to use ApiDispatcher#unhook() when the plugin disables.

Clone this wiki locally