Skip to content

Commit

Permalink
Bug fix, v1.1.19
Browse files Browse the repository at this point in the history
Buckets of fish would flow when waterlogging a block
  • Loading branch information
bermudalocket committed Mar 9, 2019
1 parent 1fe3f91 commit b12fba4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>SafeBuckets</groupId>
<artifactId>SafeBuckets</artifactId>
<version>1.1.18</version>
<version>1.1.19</version>
<packaging>jar</packaging>
<name>SafeBuckets</name>
<description>Make water non-flowing for water from buckets</description>
Expand Down
2 changes: 1 addition & 1 deletion src/nu/nerd/SafeBuckets/SafeBucketsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 26 additions & 6 deletions src/nu/nerd/SafeBuckets/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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());
}

// ------------------------------------------------------------------------
Expand All @@ -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();
Expand Down

0 comments on commit b12fba4

Please sign in to comment.