Fix some possible issues with handler priority, more javadoc work.

This commit is contained in:
GJ 2013-07-28 13:55:48 -04:00
parent c5137eb884
commit ddcbe64db6

View File

@ -6,7 +6,6 @@ import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -168,14 +167,15 @@ public class PlayerListener implements Listener {
} }
/** /**
* Handle PlayerDropItemEvents at the highest priority. * Monitor PlayerDropItemEvents.
* <p> * <p>
* These events are used to flag sharable dropped items, as well as * These events are monitored for the purpose of flagging sharable
* remove ability buffs from pickaxes and shovels. * dropped items, as well as removing ability buffs from pickaxes
* and shovels.
* *
* @param event The event to modify * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDropItem(PlayerDropItemEvent event) { public void onPlayerDropItem(PlayerDropItemEvent event) {
Item drop = event.getItemDrop(); Item drop = event.getItemDrop();
ItemStack dropStack = drop.getItemStack(); ItemStack dropStack = drop.getItemStack();
@ -188,13 +188,15 @@ public class PlayerListener implements Listener {
} }
/** /**
* Monitor PlayerFishEvents. * Handle PlayerFishEvents at the highest priority.
* <p> * <p>
* These events are monitored for the purpose of handling the various * These events are used for the purpose of handling our anti-exploit
* @param event The event to monitor * code, as well as dealing with ice fishing.
*
* @param event The event to modify
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) { public void onPlayerFishHighest(PlayerFishEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) { if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) {
@ -207,59 +209,84 @@ public class PlayerListener implements Listener {
case FISHING: case FISHING:
if (!Permissions.krakenBypass(player)) { if (!Permissions.krakenBypass(player)) {
event.setCancelled(fishingManager.exploitPrevention()); event.setCancelled(fishingManager.exploitPrevention());
if (event.isCancelled()) {
return;
}
} }
return;
if (fishingManager.canMasterAngler()) {
fishingManager.masterAngler(event.getHook());
}
break;
case CAUGHT_FISH: case CAUGHT_FISH:
fishingManager.handleFishing((Item) event.getCaught());
if (Permissions.vanillaXpBoost(player, SkillType.FISHING)) { if (Permissions.vanillaXpBoost(player, SkillType.FISHING)) {
event.setExpToDrop(fishingManager.handleVanillaXpBoost(event.getExpToDrop())); event.setExpToDrop(fishingManager.handleVanillaXpBoost(event.getExpToDrop()));
} }
break; return;
case CAUGHT_ENTITY:
Entity entity = event.getCaught();
if (fishingManager.canShake(entity)) {
fishingManager.shakeCheck((LivingEntity) entity);
}
break;
case IN_GROUND: case IN_GROUND:
Fish hook = event.getHook(); Block block = player.getTargetBlock(null, 100);
Block block = event.getPlayer().getTargetBlock(null, 100);
if (fishingManager.canIceFish(block)) { if (fishingManager.canIceFish(block)) {
FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player); FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player);
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent); plugin.getServer().getPluginManager().callEvent(blockBreakEvent);
if (blockBreakEvent.isCancelled()) { if (blockBreakEvent.isCancelled()) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
fishingManager.iceFishing(hook, block); fishingManager.iceFishing(event.getHook(), block);
} }
break; return;
default: default:
break; return;
} }
} }
/** /**
* Monitor PlayerPickupItem events. * Monitor PlayerFishEvents.
* <p>
* These events are monitored for the purpose of handling the various
* Fishing skills and abilities.
* *
* @param event The event to watch * @param event The event to monitor
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerFishMonitor(PlayerFishEvent event) {
Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) {
return;
}
FishingManager fishingManager = UserManager.getPlayer(player).getFishingManager();
Entity caught = event.getCaught();
switch (event.getState()) {
case FISHING:
if (fishingManager.canMasterAngler()) {
fishingManager.masterAngler(event.getHook());
}
return;
case CAUGHT_FISH:
fishingManager.handleFishing((Item) caught);
return;
case CAUGHT_ENTITY:
if (fishingManager.canShake(caught)) {
fishingManager.shakeCheck((LivingEntity) caught);
}
return;
default:
return;
}
}
/**
* Handle PlayerPickupItemEvents at the highest priority.
* <p>
* These events are used to handle item sharing between party members and
* are also used to handle item pickup for the Unarmed skill.
*
* @param event The event to modify
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) { public void onPlayerPickupItem(PlayerPickupItemEvent event) {
@ -294,9 +321,13 @@ public class PlayerListener implements Listener {
} }
/** /**
* Monitor PlayerQuit events. * Monitor PlayerQuitEvents.
* <p>
* These events are monitored for the purpose of resetting player
* variables and other garbage collection tasks that must take place when
* a player exits the server.
* *
* @param event The event to watch * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
@ -307,18 +338,21 @@ public class PlayerListener implements Listener {
} }
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
mcMMOPlayer.resetAbilityMode();
/* GARBAGE COLLECTION */ mcMMOPlayer.resetAbilityMode();
BleedTimerTask.bleedOut(player); // Bleed it out BleedTimerTask.bleedOut(player);
mcMMOPlayer.getProfile().save(); mcMMOPlayer.getProfile().save();
UserManager.remove(player.getName()); UserManager.remove(player.getName());
} }
/** /**
* Monitor PlayerJoin events. * Monitor PlayerJoinEvents.
* <p>
* These events are monitored for the purpose of initializing player
* variables, as well as handling the MOTD display and other important
* join messages.
* *
* @param event The event to watch * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
@ -346,9 +380,13 @@ public class PlayerListener implements Listener {
} }
/** /**
* Monitor PlayerRespawn events. * Monitor PlayerRespawnEvents.
* <p>
* These events are monitored for the purpose of setting the
* player's last respawn timestamp, in order to prevent
* possible exploitation.
* *
* @param event The event to watch * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
@ -362,34 +400,34 @@ public class PlayerListener implements Listener {
} }
/** /**
* Handle PlayerInteract events that involve modifying the event. * Handle PlayerInteractEvents at the lowest priority.
* *
* @param event The event to modify * @param event The event to modify
*/ */
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerInteractLowest(PlayerInteractEvent event) { public void onPlayerInteractLowest(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) { if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
ItemStack heldItem = player.getItemInHand();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
// This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else. // TODO: This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
return; return;
} }
MiningManager miningManager = mcMMOPlayer.getMiningManager(); MiningManager miningManager = mcMMOPlayer.getMiningManager();
Block block = event.getClickedBlock();
ItemStack heldItem = player.getItemInHand();
switch (event.getAction()) { switch (event.getAction()) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
int blockID = block.getTypeId(); int blockID = block.getTypeId();
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) { if (!Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
RepairManager repairManager = mcMMOPlayer.getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
@ -467,26 +505,27 @@ public class PlayerListener implements Listener {
} }
/** /**
* Monitor PlayerInteract events. * Monitor PlayerInteractEvents.
* *
* @param event The event to watch * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteractMonitor(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) { if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
ItemStack heldItem = player.getItemInHand();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
// This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else. // TODO: This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
return; return;
} }
ItemStack heldItem = player.getItemInHand();
switch (event.getAction()) { switch (event.getAction()) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
@ -571,7 +610,7 @@ public class PlayerListener implements Listener {
} }
/** /**
* Monitor PlayerChat events. * Handle PlayerChatEvents at high priority.
* *
* @param event The event to watch * @param event The event to watch
*/ */