From e69deaba295e2fe1062e1dce558a6591ee3e6973 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Tue, 28 Jun 2016 21:35:37 +0200 Subject: [PATCH] Detect more changes to Cauldrons --- src/com/dre/brewery/P.java | 3 +++ .../brewery/listeners/CauldronListener.java | 22 +++++++++++++++++++ .../dre/brewery/listeners/PlayerListener.java | 20 ++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/com/dre/brewery/listeners/CauldronListener.java diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index b0dc6632..45df16cb 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -102,6 +102,9 @@ public void onEnable() { p.getServer().getPluginManager().registerEvents(entityListener, p); p.getServer().getPluginManager().registerEvents(inventoryListener, p); p.getServer().getPluginManager().registerEvents(worldListener, p); + if (use1_9) { + p.getServer().getPluginManager().registerEvents(new CauldronListener(), p); + } // Heartbeat p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200); diff --git a/src/com/dre/brewery/listeners/CauldronListener.java b/src/com/dre/brewery/listeners/CauldronListener.java new file mode 100644 index 00000000..c119c581 --- /dev/null +++ b/src/com/dre/brewery/listeners/CauldronListener.java @@ -0,0 +1,22 @@ +package com.dre.brewery.listeners; + +import com.dre.brewery.BCauldron; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.CauldronLevelChangeEvent; + +public class CauldronListener implements Listener { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onCauldronChange(CauldronLevelChangeEvent event) { + if (event.getNewLevel() == 0 && event.getOldLevel() != 0) { + if (event.getReason() == CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) { + return; + } + BCauldron.remove(event.getBlock()); + } else if (event.getNewLevel() == 3 && event.getOldLevel() != 3) { + BCauldron.remove(event.getBlock()); + } + } +} diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index 402b2f99..abf69118 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -39,7 +39,7 @@ public void onPlayerInteract(PlayerInteractEvent event) { Material materialInHand = event.getMaterial(); ItemStack item = event.getItem(); - if (materialInHand == null) { + if (materialInHand == null || materialInHand == Material.BUCKET) { return; } else if (materialInHand == Material.WATCH) { @@ -64,22 +64,16 @@ public void onPlayerInteract(PlayerInteractEvent event) { } return; - // reset cauldron when refilling to prevent - // unlimited source of potions + // reset cauldron when refilling to prevent unlimited source of potions } else if (materialInHand == Material.WATER_BUCKET) { - if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) { - // will only remove when existing - BCauldron.remove(clickedBlock); + if (!P.use1_9) { + if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) { + // will only remove when existing + BCauldron.remove(clickedBlock); + } } return; - // Its possible to empty a Cauldron with a Bucket in 1.9 - } else if (P.use1_9 && materialInHand == Material.BUCKET) { - if (BCauldron.getFillLevel(clickedBlock) == 2) { - // will only remove when existing - BCauldron.remove(clickedBlock); - } - return; } // Check if fire alive below cauldron when adding ingredients