diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java index af5de4247..3cd5df861 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -98,6 +98,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.CauldronLevelChangeEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.world.StructureGrowEvent; @@ -471,6 +472,58 @@ public class BlockEventListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST) + public void onCauldronEmpty(CauldronLevelChangeEvent event) { + Entity entity = event.getEntity(); + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getPlot(location); + // TODO Add flags for specific control over cauldron changes (rain, dripstone...) + switch (event.getReason()) { + case BANNER_WASH, ARMOR_WASH, EXTINGUISH -> { + if (entity instanceof Player player) { + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); + if (plot != null) { + if (!plot.hasOwner()) { + if (Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED)) { + return; + } + } else if (!plot.isAdded(plotPlayer.getUUID())) { + if (Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) { + return; + } + } else { + return; + } + } else { + if (Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) { + return; + } + if (this.worldEdit != null && plotPlayer.getAttribute("worldedit")) { + if (player.getInventory().getItemInMainHand().getType() == Material + .getMaterial(this.worldEdit.getConfiguration().wandItem)) { + return; + } + } + } + } + if (event.getReason() == CauldronLevelChangeEvent.ChangeReason.EXTINGUISH && event.getEntity() != null) { + event.getEntity().setFireTicks(0); + } + // Though the players fire ticks are modified, + // the cauldron water level change is cancelled and the event should represent that. + event.setCancelled(true); + } + default -> { + // Bucket empty, Bucket fill, Bottle empty, Bottle fill are already handled in PlayerInteract event + // Evaporation or Unknown reasons do not need to be cancelled as they are considered natural causes + } + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockForm(BlockFormEvent event) { if (event instanceof EntityBlockFormEvent) {