mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-03 01:19:42 +01:00
Changed event registration to catch errors.
This commit is contained in:
parent
ba376a6326
commit
b7dd63ebd9
@ -70,22 +70,28 @@ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.High, plugin);
|
registerEvent("BLOCK_DAMAGE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.High, plugin);
|
registerEvent("BLOCK_BREAK", Priority.High);
|
||||||
pm.registerEvent(Event.Type.BLOCK_FROMTO, this, Priority.Normal, plugin);
|
registerEvent("BLOCK_FROMTO", Priority.Normal);
|
||||||
pm.registerEvent(Event.Type.BLOCK_IGNITE, this, Priority.High, plugin);
|
registerEvent("BLOCK_IGNITE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PHYSICS, this, Priority.Normal, plugin);
|
registerEvent("BLOCK_PHYSICS", Priority.Normal);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.High, plugin);
|
registerEvent("BLOCK_PLACE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin);
|
registerEvent("BLOCK_BURN", Priority.High);
|
||||||
pm.registerEvent(Event.Type.SIGN_CHANGE, this, Priority.High, plugin);
|
registerEvent("SIGN_CHANGE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
|
registerEvent("REDSTONE_CHANGE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.LEAVES_DECAY, this, Priority.High, plugin);
|
registerEvent("SNOW_FORM", Priority.High);
|
||||||
registerEventSafe("SNOW_FORM", Priority.High);
|
registerEvent("LEAVES_DECAY", Priority.High);
|
||||||
registerEventSafe("BLOCK_FORM", Priority.High);
|
registerEvent("BLOCK_FORM", Priority.High);
|
||||||
registerEventSafe("BLOCK_SPREAD", 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 {
|
try {
|
||||||
Event.Type type = Event.Type.valueOf(typeName);
|
Event.Type type = Event.Type.valueOf(typeName);
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
@ -41,12 +41,18 @@
|
|||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for entity related events.
|
* Listener for entity related events.
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldGuardEntityListener extends EntityListener {
|
public class WorldGuardEntityListener extends EntityListener {
|
||||||
|
/**
|
||||||
|
* Logger for messages.
|
||||||
|
*/
|
||||||
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
@ -65,14 +71,30 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin);
|
registerEvent("ENTITY_DAMAGE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
|
registerEvent("ENTITY_EXPLODE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin);
|
registerEvent("CREATURE_SPAWN", Priority.High);
|
||||||
pm.registerEvent(Event.Type.ENTITY_INTERACT, this, Priority.High, plugin);
|
registerEvent("ENTITY_INTERACT", Priority.High);
|
||||||
pm.registerEvent(Event.Type.CREEPER_POWER, this, Priority.High, plugin);
|
registerEvent("CREEPER_POWER", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PIG_ZAP, this, Priority.High, plugin);
|
registerEvent("PIG_ZAP", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PAINTING_BREAK, this, Priority.High, plugin);
|
registerEvent("PAINTING_BREAK", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PAINTING_PLACE, this, Priority.High, plugin);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,18 +72,34 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, this, Priority.High, plugin);
|
registerEvent("PLAYER_INTERACT", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin);
|
registerEvent("PLAYER_DROP_ITEM", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin);
|
registerEvent("PLAYER_PICKUP_ITEM", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Normal, plugin);
|
registerEvent("PLAYER_JOIN", Priority.Normal);
|
||||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, this, Priority.Normal, plugin);
|
registerEvent("PLAYER_LOGIN", Priority.Normal);
|
||||||
pm.registerEvent(Event.Type.PLAYER_QUIT, this, Priority.Normal, plugin);
|
registerEvent("PLAYER_QUIT", Priority.Normal);
|
||||||
pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this, Priority.High, plugin);
|
registerEvent("PLAYER_BUCKET_FILL", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this, Priority.High, plugin);
|
registerEvent("PLAYER_BUCKET_EMPTY", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.High, plugin);
|
registerEvent("PLAYER_RESPAWN", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, this, Priority.High, plugin);
|
registerEvent("PLAYER_ITEM_HELD", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_BED_ENTER, this, Priority.High, plugin);
|
registerEvent("PLAYER_BED_ENTER", Priority.High);
|
||||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.High, plugin);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,8 +32,15 @@
|
|||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class WorldGuardWeatherListener extends WeatherListener {
|
public class WorldGuardWeatherListener extends WeatherListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger for messages.
|
||||||
|
*/
|
||||||
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin.
|
* Plugin.
|
||||||
*/
|
*/
|
||||||
@ -51,9 +58,25 @@ public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.LIGHTNING_STRIKE, this, Priority.High, plugin);
|
registerEvent("LIGHTNING_STRIKE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.THUNDER_CHANGE, this, Priority.High, plugin);
|
registerEvent("THUNDER_CHANGE", Priority.High);
|
||||||
pm.registerEvent(Event.Type.WEATHER_CHANGE, this, Priority.High, plugin);
|
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
|
@Override
|
||||||
|
@ -37,7 +37,23 @@ public WorldGuardWorldListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user