Solved Register listener for more objects

Discussion in 'Plugin Development' started by Tomasko, Mar 7, 2014.

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

    Tomasko

    Hello, I'm creating minigame plugin and I want to register listener for all objects of Game() class. How can I do it? Thanks for answers :)
     
  2. Offline

    Wolfey

    You just have to register the class once and you're done.
     
  3. Offline

    Tomasko

    Please, how can I do it?
    onEnable
    Code:java
    1. public void onEnable() {
    2. sm.setup(this);
    3. Bukkit.getServer().getPluginManager().registerEvents(new Game(), this);
    4.  
    5. hmap.put("GameA", new Game());
    6. hmap.put("GameB", new Game());
    7. hmap.put("GameC", new Game());
    8. }

    Game class
    Code:java
    1. public class Game implements Listener {
    2. SettingsManager sm = new SettingsManager();
    3. public static Game pointer;
    4.  
    5.  
    6. private int phase;
    7. private String name;
    8. private String[] players;
    9. private Location[] ports; //1 red, 2 yellow, 3 blue, 4 green , 5 lobby, 6 quit
    10. @EventHandler
    11. public void onBreak(BlockBreakEvent e) {
    12. Bukkit.getServer().broadcastMessage("debug");
    13. }
    14.  
    15. }

    Whenever I break block I see only 1 "debug", what is wrong?
     
  4. Offline

    Mathias Eklund

    Thats all you have set it to do?.. If I am not mistaken. Can't see anything else.
     
  5. Offline

    Tomasko

    I know I'm doing something wrong. I want to store the arenas in HashMap, so if possible, I need register listener for each object. That is, if possible, please advice how to do.
     
  6. Offline

    TemphisEquinox

    You registered the listeners in Game class, but there aren't any listeners listed. First code some Events and then you can register the Events in Game class

    Edit:
    Sorry, my fault. It should work.
     
  7. Offline

    Tomasko

    Any other ideas? :/
     
  8. Offline

    Tomasko

  9. Offline

    Rocoty

    If you want to register all instances you have to register all instances, not a new separate instance. Loop through the hmap and register all values.
     
  10. Offline

    Tomasko

    Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page