Eventing redone, revision 1

This commit is contained in:
durron597
2010-12-28 10:48:03 +08:00
committed by Nathan Adams
parent 2e88ac9e9f
commit 37f3b8fe58
8 changed files with 214 additions and 44 deletions

View File

@@ -1,16 +1,20 @@
package org.bukkit.event;
import org.bukkit.Player;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerEvent;
/**
* Represents an event
*/
public abstract class Event {
private final Server server;
private final Type type;
protected Event(final Server instance) {
protected Event(final Server instance, final Type type) {
server = instance;
this.type = type;
}
/**
@@ -21,6 +25,14 @@ public abstract class Event {
return server;
}
/**
* Gets the Type of this event
* @return Server which this event was triggered on
*/
public Type getType() {
return type;
}
/**
* Represents an events priority
*/
@@ -50,4 +62,125 @@ public abstract class Event {
*/
Lowest
}
public enum Category {
PLAYER,
BLOCK,
ITEM,
ENVIRONMENT,
ENTITY,
VEHICLE,
INVENTORY,
SIGN,
CUSTOM;
}
public enum Type {
/**
* Player Events
*/
LOGINCHECK (Category.PLAYER),
JOIN (Category.PLAYER),
CHAT (Category.PLAYER),
COMMAND (Category.PLAYER),
SERVERCOMMAND (Category.PLAYER),
BAN (Category.PLAYER),
IPBAN (Category.PLAYER),
KICK (Category.PLAYER),
QUIT (Category.PLAYER),
PLAYER_MOVE (Category.PLAYER),
ARM_SWING (Category.PLAYER),
TELEPORT (Category.PLAYER),
/**
* Block Events
*/
BLOCK_DESTROYED (Category.BLOCK),
BLOCK_BROKEN (Category.BLOCK),
BLOCK_PLACE (Category.BLOCK),
BLOCK_RIGHTCLICKED (Category.BLOCK),
REDSTONE_CHANGE (Category.BLOCK),
BLOCK_PHYSICS (Category.BLOCK),
/**
* Item Events
*/
ITEM_DROP (Category.ITEM),
ITEM_PICK_UP (Category.ITEM),
ITEM_USE (Category.ITEM),
/**
* Environment Events
*/
IGNITE (Category.ENVIRONMENT),
FLOW (Category.ENVIRONMENT),
EXPLODE (Category.ENVIRONMENT),
LIQUID_DESTROY (Category.ENVIRONMENT),
/**
* Non-player Entity Events
*/
MOB_SPAWN (Category.ENTITY),
DAMAGE (Category.ENTITY),
HEALTH_CHANGE (Category.ENTITY),
ATTACK (Category.ENTITY), // Need to look into this category more
/**
* Vehicle Events
*/
VEHICLE_CREATE (Category.VEHICLE),
VEHICLE_UPDATE (Category.VEHICLE),
VEHICLE_DAMAGE (Category.VEHICLE),
VEHICLE_COLLISION (Category.VEHICLE),
VEHICLE_DESTROYED (Category.VEHICLE),
VEHICLE_ENTERED (Category.VEHICLE),
VEHICLE_POSITIONCHANGE (Category.VEHICLE),
/**
* Inventory Events
*/
OPEN_INVENTORY (Category.INVENTORY),
/**
* Sign Events (Item events??)
*/
SIGN_SHOW (Category.SIGN),
SIGN_CHANGE (Category.SIGN),
/**
* Custom Event Placeholder?
*/
CUSTOM_EVENT (Category.CUSTOM);
private Category category;
private Type(Category category) {
this.category = category;
}
public Category getCategory() {
return category;
}
}
public static Event eventFactory(Server server, Event.Type type, Object[] data) throws EventException {
switch (type.getCategory()) {
case PLAYER:
if (data.length < 1 || !(data[0] instanceof Player)) {
throw new EventException("Data is not a Player!");
}
return new PlayerEvent(server, type, (Player) data[0]);
// TODO: IMPLEMENT ME
case BLOCK:
return null;
case ITEM:
return null;
case ENVIRONMENT:
return null;
case ENTITY:
return null;
case VEHICLE:
return null;
case INVENTORY:
return null;
case SIGN:
return null;
case CUSTOM:
return null;
default:
return null;
}
}
}