[Tutorial] Easy way to make your Custom Event

Discussion in 'Resources' started by BlazingBroGamer, Jun 11, 2014.

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

    BlazingBroGamer

    So this, right here, is in my opinion, the SIMPLEST way of making a custom event.

    Steps:
    1) Make your Custom Event class, and make sure it extends Event.
    Code:java
    1.  
    2. public class CustomEventClass extends Event{
    3.  
    4. }
    5.  


    2) Now, you need to make some Handlers, or else it is going to give you errors. (Taken from Here)
    Code:java
    1.  
    2. private static final HandlerList handlers = new HandlerList();
    3.  
    4. public HandlerList getHandlers() {
    5. return handlers;
    6. }
    7.  
    8. public static HandlerList getHandlerList() {
    9. return handlers;
    10. }
    11.  


    3) Now that you have your handlers, make your specific needs. For example, if you need the Player when you call this event, you need to do something like this:
    Code:java
    1.  
    2. //Put what you need to put, in replace of the Player.
    3. public CustomEventClass(Player p){
    4. p.sendMessage("The Event has Activated!");
    5. }
    6.  


    4) Now, for calling the Event. You need to get the plugin manager, and call the Event from there.
    Code:java
    1.  
    2. //Don't forget the Arguments! If you don't get the arguments from here, it will fail.
    3. plugin.getServer().getPluginManager().callEvent(new CustomEventClass(Player));
    4.  


    5) Now that your done, you can modify the Event, to make it return anything when the Event is called.
    Code:java
    1.  
    2. //You can change this when the event is called, as Player is in the arguments.
    3. Player p;
    4.  
    5. public CustomEventsClass(Player p){
    6. this.p = p;
    7. }
    8.  
    9. //This is in the Custom Events Class again!
    10. public Player getPlayer(){
    11.  
    12. }
    13.  


    There you go, thats the most SIMPLEST way, in my opinion, to make an Event.
     
  2. Offline

    ZeusAllMighty11

  3. Offline

    BlazingBroGamer

    ZeusAllMighty11 I was thinking about that while I was looking at it...
     
  4. Offline

    BungeeTheCookie

    So why did you make this thread?
     
    Chlorek likes this.
Thread Status:
Not open for further replies.

Share This Page