From bddcc798ce18173eeb89b0b2b394b82b5d7e5f49 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 30 Mar 2011 04:23:20 -0500 Subject: [PATCH] For some reason onPlayerInteract() doesn't always detect bucket usage if it's about 2-3 blocks away from you, so I added monitoring of PLAYER_BUCKET_EMPTY and PLAYER_BUCKET_FILL events which seem to always fire correctly without fail --- src/com/bukkit/mcteam/factions/Factions.java | 2 ++ .../listeners/FactionsPlayerListener.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 48225a46..82801234 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -140,6 +140,8 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this); + pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this); diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 98e6e94a..fdf5162a 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -9,6 +9,8 @@ import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -146,6 +148,8 @@ public class FactionsPlayerListener extends PlayerListener{ event.setCancelled(true); return; } + // this check below might no longer be needed... bucket detection is now necessarily handled separately in onPlayerBucketXXX() events, and + // Flint&Steel is somehow detected before this in onBlockPlace(), and that's currently it for the default territoryDenyUseageMaterials if ( ! this.playerCanUseItemHere(player, block, event.getMaterial())) { event.setCancelled(true); return; @@ -215,4 +219,35 @@ public class FactionsPlayerListener extends PlayerListener{ event.setRespawnLocation(home); } } + + // For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected), + // but these separate bucket events below always fire without fail + @Override + public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { + if (event.isCancelled()) { + return; + } + + Block block = event.getBlockClicked(); + Player player = event.getPlayer(); + + if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) { + event.setCancelled(true); + return; + } + } + @Override + public void onPlayerBucketFill(PlayerBucketFillEvent event) { + if (event.isCancelled()) { + return; + } + + Block block = event.getBlockClicked(); + Player player = event.getPlayer(); + + if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) { + event.setCancelled(true); + return; + } + } }