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

It is highly recommended to take a look at the Recommendations page after understanding the usage.

1. The library must be initialized. This is normally 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:

  • In the conventional way:

    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 necessary to call ApiDispatcher#unhook() when the plugin disables.

Clone this wiki locally