Updated to new event system

This commit is contained in:
TomyLobo 2012-01-18 18:22:29 +01:00 committed by zml2008
parent 47c84beb43
commit 57ed91cd28
9 changed files with 219 additions and 375 deletions

View File

@ -40,14 +40,14 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.1</version>
<version>5.2-SNAPSHOT</version>
</dependency>
<!-- Bukkit -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.0.0-R1-SNAPSHOT</version>
<version>1.1-R1-SNAPSHOT</version>
</dependency>
<!-- CommandBook -->

View File

@ -27,8 +27,9 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent;
@ -36,7 +37,6 @@
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
@ -47,8 +47,6 @@
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemType;
@ -66,10 +64,11 @@
*
* @author sk89q
*/
public class WorldGuardBlockListener extends BlockListener {
public class WorldGuardBlockListener implements Listener {
/**
* Logger for messages.
*/
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
@ -87,39 +86,9 @@ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
* Register events.
*/
public void registerEvents() {
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("LEAVES_DECAY", Priority.High);
registerEvent("BLOCK_FORM", Priority.High);
registerEvent("BLOCK_SPREAD", Priority.High);
registerEvent("BLOCK_FADE", Priority.High);
registerEvent("BLOCK_PISTON_EXTEND", Priority.High);
registerEvent("BLOCK_PISTON_RETRACT", Priority.High);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* 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);
}
}
/**
* Get the world configuration given a world.
*
@ -129,7 +98,7 @@ private void registerEvent(String typeName, Priority priority) {
protected WorldConfiguration getWorldConfig(World world) {
return plugin.getGlobalStateManager().get(world);
}
/**
* Get the world configuration given a player.
*
@ -139,11 +108,11 @@ protected WorldConfiguration getWorldConfig(World world) {
protected WorldConfiguration getWorldConfig(Player player) {
return plugin.getGlobalStateManager().get(player.getWorld());
}
/**
* Called when a block is damaged.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) {
return;
@ -166,7 +135,7 @@ public void onBlockDamage(BlockDamageEvent event) {
/**
* Called when a block is broken.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
@ -219,7 +188,7 @@ public void onBlockBreak(BlockBreakEvent event) {
/**
* Called when fluids flow.
*/
@Override
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if (event.isCancelled()) {
return;
@ -316,7 +285,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
/**
* Called when a block gets ignited.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockIgnite(BlockIgniteEvent event) {
if (event.isCancelled()) {
return;
@ -418,7 +387,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
/**
* Called when a block is destroyed from burning.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBurn(BlockBurnEvent event) {
if (event.isCancelled()) {
@ -474,7 +443,7 @@ public void onBlockBurn(BlockBurnEvent event) {
/**
* Called when block physics occurs.
*/
@Override
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) {
if (event.isCancelled()) {
@ -510,7 +479,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
/**
* Called when a player places a block.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) {
@ -565,7 +534,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
/**
* Called when redstone changes.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
Block blockTo = event.getBlock();
@ -601,7 +570,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
/**
* Called when a sign is changed.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
@ -668,7 +637,7 @@ public void onSignChange(SignChangeEvent event) {
}
}
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onLeavesDecay(LeavesDecayEvent event) {
if (event.isCancelled()) {
return;
@ -698,6 +667,7 @@ public void onLeavesDecay(LeavesDecayEvent event) {
/**
* Called when a block is formed based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockForm(BlockFormEvent event) {
if (event.isCancelled()) {
return;
@ -741,6 +711,7 @@ public void onBlockForm(BlockFormEvent event) {
/**
* Called when a block spreads based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockSpread(BlockSpreadEvent event) {
if (event.isCancelled()) {
return;
@ -784,6 +755,7 @@ public void onBlockSpread(BlockSpreadEvent event) {
/**
* Called when a block fades.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockFade(BlockFadeEvent event) {
if (event.isCancelled()) {
return;
@ -822,6 +794,7 @@ public void onBlockFade(BlockFadeEvent event) {
/**
* Called when a piston extends
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (event.isCancelled()) {
return;
@ -847,6 +820,7 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
/**
* Called when a piston retracts
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (event.isCancelled()) {
return;

View File

@ -42,8 +42,9 @@
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
import org.bukkit.event.entity.EndermanPickupEvent;
@ -55,7 +56,6 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
@ -66,8 +66,6 @@
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
@ -80,10 +78,11 @@
*
* @author sk89q
*/
public class WorldGuardEntityListener extends EntityListener {
public class WorldGuardEntityListener implements Listener {
/**
* Logger for messages.
*/
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
@ -101,45 +100,13 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
* Register events.
*/
public void registerEvents() {
// PluginManager pm = plugin.getServer().getPluginManager();
registerEvent("ENTITY_DAMAGE", Priority.High);
registerEvent("ENTITY_COMBUST", Priority.High);
registerEvent("ENTITY_EXPLODE", Priority.High);
registerEvent("EXPLOSION_PRIME", 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);
registerEvent("ENTITY_REGAIN_HEALTH", Priority.High);
registerEvent("ENDERMAN_PICKUP", Priority.High);
registerEvent("ENDERMAN_PLACE", Priority.High);
registerEvent("ENTITY_DEATH", Priority.High);
registerEvent("FOOD_LEVEL_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);
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when an entity interacts with another object.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityInteract(EntityInteractEvent event) {
Entity entity = event.getEntity();
Block block = event.getBlock();
@ -157,7 +124,7 @@ public void onEntityInteract(EntityInteractEvent event) {
/**
* Called when an entity dies.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
@ -435,7 +402,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
/**
* Called on entity damage.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
return;
@ -516,7 +483,7 @@ public void onEntityDamage(EntityDamageEvent event) {
/**
* Called on entity combust.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombust(EntityCombustEvent event) {
if (event.isCancelled()) {
return;
@ -540,7 +507,7 @@ public void onEntityCombust(EntityCombustEvent event) {
/**
* Called on entity explode.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) {
return;
@ -657,7 +624,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
/**
* Called on explosion prime
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onExplosionPrime(ExplosionPrimeEvent event) {
if (event.isCancelled()) {
return;
@ -677,7 +644,7 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
/**
* Called on creature spawn.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled()) {
return;
@ -723,7 +690,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
/**
* Called on pig zap.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPigZap(PigZapEvent event) {
if (event.isCancelled()) {
return;
@ -740,7 +707,7 @@ public void onPigZap(PigZapEvent event) {
/**
* Called on creeper power.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onCreeperPower(CreeperPowerEvent event) {
if (event.isCancelled()) {
return;
@ -757,7 +724,7 @@ public void onCreeperPower(CreeperPowerEvent event) {
/**
* Called when a painting is removed.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (breakEvent.isCancelled()) {
return;
@ -800,7 +767,7 @@ public void onPaintingBreak(PaintingBreakEvent breakEvent) {
/**
* Called on painting place.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPaintingPlace(PaintingPlaceEvent event) {
if (event.isCancelled()) {
return;
@ -834,7 +801,7 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
/**
* Called on entity health regain.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (event.isCancelled()) {
return;
@ -855,7 +822,7 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
/**
* Called when an enderman picks a block up.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEndermanPickup(EndermanPickupEvent event) {
if (event.isCancelled()) {
return;
@ -883,7 +850,7 @@ public void onEndermanPickup(EndermanPickupEvent event) {
/**
* Called when an enderman places a block.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onEndermanPlace(EndermanPlaceEvent event) {
if (event.isCancelled()) {
return;
@ -908,7 +875,7 @@ public void onEndermanPlace(EndermanPlaceEvent event) {
}
}
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();

View File

@ -33,9 +33,10 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
@ -45,7 +46,6 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -73,7 +73,7 @@
/**
* Handles all events thrown in relation to a player.
*/
public class WorldGuardPlayerListener extends PlayerListener {
public class WorldGuardPlayerListener implements Listener {
/**
* Logger for messages.
@ -95,46 +95,142 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
* Register events.
*/
public void registerEvents() {
// PluginManager pm = plugin.getServer().getPluginManager();
final PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvents(this, 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.Highest);
registerEvent("PLAYER_ITEM_HELD", Priority.High);
registerEvent("PLAYER_BED_ENTER", Priority.High);
registerEvent("PLAYER_COMMAND_PREPROCESS", Priority.Lowest);
if (plugin.getGlobalStateManager().usePlayerMove) {
registerEvent("PLAYER_MOVE", Priority.High);
pm.registerEvents(new PlayerMoveHandler(), plugin);
}
}
private class PlayerMoveHandler implements Listener {
/**
* Called when a player attempts to move.
*
* @param event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
/**
* 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);
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (player.getVehicle() != null) return; // handled in vehicle listener
if (wcfg.useRegions) {
// Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
//Flush states in multiworld scenario
if (state.lastWorld != null && !state.lastWorld.equals(world)) {
plugin.getFlagStateManager().forget(player);
state = plugin.getFlagStateManager().getState(player);
}
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE);
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ regionList);
}
state.lastGreeting = greeting;
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
}
}
}
}
}
/**
* Called when a player joins a server.
*/
@SuppressWarnings("deprecation")
@Override
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -188,7 +284,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
/**
* Called when a player leaves a server.
*/
@Override
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -233,7 +329,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
/**
* Called when a player interacts with an item.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -263,126 +359,6 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}
}
/**
* Called when a player attempts to move.
*
* @param event
*/
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (player.getVehicle() != null) return; // handled in vehicle listener
if (wcfg.useRegions) {
// Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
//Flush states in multiworld scenario
if (state.lastWorld != null && !state.lastWorld.equals(world)) {
plugin.getFlagStateManager().forget(player);
return;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE);
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ regionList);
}
state.lastGreeting = greeting;
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
}
}
}
/**
* Called when a player left clicks air.
@ -872,7 +848,7 @@ public void onPlayerItem(PlayerItemEvent event) {
/**
* Called when a player attempts to drop an item.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (event.isCancelled()) {
return;
@ -896,7 +872,7 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
/**
* Called when a player attempts to pickup an item.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (event.isCancelled()) {
return;
@ -920,7 +896,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
/**
* Called when a bucket is filled.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -955,7 +931,7 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
/**
* Called when a bucket is empty.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -983,7 +959,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
/**
* Called when a player is respawned.
*/
@Override
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
Location location = player.getLocation();
@ -1018,7 +994,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
/**
* Called when a player changes their held item.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
@ -1039,7 +1015,7 @@ public void onItemHeldChange(PlayerItemHeldEvent event) {
/**
* Called when a player enters a bed.
*/
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (event.isCancelled()) {
return;
@ -1068,7 +1044,7 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
/**
* Called on command run.
*/
@Override
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();

View File

@ -1,15 +1,15 @@
package com.sk89q.worldguard.bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.PluginManager;
/**
* @author zml2008
*/
public class WorldGuardServerListener extends ServerListener {
public class WorldGuardServerListener implements Listener {
private final WorldGuardPlugin plugin;
@ -18,31 +18,16 @@ public WorldGuardServerListener(WorldGuardPlugin plugin) {
}
public void registerEvents() {
registerEvent("PLUGIN_ENABLE");
registerEvent("PLUGIN_DISABLE");
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvents(this, plugin);
}
/**
* Register an event, but not failing if the event is not implemented.
*
* @param typeName
*/
private void registerEvent(String typeName) {
try {
Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(type, this, Event.Priority.Normal, plugin);
} catch (IllegalArgumentException e) {
WorldGuardPlugin.logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
}
@Override
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
}
@Override
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
}

View File

@ -14,12 +14,10 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleListener;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState;
@ -28,11 +26,12 @@
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class WorldGuardVehicleListener extends VehicleListener {
public class WorldGuardVehicleListener implements Listener {
/**
* Logger for messages.
*/
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
@ -50,30 +49,13 @@ public WorldGuardVehicleListener(WorldGuardPlugin plugin) {
* Register events.
*/
public void registerEvents() {
registerEvent("VEHICLE_MOVE", Event.Priority.Normal);
registerEvent("VEHICLE_DESTROY", 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);
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when a vehicle is destroyed.
*/
@Override
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
Vehicle vehicle = event.getVehicle();
Entity destroyer = event.getAttacker();
@ -104,7 +86,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) {
/**
* Called when a vehicle moves.
*/
@Override
@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
Vehicle vehicle = event.getVehicle();
if (vehicle.getPassenger() == null

View File

@ -23,24 +23,23 @@
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.WeatherListener;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
public class WorldGuardWeatherListener extends WeatherListener {
public class WorldGuardWeatherListener implements Listener {
/**
* Logger for messages.
*/
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
@ -58,30 +57,10 @@ public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
}
public void registerEvents() {
// PluginManager pm = plugin.getServer().getPluginManager();
registerEvent("LIGHTNING_STRIKE", Priority.High);
registerEvent("THUNDER_CHANGE", Priority.High);
registerEvent("WEATHER_CHANGE", Priority.High);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* 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
@EventHandler(priority = EventPriority.HIGH)
public void onWeatherChange(WeatherChangeEvent event) {
if (event.isCancelled()) {
return;
@ -100,7 +79,7 @@ public void onWeatherChange(WeatherChangeEvent event) {
}
}
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onThunderChange(ThunderChangeEvent event) {
if (event.isCancelled()) {
return;
@ -120,7 +99,7 @@ public void onThunderChange(ThunderChangeEvent event) {
}
}
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onLightningStrike(LightningStrikeEvent event) {
if (event.isCancelled()) {
return;

View File

@ -9,13 +9,12 @@
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.plugin.PluginManager;
public class WorldGuardWorldListener extends WorldListener {
public class WorldGuardWorldListener implements Listener {
/**
* Logger for messages.
@ -37,31 +36,13 @@ public WorldGuardWorldListener(WorldGuardPlugin plugin) {
* Register events.
*/
public void registerEvents() {
// PluginManager pm = plugin.getServer().getPluginManager();
registerEvent("CHUNK_LOAD", Event.Priority.Normal);
registerEvent("WORLD_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);
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when a chunk is loaded.
*/
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
@ -85,6 +66,7 @@ public void onChunkLoad(ChunkLoadEvent event) {
/**
* Called when a world is loaded.
*/
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
initWorld(event.getWorld());
}

View File

@ -24,9 +24,9 @@
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.Plugin;
import java.util.*;
@ -65,8 +65,7 @@ private CommandMap getCommandMap() {
Bukkit.getServer().getLogger().warning(plugin.getDescription().getName() +
": Could not retrieve server CommandMap! Please report to http://redmine.sk89q.com");
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
Bukkit.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS,
new FallbackRegistrationListener(fallbackCommands), Event.Priority.Normal, plugin);
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
}
}
return commandMap;
@ -118,7 +117,7 @@ public Plugin getPlugin() {
}
}
public static class FallbackRegistrationListener extends PlayerListener {
public static class FallbackRegistrationListener implements Listener {
private final CommandMap commandRegistration;
@ -126,7 +125,7 @@ public FallbackRegistrationListener(CommandMap commandRegistration) {
this.commandRegistration = commandRegistration;
}
@Override
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
return;