Skip to content

Commit

Permalink
no need to cancel bucket event, new method works without it and lets …
Browse files Browse the repository at this point in the history
…the fishbucket work naturally.
  • Loading branch information
msudol committed Feb 18, 2019
1 parent 0442743 commit 4f95e3d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 62 deletions.
18 changes: 10 additions & 8 deletions src/com/pwn9/PwnBuckets/EvaporateLavaTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Levelled;

public class EvaporateLavaTask implements Runnable
{
Expand Down Expand Up @@ -41,15 +42,16 @@ public void run()

public boolean isLava(Block block)
{
Block b = block;

if (b.getType() == Material.LAVA)
if ((block.getType() == Material.LAVA) && (block.getBlockData() instanceof Levelled))
{
return true;
}
else
{
return false;
Levelled levelledBlock = (Levelled) block.getBlockData();
int level = levelledBlock.getLevel();
//source block
if (level == 0)
{
return true;
}
}
return false;
}
}
18 changes: 10 additions & 8 deletions src/com/pwn9/PwnBuckets/EvaporateWaterTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Levelled;

public class EvaporateWaterTask implements Runnable
{
Expand Down Expand Up @@ -41,15 +42,16 @@ public void run()

public boolean isWater(Block block)
{
Block b = block;

if (b.getType() == Material.WATER)
{
return true;
}
else
if ((block.getType() == Material.WATER) && (block.getBlockData() instanceof Levelled))
{
return false;
Levelled levelledBlock = (Levelled) block.getBlockData();
int level = levelledBlock.getLevel();
//source block
if (level == 0)
{
return true;
}
}
return false;
}
}
63 changes: 17 additions & 46 deletions src/com/pwn9/PwnBuckets/WaterListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -58,9 +57,9 @@ public void onPlayerEmptyBucket(PlayerBucketEmptyEvent event)
}

// if its water
if ((bucket.toString().contains("WATER") || bucket.toString().contains("FISH") || bucket.toString().contains("SALMON") || bucket.toString().contains("COD")) && (!player.hasPermission("pwnbuckets.waterbucket"))) {

if ((bucket.toString().contains("WATER") || bucket.toString().contains("FISH") || bucket.toString().contains("SALMON") || bucket.toString().contains("COD")) && (!player.hasPermission("pwnbuckets.waterbucket")))
{

// if the biome has a bypass allow dumping water
if (PwnBuckets.containsCaseInsensitive(biome, PwnBuckets.bucketBypass))
{
Expand All @@ -80,24 +79,7 @@ public void onPlayerEmptyBucket(PlayerBucketEmptyEvent event)
plugin.getServer().getScheduler().runTaskLater(plugin, task, 30L);
}

// need to cancel the event and manually change the inventory or else fast placing buckets can get around the plugin
if (mainBucket == bucket) {
ClearBucketTask clearTask = new ClearBucketTask(player, true);
plugin.getServer().getScheduler().runTaskLater(plugin, clearTask, 1L);
}
else if (offBucket == bucket){
ClearBucketTask clearTask = new ClearBucketTask(player, false);
plugin.getServer().getScheduler().runTaskLater(plugin, clearTask, 1L);
}
else {
// this shouldn't happen
if (PwnBuckets.logEnabled)
{
PwnBuckets.logToFile("Couldn't identify bucket hand.");
}
}

event.setCancelled(true);
// no need to cancel the event anymore, let it finish and evaporate the water

if (PwnBuckets.logEnabled)
{
Expand All @@ -109,7 +91,8 @@ else if (offBucket == bucket){
}

// if its lava
if (bucket.toString().contains("LAVA") && (!player.hasPermission("pwnbuckets.lavabucket"))) {
if (bucket.toString().contains("LAVA") && (!player.hasPermission("pwnbuckets.lavabucket")))
{

// if the biome has a bypass allow dumping lava
if (PwnBuckets.containsCaseInsensitive(biome, PwnBuckets.lavaBucketBypass))
Expand All @@ -130,24 +113,7 @@ else if (offBucket == bucket){
plugin.getServer().getScheduler().runTaskLater(plugin, task, 120L);
}

// need to cancel the event and manually change the inventory or else fast placing buckets can get around the plugin
if (mainBucket == bucket) {
ClearBucketTask clearTask = new ClearBucketTask(player, true);
plugin.getServer().getScheduler().runTaskLater(plugin, clearTask, 1L);
}
else if (offBucket == bucket){
ClearBucketTask clearTask = new ClearBucketTask(player, false);
plugin.getServer().getScheduler().runTaskLater(plugin, clearTask, 1L);
}
else {
// this shouldn't happen
if (PwnBuckets.logEnabled)
{
PwnBuckets.logToFile("Couldn't identify bucket hand.");
}
}

event.setCancelled(true);
// no need to cancel the event anymore, let it finish and evaporate the lava

if (PwnBuckets.logEnabled)
{
Expand Down Expand Up @@ -240,7 +206,8 @@ else if(bucket.toString().contains("LAVA"))

// when ice melts?
@EventHandler(ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent event) {
public void onBlockFade(BlockFadeEvent event)
{

World world = event.getBlock().getWorld();

Expand Down Expand Up @@ -287,11 +254,13 @@ public void onBlockFade(BlockFadeEvent event) {
// to set a source water not flowing water
public boolean isWater(Block block)
{
if ((block.getType() == Material.WATER) && (block.getBlockData() instanceof Levelled)) {
if ((block.getType() == Material.WATER) && (block.getBlockData() instanceof Levelled))
{
Levelled levelledBlock = (Levelled) block.getBlockData();
int level = levelledBlock.getLevel();
//source block
if (level == 0) {
if (level == 0)
{
if (PwnBuckets.logEnabled)
{
PwnBuckets.logToFile("Placing bucket on an existing source block.");
Expand All @@ -305,11 +274,13 @@ public boolean isWater(Block block)
// to get a source lava not flowing lava
public boolean isLava(Block block)
{
if ((block.getType() == Material.LAVA) && (block.getBlockData() instanceof Levelled)) {
if ((block.getType() == Material.LAVA) && (block.getBlockData() instanceof Levelled))
{
Levelled levelledBlock = (Levelled) block.getBlockData();
int level = levelledBlock.getLevel();
//source block
if (level == 0) {
if (level == 0)
{
if (PwnBuckets.logEnabled)
{
PwnBuckets.logToFile("Placing bucket on an existing source block.");
Expand Down

0 comments on commit 4f95e3d

Please sign in to comment.