Skip to content

Commit 89511f0

Browse files
Tamikaschupowercasgamer
Tamikaschu
andauthored
Fix: disable sign-coloring when edit-sign flag is false (#4252)
* Initial commit * Update Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java Co-authored-by: powercas_gamer <[email protected]> * Relocated Item check * Added version check when building list of items * Use mutable set and copy to immutable --------- Co-authored-by: powercas_gamer <[email protected]>
1 parent 1a18adc commit 89511f0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java

+61
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.plotsquared.core.plot.flag.implementations.DenyTeleportFlag;
5151
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
5252
import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag;
53+
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
5354
import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag;
5455
import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag;
5556
import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag;
@@ -87,6 +88,7 @@
8788
import org.bukkit.block.Block;
8889
import org.bukkit.block.BlockFace;
8990
import org.bukkit.block.BlockState;
91+
import org.bukkit.block.Sign;
9092
import org.bukkit.block.data.Waterlogged;
9193
import org.bukkit.command.PluginCommand;
9294
import org.bukkit.entity.ArmorStand;
@@ -175,6 +177,33 @@ public class PlayerEventListener implements Listener {
175177
Material.WRITABLE_BOOK,
176178
Material.WRITTEN_BOOK
177179
);
180+
private static final Set<String> DYES;
181+
static {
182+
Set<String> mutableDyes = new HashSet<>(Set.of(
183+
"WHITE_DYE",
184+
"LIGHT_GRAY_DYE",
185+
"GRAY_DYE",
186+
"BLACK_DYE",
187+
"BROWN_DYE",
188+
"RED_DYE",
189+
"ORANGE_DYE",
190+
"YELLOW_DYE",
191+
"LIME_DYE",
192+
"GREEN_DYE",
193+
"CYAN_DYE",
194+
"LIGHT_BLUE_DYE",
195+
"BLUE_DYE",
196+
"PURPLE_DYE",
197+
"MAGENTA_DYE",
198+
"PINK_DYE",
199+
"GLOW_INK_SAC"
200+
));
201+
int[] version = PlotSquared.platform().serverVersion();
202+
if (version[1] >= 20 && version[2] >= 1) {
203+
mutableDyes.add("HONEYCOMB");
204+
}
205+
DYES = Set.copyOf(mutableDyes);
206+
}
178207
private final EventDispatcher eventDispatcher;
179208
private final WorldEdit worldEdit;
180209
private final PlotAreaManager plotAreaManager;
@@ -207,6 +236,38 @@ public PlayerEventListener(
207236
this.plotListener = plotListener;
208237
}
209238

239+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
240+
public void onPlayerDyeSign(PlayerInteractEvent event) {
241+
ItemStack itemStack = event.getItem();
242+
if (itemStack == null) {
243+
return;
244+
}
245+
Block block = event.getClickedBlock();
246+
if (block != null && block.getState() instanceof Sign) {
247+
if (DYES.contains(itemStack.getType().toString())) {
248+
Location location = BukkitUtil.adapt(block.getLocation());
249+
PlotArea area = location.getPlotArea();
250+
if (area == null) {
251+
return;
252+
}
253+
Plot plot = location.getOwnedPlot();
254+
if (plot == null) {
255+
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) {
256+
event.setCancelled(true);
257+
}
258+
return;
259+
}
260+
if (plot.isAdded(event.getPlayer().getUniqueId())) {
261+
return; // allow for added players
262+
}
263+
if (!plot.getFlag(EditSignFlag.class)) {
264+
plot.debug(event.getPlayer().getName() + " could not color the sign because of edit-sign = false");
265+
event.setCancelled(true);
266+
}
267+
}
268+
}
269+
}
270+
210271
@EventHandler(ignoreCancelled = true)
211272
public void onEffect(@NonNull EntityPotionEffectEvent event) {
212273
if (Settings.Enabled_Components.DISABLE_BEACON_EFFECT_OVERFLOW ||

0 commit comments

Comments
 (0)