Main Class Help (Remaking Blockey)

Discussion in 'Plugin Development' started by horse2950, Jul 10, 2012.

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

    horse2950

    Hello i got perms to re-make bukkit and keep it updated so i tried everything i could and used the code bellow and still coulden't Get it to work... i belive its somthing wrong in the mainclass. The 2 classes in the src/me/horse2950/Blockey are Blockey.java and BlockeyPlayerListener.java

    Here is my code...




    here is this if it makes it easyer
    http://pastie.org/4235411
    http://pastebin.com/AX3j87K2
     
  2. Offline

    r0306

    horse2950 likes this.
  3. Offline

    horse2950

    o okay thxs ill keep this fourm up so i can test and reffer back 2 it if it fails

    okay ima bit lost....
    Here is my player listener

    and here is what im confussed about...
    Before:
    Dose it go like This?

    pm.registerEvent(this.playerListener.PlayerPickupItem, this);

    can u help r0306

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. No need to register each event... just register the entire class:

    Code:
    pm.registerEvents(new YourListener(), this);
    And the event methods must have @EventHandler before them.

    Also, stop posting code in quote, it looks *really* bad, post it in code or syntax=java tags instead.
     
  5. Offline

    horse2950

    okay

    Digi okay but if i have more that 1 Event Such as Player_Move and Player_Drop_Item then would i need to create a Listener for each?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. No, they can all be in a single listener class... they can all be in your main class as well, for that you would use "this" as first argument for registerEvents().
     
  7. Offline

    horse2950

    o um okay? im still confussed but i think i can work around this, XD this is my first plugin

    Digi okay i tried doing that which i still couldent figure out how Becuase...
    @Override


    publicvoid onDisable() {

    PluginManager pm = getServer().getPluginManager();

    pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM,
    playerListener,Event.Priority.Normal,this);

    pm.registerEvent(Event.Type.PLAYER_MOVE,
    playerListener,Event.Priority.Normal,this);

    pm.registerEvent(Event.Type.PLAYER_DROP_ITEM,
    playerListener,Event.Priority.Normal,this);

    PluginDescriptionFile pdfFile =
    this.getDescription();


    this.logger.info(pdfFile.getName() + " Has Been Disabled");

    }


    Thats how it looked like before i did new Priority btw.. So like with the new how would i set it so that for each Pm.registerEvent it would link to it in the BlockeyPlayerListener? i mean can u give me a example of say the Player_Move? The Player Listener is in one of the comments above...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  8. Well, let me explain it like this...

    Events are triggered by Bukkit, so you must inform Bukkit where your events are at, by using registerEvents() will notify Bukkit in what class Bukkit should look for the @EventHandler annotatinos and trigger the events.

    Events can be as many as you want and in any class that implements Listener.

    So if you implement Listener in your main class, you can put some events in that class and use registerEvents(this, this) to register this class as a listener class :)

    This isn't accurate to the way Bukkit works but it's a start to eliminate the confusion :}

    EDIT: Priority is set in @EventHandler, like so:
    @EventHandler(priority = EventPriority.NORMAL)
    You can also ignore the cancelled events:
    @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)


    EDIT #2: here's a simple example of an event in your main class:
    Code:
    public void onEnable()
    {
        getPluginManager().registerEvents(this, this);
    }
    
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void whateverNameYouWant(BlockBreakEvent event)
    {
        // ...
    }
     
  9. Offline

    horse2950

    Thankyou XD i just figured that out was about to reply and then my internet crashed, good news, MY FIRST PLUGIN IS COMPLETE AND WORKS!!!!
     
Thread Status:
Not open for further replies.

Share This Page