From 2045a4988dd5083c9bff0f4db5cb53f3a5928c66 Mon Sep 17 00:00:00 2001 From: "Patrick \"IPat\" Hein" Date: Fri, 28 May 2021 10:57:48 +0200 Subject: [PATCH] Prevent dragon eggs from leaving or entering plot bounds (#3075) * Negate mob-place flag debug message * fixed a little typo :) * Added check for dragon egg teleportation event https://github.com/IntellectualSites/PlotSquared/issues/3074 * Basic dragon egg interact bugfix (Left-click interaction) Co-authored-by: NotMyFault --- .../bukkit/listener/BlockEventListener.java | 17 ++++++++++++++++- .../bukkit/listener/PlayerEventListener.java | 11 +++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 3cd5df861..15f8e5e07 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -751,7 +751,7 @@ public class BlockEventListener implements Listener { if (plot != null && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event .getBlock() .isLiquid()) { - plot.debug("Liquid could now flow because liquid-flow = disabled"); + plot.debug("Liquid could not flow because liquid-flow = disabled"); event.setCancelled(true); return; } @@ -761,9 +761,24 @@ public class BlockEventListener implements Listener { Location tLocation = BukkitUtil.adapt(to.getLocation()); PlotArea area = tLocation.getPlotArea(); if (area == null) { + if (from.getType() == Material.DRAGON_EGG && fromArea != null) { + event.setCancelled(true); + } return; } Plot plot = area.getOwnedPlot(tLocation); + + if (from.getType() == Material.DRAGON_EGG && fromArea != null) { + final Plot fromPlot = fromArea.getOwnedPlot(fLocation); + + if (fromPlot != null || plot != null) { + if ((fromPlot == null || !fromPlot.equals(plot)) && (plot == null || !plot.equals(fromPlot))) { + event.setCancelled(true); + return; + } + } + } + if (plot != null) { if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { event.setCancelled(true); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index b9eb1fcd7..f64c52f10 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -1103,6 +1103,17 @@ public class PlayerEventListener extends PlotListener implements Listener { } break; } + case LEFT_CLICK_BLOCK: { + Material blockType = block.getType(); + + // todo: when the code above is rearranged, it would be great to beautify this as well. + // will code this as a temporary, specific bug fix (for dragon eggs) + if (blockType != Material.DRAGON_EGG) return; + + eventType = PlayerBlockEventType.INTERACT_BLOCK; + blocktype1 = BukkitAdapter.asBlockType(block.getType()); + break; + } default: return; }