[Solved] Register Events - Don't get it

Discussion in 'Plugin Development' started by recon88, Feb 21, 2012.

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

    recon88

    I'm still using the old event system because i can't figure out how to switch to the new one:
    Someone can give me an example?

    I got something like that:

    HTML:
    public void onEnable() {
     
            pm.registerEvent(org.bukkit.event.Event.Type.PAINTING_BREAK, entityListener, org.bukkit.event.Event.Priority.Low, this);
            pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this);
     
    }
    So what i have to change?
     
  2. Offline

    dillyg10

    Use this genereral syntax:

    getServer().getPluginManager().registerEvents(new yourevent(), this);

    ta-dah!
    Oh and make sure that your class implements Listner (your event class at least)
     
  3. Offline

    recon88

    Still doing sth wrong. The "ARGEntityListener" on Line 3 is wrong. Where's the mistake? Followed the Tutorial here on Forums a bit.

    HTML:
    public class ARGEntityListener implements Listener {
     
        public ARGEntityListener() {
            Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
            }
     
        @EventHandler(priority = EventPriority.LOW)
        public void onPaintingPlace(PaintingPlaceEvent event) { 
     
        }
    }
     
  4. Offline

    dillyg10

    Register the event in your onEnable :p
     
  5. Offline

    recon88

    Sorry, don't get it >.<
    Totally confused
     
  6. Offline

    Firefly

    PHP:
    @EventHandler
     
    public void yourEventDerp(PlayerMoveEvent event) {
     
      
    //Bla bla bla
     
    }
     
     
    public 
    onEnable() {
     
    Bukkit.getServer().getPluginManager().registerEvents(thisthis);
     
    }
    This should work (I'm pretty sure that's how I do it in my plugins, but I don't have my code in front of me atm :p)
     
  7. Offline

    dillyg10

    Firefly Thanks for writing the code that I was too lazy to write :D
     
  8. Offline

    Firefly

  9. Offline

    recon88

    Doesn't work, sorry

    This seems to be wrong:
    PHP:
    Bukkit.getServer().getPluginManager().registerEvents(thisthis);

     
  10. Offline

    Firefly

    Again, I don't have the proper code. Let me consult something real quick and I'll get back to you..

    [EDIT] If your listener IS your main class use:

    getServer().getPluginManager().registerEvents(this, this);

    if not:

    plugin.getServer().getPluginManager().registerEvents(this, plugin);

    Hope this helps!

    -Firefly
     
  11. Offline

    recon88

    So what i got now seems to be right. If there's any mistake please let me know

    Main:
    PHP:
      public class ARG extends JavaPlugin implements Listener {
     
    public 
    void onEnable() {
     
          
    getServer().getPluginManager().registerEvents(thisthis);
     
          }
    }

    Listener:
    PHP:
    public class ARGEntityListener implements Listener {
     
        @
    EventHandler
        
    public void onEntityDamage(EntityDamageEvent event){
      
    BLA
    BLA
    }
     
    }
     
  12. Offline

    nisovin

    No. You're passing "this" as the listener, but you've defined your events in a separate class. You either need to move your events into your main class, or change the first "this" to an instance of your listener class.
     
  13. Offline

    recon88

    Ok once again. This seems to be correct for R5 now.

    Main:
    PHP:
    // Listener Classes
    private final ARGVehicleListener vehicleListener = new ARGVehicleListener(this);
     
    // onEnable Stuff
    public void onEnable() {
    PluginManager pm getServer().getPluginManager();
     
    //Register Events
    pm.registerEvents(this.vehicleListenerthis);
     
    }
    }
    Listener:
    PHP:
    public class ARGVehicleListener implements Listener {
     
    @
    EventHandler
    public void onVehicleDamage(VehicleDamageEvent event){
    // code stuff here //
    }
    }
     
  14. Offline

    dillyg10

    you don't need to define the object for vehicle listener in the class, just do new veichleListner(), this
     
  15. Offline

    recon88

    Ok thanks =)
    So i finally got it now
     
Thread Status:
Not open for further replies.

Share This Page