diff --git a/pom.xml b/pom.xml index 64f40d4..b22c058 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 SafeBuckets SafeBuckets - 1.1.18 + 1.1.19 jar SafeBuckets Make water non-flowing for water from buckets diff --git a/src/nu/nerd/SafeBuckets/SafeBucketsListener.java b/src/nu/nerd/SafeBuckets/SafeBucketsListener.java index b4f5540..9d451f7 100755 --- a/src/nu/nerd/SafeBuckets/SafeBucketsListener.java +++ b/src/nu/nerd/SafeBuckets/SafeBucketsListener.java @@ -276,7 +276,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { // not a staff member trying to flow, and buckets are set to be safe if (!EnchantGlow.hasGlow(mainHand)) { - if (Util.isWaterloggable(clickedBlock) && mainHand.getType() == Material.WATER_BUCKET) { + if (Util.isWaterloggable(clickedBlock) && Util.isWaterBucket(mainHand)) { if (!Util.isWaterlogged(clickedBlock)) { SafeBuckets.setSafe(clickedBlock, true); } else { diff --git a/src/nu/nerd/SafeBuckets/Util.java b/src/nu/nerd/SafeBuckets/Util.java index 8b3e9e7..6647203 100644 --- a/src/nu/nerd/SafeBuckets/Util.java +++ b/src/nu/nerd/SafeBuckets/Util.java @@ -13,6 +13,7 @@ import org.bukkit.block.data.type.Slab; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import java.util.Arrays; @@ -69,6 +70,25 @@ static boolean isWaterloggable(Block block) { return block.getBlockData() instanceof Waterlogged; } + // ------------------------------------------------------------------------ + /** + * Returns true if the given ItemStack is capable of placing water in the + * world. + * + * @param itemStack the item. + * @return true if the item is capable of placing water in the world. + */ + static boolean isWaterBucket(ItemStack itemStack) { + if (itemStack == null) { + return false; + } + Material bucketType = itemStack.getType(); + if (bucketType == Material.LAVA_BUCKET || bucketType == Material.MILK_BUCKET) { + return false; + } + return SafeBuckets.CONFIG.BUCKETS.contains(bucketType) || bucketType.toString().contains("_BUCKET"); + } + // ------------------------------------------------------------------------ /** * Plays a sound at the player's location. Used as an auditory confirmation @@ -91,8 +111,7 @@ static void playFlowSound(Player player) { static void showParticles(Block block, boolean state) { Location blockCenter = block.getLocation().add(0.5, 0.5, 0.5); boolean isLiquid = block.getType() == Material.WATER; // lava is liquid but not transparent - Particle.DustOptions color = (state) ? new Particle.DustOptions(Color.LIME, 1) - : new Particle.DustOptions(Color.RED, 1); + Particle.DustOptions color = new Particle.DustOptions(state ? Color.LIME : Color.RED, 1); if (isLiquid) { // center only block.getWorld().spawnParticle(Particle.REDSTONE, blockCenter, 10, color); @@ -112,9 +131,10 @@ static void showParticles(Block block, boolean state) { * @return a human-readable ordered triple as a string. */ static String formatCoords(Location location) { - return String.format("(x:%d, y:%d, z:%d)", location.getBlockX(), - location.getBlockY(), - location.getBlockZ()); + return String.format("(x:%d, y:%d, z:%d)", + location.getBlockX(), + location.getBlockY(), + location.getBlockZ()); } // ------------------------------------------------------------------------ @@ -140,7 +160,7 @@ static void forceBlockUpdate(Block block) { } if (updateBlock == null) { // fail gracefully - SafeBuckets.log("Failed to force a block update at " + Util.formatCoords(block.getLocation()) + ": no suitable adjacent blocks."); + SafeBuckets.log("Failed to force a block update at " + Util.formatCoords(block.getLocation())+ ": no suitable adjacent blocks."); return; } BlockState currentState = updateBlock.getState();