Solved When Custom Events are Called?

Discussion in 'Plugin Development' started by JBoss925, Aug 18, 2014.

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

    JBoss925

    Hey guys, I've worked with events before but never in Bukkit. I understand handlers and registering them but what I don't understand is how to "call" an event in bukkit and/or choose when the handlers are notified an event has occurred.

    My current code:

    PortalEvent:
    Code:java
    1. package me.JBoss925.Portal.Listener;
    2.  
    3. import me.JBoss925.Portal.Portal;
    4. import org.bukkit.event.Event;
    5.  
    6. public abstract class PortalEvent extends Event {
    7.  
    8. protected Portal portal;
    9.  
    10. public PortalEvent(Portal portal, boolean async){
    11. super(async);
    12. this.portal = portal;
    13. }
    14.  
    15. public final Portal getPortal(){
    16. return this.portal;
    17. }
    18.  
    19. }


    PortalTeleportEvent:
    Code:java
    1. package me.JBoss925.Portal.Listener.Events;
    2.  
    3. import me.JBoss925.Portal.Listener.PortalEvent;
    4. import me.JBoss925.Portal.Portal;
    5. import org.bukkit.event.HandlerList;
    6.  
    7. public class PortalTeleportEvent extends PortalEvent {
    8. private static final HandlerList handlers = new HandlerList();
    9.  
    10. public PortalTeleportEvent(final Portal portalUsed){
    11. super(portalUsed, false);
    12. }
    13.  
    14.  
    15. @Override
    16. public HandlerList getHandlers() {
    17. return handlers;
    18. }
    19.  
    20. }
     
  2. Offline

    Lactem

    Bukkit.getServer().getPluginManager().callEvent(event);
     
    JBoss925 likes this.
  3. Offline

    br456

  4. Offline

    _LB

    Your events are not fully defined, you need to read the wiki as br456 pointed out.
     
  5. Offline

    JBoss925

    What do you mean? They're defined? I'm using a parent portal event that extends Event if that's what you're speaking to.
     
  6. Offline

    _LB

    There are more requirements to make an event than just to extend an event class. Read the wiki tutorial - you need the static and non-static functions to get the handler list for your event specifically.
     
  7. Offline

    JBoss925

    Oh, I gotcha. Fixed.
     
Thread Status:
Not open for further replies.

Share This Page