Registering multiple events?

Discussion in 'Plugin Development' started by Antigrate, Mar 20, 2014.

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

    Antigrate

    How do you register multiple events to your main? For example, I have this right now:

    Code:java
    1. package me.antigrate.oblivioncombat;
    2.  
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class OblivionCombat extends JavaPlugin implements Listener
    7. {
    8. public void onDisable()
    9. {
    10. }
    11.  
    12. public void onEnable()
    13. {
    14. getServer().getPluginManager().registerEvents(new ArcherCorrosiveShot(), this);
    15. }
    16. }


    But there's more classes I need to register, how would I do that?
     
  2. Offline

    Venexor

    getServer().getPluginManager().registerEvents(new ArcherCorrosiveShot(), new <name of class>, new <name of another class>, this)

    You can keep on registering the events like that for all your classes.
     
  3. Offline

    unon1100

    If you use the registerEvents(); method (which you did) it registers all of the events in that class.
     
  4. Offline

    JBoss925

    If the class was named "Example", you'd do:
    Code:java
    1. getServer().getPluginManager().registerEvents(new ArcherCorrosiveShot(), new Example(), this);
     
  5. Offline

    Antigrate

    JBoss925 Venexor unon1100


    I did exactly that but Eclipse throws an error at me. "The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments"

    Code:java
    1. package me.antigrate.oblivioncombat;
    2.  
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class OblivionCombat extends JavaPlugin implements Listener
    7. {
    8. public void onDisable()
    9. {
    10. }
    11.  
    12. public void onEnable()
    13. {
    14. getServer().getPluginManager().registerEvents(new ArcherCorrosiveShot(), new AssassinIntervention(), this);
    15. }
    16. }
     
  6. Offline

    Barinade

    Do they both implement Listener?
     
  7. Offline

    Antigrate


    Yep.

    Code:java
    1. public class AssassinIntervention implements Listener
     
  8. Offline

    Barinade

    Try registering them on different lines, I've never seen more than one on a single line, and the constructors in the docs don't show the ability to do it
     
  9. Offline

    Antigrate


    Thank you! That worked, one more problem I have if you don't mind and then I'll be off your ass. I'm trying to use cooldowns for abilities. This is my cooldown class.

    Code:java
    1. package me.antigrate.oblivioncombat;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.scheduler.BukkitRunnable;
    8.  
    9. public class Cooldown
    10. {
    11.  
    12. public OblivionCombat p;
    13.  
    14. public Cooldown(OblivionCombat i)
    15. {
    16. p = i;
    17. }
    18.  
    19. int task;
    20.  
    21. public void setCooldownLength(Player player, int time,
    22. HashMap<String, Integer> hashmap)
    23. {
    24. hashmap.put(player.getName(), time);
    25. }
    26.  
    27. public int getTimeLeft(Player player, HashMap<String, Integer> hashmap)
    28. {
    29. int time = hashmap.get(player.getName());
    30. return time;
    31. }
    32.  
    33. public void startCooldown(final Player player,
    34. final HashMap<String, Integer> hashmap)
    35. {
    36. task = Bukkit.getServer().getScheduler()
    37. .scheduleSyncRepeatingTask(p, new BukkitRunnable()
    38. {
    39. public void run()
    40. {
    41. int time = hashmap.get(player.getName());
    42. if (time != 0)
    43. {
    44. hashmap.put(player.getName(), time - 1);
    45. } else
    46. {
    47. hashmap.remove(player.getName());
    48. Bukkit.getServer().getScheduler().cancelTask(task);
    49. }
    50. }
    51. }, 0L, 20L);
    52. }
    53.  
    54. }


    And I'm trying to implement that into another class, and I'm doing this:

    Code:java
    1. public class WarriorWarCry extends Cooldown implements Listener


    Eclipse throws an error at me though, saying:

    Implicit super constructor Cooldown() is undefined for default constructor. Must define an explicit constructor

    Any ideas? Thanks again!
     
  10. Offline

    JBoss925

    Yeah, hmmm. Idk I used to do it like that a while ago… I might have had some API thing for it. I would just try registering it on different lines I guess.
     
  11. Offline

    Charliechumbuck

    Venexor
    I tried to this thing but it didn't work
     
Thread Status:
Not open for further replies.

Share This Page