Changed event registration to catch errors.

This commit is contained in:
sk89q 2011-06-25 21:41:18 -07:00
parent ba376a6326
commit b7dd63ebd9
5 changed files with 121 additions and 38 deletions

View File

@ -70,22 +70,28 @@ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_FROMTO, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_IGNITE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_PHYSICS, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.SIGN_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.LEAVES_DECAY, this, Priority.High, plugin);
registerEventSafe("SNOW_FORM", Priority.High);
registerEventSafe("BLOCK_FORM", Priority.High);
registerEventSafe("BLOCK_SPREAD", Priority.High);
registerEvent("BLOCK_DAMAGE", Priority.High);
registerEvent("BLOCK_BREAK", Priority.High);
registerEvent("BLOCK_FROMTO", Priority.Normal);
registerEvent("BLOCK_IGNITE", Priority.High);
registerEvent("BLOCK_PHYSICS", Priority.Normal);
registerEvent("BLOCK_PLACE", Priority.High);
registerEvent("BLOCK_BURN", Priority.High);
registerEvent("SIGN_CHANGE", Priority.High);
registerEvent("REDSTONE_CHANGE", Priority.High);
registerEvent("SNOW_FORM", Priority.High);
registerEvent("LEAVES_DECAY", Priority.High);
registerEvent("BLOCK_FORM", Priority.High);
registerEvent("BLOCK_SPREAD", Priority.High);
}
private void registerEventSafe(String typeName, Priority priority) {
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
* @param priority
*/
private void registerEvent(String typeName, Priority priority) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();

View File

@ -41,12 +41,18 @@
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import java.util.logging.Logger;
/**
* Listener for entity related events.
*
* @author sk89q
*/
public class WorldGuardEntityListener extends EntityListener {
/**
* Logger for messages.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
@ -65,14 +71,30 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.ENTITY_INTERACT, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREEPER_POWER, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PIG_ZAP, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PAINTING_BREAK, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PAINTING_PLACE, this, Priority.High, plugin);
registerEvent("ENTITY_DAMAGE", Priority.High);
registerEvent("ENTITY_EXPLODE", Priority.High);
registerEvent("CREATURE_SPAWN", Priority.High);
registerEvent("ENTITY_INTERACT", Priority.High);
registerEvent("CREEPER_POWER", Priority.High);
registerEvent("PIG_ZAP", Priority.High);
registerEvent("PAINTING_BREAK", Priority.High);
registerEvent("PAINTING_PLACE", Priority.High);
}
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
* @param priority
*/
private void registerEvent(String typeName, Priority priority) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(type, this, priority, plugin);
} catch (IllegalArgumentException e) {
logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
}
/**

View File

@ -72,18 +72,34 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_INTERACT, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_LOGIN, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_QUIT, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_BED_ENTER, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.High, plugin);
registerEvent("PLAYER_INTERACT", Priority.High);
registerEvent("PLAYER_DROP_ITEM", Priority.High);
registerEvent("PLAYER_PICKUP_ITEM", Priority.High);
registerEvent("PLAYER_JOIN", Priority.Normal);
registerEvent("PLAYER_LOGIN", Priority.Normal);
registerEvent("PLAYER_QUIT", Priority.Normal);
registerEvent("PLAYER_BUCKET_FILL", Priority.High);
registerEvent("PLAYER_BUCKET_EMPTY", Priority.High);
registerEvent("PLAYER_RESPAWN", Priority.High);
registerEvent("PLAYER_ITEM_HELD", Priority.High);
registerEvent("PLAYER_BED_ENTER", Priority.High);
registerEvent("PLAYER_MOVE", Priority.High);
}
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
* @param priority
*/
private void registerEvent(String typeName, Priority priority) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(type, this, priority, plugin);
} catch (IllegalArgumentException e) {
logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
}
/**

View File

@ -32,8 +32,15 @@
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import java.util.logging.Logger;
public class WorldGuardWeatherListener extends WeatherListener {
/**
* Logger for messages.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* Plugin.
*/
@ -51,9 +58,25 @@ public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.LIGHTNING_STRIKE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.THUNDER_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.WEATHER_CHANGE, this, Priority.High, plugin);
registerEvent("LIGHTNING_STRIKE", Priority.High);
registerEvent("THUNDER_CHANGE", Priority.High);
registerEvent("WEATHER_CHANGE", Priority.High);
}
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
* @param priority
*/
private void registerEvent(String typeName, Priority priority) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(type, this, priority, plugin);
} catch (IllegalArgumentException e) {
logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
}
@Override

View File

@ -37,7 +37,23 @@ public WorldGuardWorldListener(WorldGuardPlugin plugin) {
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.CHUNK_LOAD, this, Event.Priority.Normal, plugin);
registerEvent("CHUNK_LOAD", Event.Priority.Normal);
}
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
* @param priority
*/
private void registerEvent(String typeName, Event.Priority priority) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(type, this, priority, plugin);
} catch (IllegalArgumentException e) {
logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
}
/**