Added custom event support.
This commit is contained in:
parent
739142b42e
commit
4a9c7e0712
5
src/main/java/org/bukkit/event/CustomEventListener.java
Normal file
5
src/main/java/org/bukkit/event/CustomEventListener.java
Normal file
@ -0,0 +1,5 @@
|
||||
package org.bukkit.event;
|
||||
|
||||
public interface CustomEventListener {
|
||||
public void onCustomEvent(Event event);
|
||||
}
|
@ -6,19 +6,42 @@ package org.bukkit.event;
|
||||
*/
|
||||
public abstract class Event {
|
||||
private final Type type;
|
||||
private final String name;
|
||||
|
||||
protected Event(final Type type) {
|
||||
exAssert(type != null, "type is null");
|
||||
exAssert(type != Type.CUSTOM_EVENT, "use Event(String) to make custom events");
|
||||
this.type = type;
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
protected Event(final String name) {
|
||||
exAssert(name != null, "name is null");
|
||||
this.type = Type.CUSTOM_EVENT;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Type of this event
|
||||
* @return Server which this event was triggered on
|
||||
* @return Event type that this object represents
|
||||
*/
|
||||
public Type getType() {
|
||||
public final Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private void exAssert(boolean b, String s) {
|
||||
if(!b) throw new IllegalArgumentException(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event's name. Should only be used if getType returns null.
|
||||
* @return
|
||||
*/
|
||||
public final String getEventName() {
|
||||
if(type!=Type.CUSTOM_EVENT) return type.toString();
|
||||
else return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an events priority
|
||||
*/
|
||||
@ -83,7 +106,7 @@ public abstract class Event {
|
||||
BLOCK_PHYSICS (Category.BLOCK),
|
||||
BLOCK_PLACED (Category.BLOCK),
|
||||
BLOCK_RIGHTCLICKED (Category.BLOCK),
|
||||
REDSTONE_CHANGE (Category.BLOCK);
|
||||
REDSTONE_CHANGE (Category.BLOCK),
|
||||
|
||||
|
||||
/**
|
||||
@ -124,10 +147,12 @@ public abstract class Event {
|
||||
* Sign Events (Item events??)
|
||||
|
||||
SIGN_SHOW (Category.SIGN),
|
||||
SIGN_CHANGE (Category.SIGN);
|
||||
SIGN_CHANGE (Category.SIGN)
|
||||
*/
|
||||
|
||||
private Category category;
|
||||
CUSTOM_EVENT (Category.CUSTOM);
|
||||
|
||||
private final Category category;
|
||||
|
||||
private Type(Category category) {
|
||||
this.category = category;
|
||||
|
@ -12,6 +12,7 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.CustomEventListener;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
@ -118,6 +119,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
trueListener.onBlockFlow((BlockFromToEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if(listener instanceof CustomEventListener) {
|
||||
if(event.getType()==Event.Type.CUSTOM_EVENT)
|
||||
((CustomEventListener)listener).onCustomEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user