From fafdae9ba91825a14c0fb489cd7d0ac8074eceb7 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 28 Dec 2020 15:11:30 +0100 Subject: [PATCH] Only check ice-form for ice (#2940) Co-authored-by: NotMyFault --- .../bukkit/listener/BlockEventListener.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) 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 d19b62f67..f13823478 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -57,6 +57,7 @@ import com.plotsquared.core.plot.flag.implementations.SnowMeltFlag; import com.plotsquared.core.plot.flag.implementations.SoilDryFlag; import com.plotsquared.core.plot.flag.implementations.VineGrowFlag; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; +import com.plotsquared.core.plot.flag.types.BooleanFlag; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; @@ -469,7 +470,9 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockForm(BlockFormEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockForm(BlockFormEvent event) { + if (event instanceof EntityBlockFormEvent) return; // handled below Block block = event.getBlock(); Location location = BukkitUtil.adapt(block.getLocation()); if (location.isPlotRoad()) { @@ -502,7 +505,8 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityBlockForm(EntityBlockFormEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityBlockForm(EntityBlockFormEvent event) { String world = event.getBlock().getWorld().getName(); if (!this.plotAreaManager.hasPlotArea(world)) { return; @@ -517,32 +521,44 @@ public class BlockEventListener implements Listener { event.setCancelled(true); return; } + Class> flag; + switch (event.getNewState().getType()) { + case SNOW: + case SNOW_BLOCK: + flag = SnowFormFlag.class; + break; + case ICE: + case FROSTED_ICE: + case PACKED_ICE: + flag = IceFormFlag.class; + break; + default: + return; // other blocks are ignored by this event + } + boolean allowed = plot.getFlag(flag); Entity entity = event.getEntity(); if (entity instanceof Player) { Player player = (Player) entity; - if (!plot.hasOwner()) { - BukkitPlayer plotPlayer = BukkitUtil.adapt(player); - if (plot.getFlag(IceFormFlag.class)) { - plot.debug("Ice could not be formed because ice-form = false"); - return; - } - event.setCancelled(true); - return; - } BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (!plot.isAdded(plotPlayer.getUUID())) { - if (plot.getFlag(IceFormFlag.class)) { - plot.debug("Ice could not be formed because ice-form = false"); - return; + if (allowed) { + return; // player is not added but forming is allowed } - event.setCancelled(true); + plot.debug(String.format("%s could not be formed because %s = false (entity is player)", + event.getNewState().getType(), + flag == SnowFormFlag.class ? "snow-form" : "ice-form")); + event.setCancelled(true); // player is not added and forming isn't allowed + } + return; // event is cancelled if not added and not allowed, otherwise forming is allowed + } + if (plot.hasOwner()) { + if (allowed) { return; } - return; - } - if (!plot.getFlag(IceFormFlag.class)) { + plot.debug(String.format("%s could not be formed because %s = false (entity is not player)", + event.getNewState().getType(), + flag == SnowFormFlag.class ? "snow-form" : "ice-form")); event.setCancelled(true); - plot.debug("Ice could not form because ice-form = false"); } }