Lots of listeners

Discussion in 'Plugin Development' started by Bartoke, Nov 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Bartoke

    Hey y'all,

    I'm redoing a skills system and each skill is activated differently. Up until now, I handled events by checking which skills are listening which events and then firing the methods from the skills that handle the event that was triggered.

    Now, I've noticed that other plugins just register a listener per skill. Do lots of listeners, say, 50 skills - so 50 listeners a plugin, have a dramatic effect on the server's tick p/s or cpu/ram usage? I haven't had a chance to test.

    Thanks!
     
  2. Offline

    fireblast709

    Bartoke why not one listener that checks the active skill / which item the player is holding and act accordingly?
     
  3. I would do something like this:
    Code:java
    1. @EventHandler
    2. public void onItemSwitch(PlayerItemHeldEvent event) {
    3. Material material = event.getPlayer().getInventory().getItem(event.getNewSlot()).getType();
    4. switch(material) {
    5. case STONE: handleSpellStone();
    6. case DIRT: handleSpellDirt();
    7. ...
     
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page