mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 05:11:27 +01:00
Added custom event support.
By: Lymia <lymiahugs@gmail.com>
This commit is contained in:
parent
4937cffabb
commit
aeb55da0e1
@ -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 {
|
public abstract class Event {
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
protected Event(final Type type) {
|
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.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
|
* 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;
|
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
|
* Represents an events priority
|
||||||
*/
|
*/
|
||||||
@ -83,7 +106,7 @@ public abstract class Event {
|
|||||||
BLOCK_PHYSICS (Category.BLOCK),
|
BLOCK_PHYSICS (Category.BLOCK),
|
||||||
BLOCK_PLACED (Category.BLOCK),
|
BLOCK_PLACED (Category.BLOCK),
|
||||||
BLOCK_RIGHTCLICKED (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 Events (Item events??)
|
||||||
|
|
||||||
SIGN_SHOW (Category.SIGN),
|
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) {
|
private Type(Category category) {
|
||||||
this.category = category;
|
this.category = category;
|
||||||
|
@ -12,6 +12,7 @@ import java.util.jar.JarEntry;
|
|||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.event.CustomEventListener;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
@ -118,6 +119,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
trueListener.onBlockFlow((BlockFromToEvent)event);
|
trueListener.onBlockFlow((BlockFromToEvent)event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if(listener instanceof CustomEventListener) {
|
||||||
|
if(event.getType()==Event.Type.CUSTOM_EVENT)
|
||||||
|
((CustomEventListener)listener).onCustomEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user