Create a class for the event e.g. 'MyCustomEvent': Code:java package me.iffa.bananaspace; import org.bukkit.event.Cancellable;import org.bukkit.event.Event; public class MyCustomEvent extends Event implements Cancellable { private String text; private boolean cancelled; public MyCustomEvent(String event, String text) { super(event); this.text = text; } public String getText() { return this.text; } public void setText(String text) { this.text = text; } public boolean isCancelled() { return cancelled; } public void setCancelled(boolean bln) { this.cancelled = bln; } } Once you have that you can make a listener class for it: Code:java package me.iffa.bananaspace; import org.bukkit.event.CustomEventListener;import org.bukkit.event.Event;import org.bukkit.event.Listener; public class MyCustomEventListener extends CustomEventListener implements Listener { /** * This is called when your custom event is triggered. * * @param event Event data */ public void onMyCustomEvent(MyCustomEvent event) { } /** * This is required for your events to be triggered correctly. * * @param event Event data */ @Override public void onCustomEvent(Event event) { if (event instanceof MyCustomEvent) { onMyCustomEvent((MyCustomEvent) event); } // you can continue this with else if's as long as you like (if you have many events) }} As you can see, making the listener and events is pretty easy. Now to calling your custom event from your code (an example of a main class that calls the event everytime it disables and enables): Code:java package me.iffa.bananaspace; import org.bukkit.plugin.java.JavaPlugin; public class MyPlugin extends JavaPlugin { @Override public void onDisable() { String text = "disabled"; /* Event calling start */ MyCustomEvent event = new MyCustomEvent("MyCustomEvent", text); getServer().getPluginManager().callEvent(event); // Example of cancelling the actions after this if the event was cancelled. if (event.isCancelled()) { return; } /* Event calling end */ System.out.println(event.getText()); } @Override public void onEnable() { String text = "enabled"; /* Event calling start */ MyCustomEvent event = new MyCustomEvent("MyCustomEvent", text); getServer().getPluginManager().callEvent(event); // Example of cancelling the actions after this if the event was cancelled. if (event.isCancelled()) { return; } /* Event calling end */ System.out.println(event.getText()); }}
So, is there any need in making it fire when the plugin is launched, or can I just fire it whenever I want?