Registering events?

Discussion in 'Plugin Development' started by bodhistrontg, Nov 10, 2013.

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

    bodhistrontg

  2. Offline

    1Rogue Retired Staff

    1) Stop sleeping the main thread
    2) Only extend JavaPlugin in a single class
    3) Don't have a static main class variable
    4) Every class does not have to be a listener
    5) You never make any calls for registering events


    (I will elaborate more in a moment, doing laundry)
     
    MrSparkzz and Jake6177 like this.
  3. Offline

    bodhistrontg

    Now I have done every thing you said but how do you suppose i register the events for all the classes
     
  4. Offline

    maxben34

    Go to your main class and do bukkit.getPluginManager().registerEvents(this,this)-- put the name of each class inside parenthesis
     
  5. Offline

    bodhistrontg

    maxben34 How would i do that if my class names were Arena and TheScoreBoard and do i implements Listener for those classes?
     
  6. Offline

    maxben34

    You need implement listener on any class an event handler on it. register your events in the main class and instead of registerEvents(this,this) fill the args with plugin and the class name.
     
  7. Offline

    bodhistrontg

    maxben34 Umm like this
    Code:
        private static final Plugin Arena = null;
     
        private static final Listener Plugin = null;
     
        @Override
        public void onEnable() {
            getLogger().info("Plugin has been Enabled");
            Bukkit.getPluginManager().registerEvents(this,this);
            Bukkit.getPluginManager().registerEvents(Plugin,Arena);
        }
    
    No that wont work Someone help please!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  8. Offline

    maxben34

    Try ; this, Arena for the second registration.
     
  9. Offline

    bodhistrontg

    It says Arena cannot be resolved to a variable and i was going to create a constant but it turns out to look like this
    Code:java
    1. private static final Plugin Arena = null;

    So i have no clue what to do and as you can tell i'm new to bukkit plane java i'm okay but not bukkit.
     
  10. Offline

    maxben34

    You have to call the Arena class inside your main class so it knows what "Arena" means. I think you should take a look at the tutorial on using multiple classes.
     
  11. Offline

    bodhistrontg

    maxben34 I know how to do it it just says The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (Main, Arena)
     
  12. Offline

    1Rogue Retired Staff

    Code:java
    1. private static final Plugin Arena = null;

    :|
    :|||||||

    Solution: Don't use keywords that you don't know the meaning of. By using final and setting to null you can never set that variable, and by having it static you have a persist null object throughout the runtime of your plugin. What maxben is trying to say is that you need to register the class with a instance of the class:

    Code:java
    1. public class YourMain extends JavaPlugin {
    2.  
    3. private YourListener listener;
    4.  
    5. public void onEnable() {
    6. this.listener = new YourListener();
    7. this.getServer().getPluginManager().registerEvents(this.listener, this);
    8. }
    9.  
    10. }
     
    maxben34 likes this.
  13. Offline

    xTrollxDudex

    I think it's tyme to learn java and get yourself familiarized with he Bukkit API.
     
    L33m4n123 likes this.
  14. Offline

    bodhistrontg

    1Rogue
    So we have and it registers the classes Arena and TheScoreBoard
    Code:java
    1. private Arena listener;
    2. private TheScoreBoard l;
    3.  
    4. @Override
    5. public void onEnable() {
    6. getLogger().info("Plugin has been Enabled");
    7. Bukkit.getPluginManager().registerEvents(this,this);
    8. Bukkit.getPluginManager().registerEvents(this.listener,this);
    9. Bukkit.getPluginManager().registerEvents(this.l,this);
    10. }
     
  15. Offline

    1Rogue Retired Staff

    You never initialized the listener classes.
     
  16. Offline

    jasonderlo22

    Thought i'd find you here...
     
  17. Offline

    maxben34

    Nice to see you.
     
  18. Offline

    bodhistrontg

    1Rogue
    Then what was oh nvm how do you suppose i do that?
    Thank you everyone
     
  19. Offline

    bodhistrontg

    woulnt the listener class be this?
     
  20. bodhistrontg just do this
    Code:
    private static final Plugin Arena = null;
     
        private static final Listener Plugin = null;
     
        @Override
        public void onEnable() {
            getLogger().info("Plugin has been Enabled");
            Bukkit.getPluginManager().registerEvents(this,this);
            Bukkit.getPluginManager().registerEvents(new Arena(),new Scoreboard()<---- if thats ur class name!);
        }
     
  21. Offline

    1Rogue Retired Staff


    That would not work....

    Also don't suggest keywords if you don't know what they mean.


    You're very close, you made the correct usage on the .registerEvents(), but you need to set the variable to something first. For example:

    Code:java
    1. this.listener = new Arena(/* args */);
    2. this.l = new TheScoreboard(/* args */);
     
  22. Offline

    BungeeTheCookie

    Guys really...
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(new TheScoreBoard(), this);
    2. Bukkit.getServer().getPluginManager().registerEvents(new Arena(), this);
     
  23. Offline

    1Rogue Retired Staff


    And then you can no longer access the listener instances anywhere else in the plugin.
     
  24. Offline

    bodhistrontg

    I've tryed that that is what i had at the begineing but still nothing

    Now what is the args like what do they mean and what are they doing so i know what to put

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  25. Offline

    L33m4n123

    you wrote the classes yourself. You put whatever args in there the constructor requires
     
    1Rogue likes this.
  26. Offline

    jacklin213

    holy moley
     
    L33m4n123 likes this.
Thread Status:
Not open for further replies.

Share This Page