Solved Need help registering events

Discussion in 'Spigot Plugin Development' started by Nicbo, Feb 8, 2020.

  1. Hey guys I'm making a new minigame plugin and I need help registering the events.

    So the way I set it up was having an abstract minigame class that every minigame extends. This abstract class implements listener and all the minigame have events inside them. Everytime an event is hosted it makes a new minigame.

    Code (Java):
    public void hostMinigame() { //example
        currentGame = new TDM();
    }
    Just wondering how I would register events inside the TDM class for example.

    Thanks!
     
  2. Just the way you would register any event? What is hindering you from just using PluginManager#registerEvents(...)?
     
  3. So even if I make a new TDM object every time I can still just register it once in the beginning?
     
  4. Sure. But you should only register one event since registering a new event causes the HandlerList to bake all events again. I would suggest to put your events in a completely different scope and referencing any objects in that different events-spectrum.
     
  5. So have the events outside the minigame class?
     
  6. Yes.
     
  7. Sorry, I just remembered why I wanted the events in the minigame class. I need to access variables from the class that change everytime depending on the minigame. Is there any possible way to register these events in the same class?
     
  8. Again, you can do that. But you are better of having a reference to your TDM in your events-class (or something like that)
     
  9. It would be best to have getters and setters etc and have listeners separate and have them use the methods you create to access/modify the data.
     
    • Like Like x 2
  10. Ok thanks a lot guys