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 c32344cbf..33b4108f7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -50,6 +50,7 @@ import com.plotsquared.core.plot.flag.implementations.DenyPortalsFlag; import com.plotsquared.core.plot.flag.implementations.DenyTeleportFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag; +import com.plotsquared.core.plot.flag.implementations.EditSignFlag; import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag; import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag; import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag; @@ -87,6 +88,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; import org.bukkit.block.data.Waterlogged; import org.bukkit.command.PluginCommand; import org.bukkit.entity.ArmorStand; @@ -131,6 +133,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerSignOpenEvent; import org.bukkit.event.player.PlayerTakeLecternBookEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; @@ -1873,4 +1876,28 @@ public class PlayerEventListener implements Listener { } } + @EventHandler(ignoreCancelled = true) + @SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot + public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) { + Sign sign = event.getSign(); + Location location = BukkitUtil.adapt(sign.getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) { + event.setCancelled(true); + } + return; + } + if (plot.isAdded(event.getPlayer().getUniqueId())) { + return; // allow for added players + } + if (!plot.getFlag(EditSignFlag.class)) { + plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false"); + event.setCancelled(true); + } + } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java index 25b12d39d..3323ac5a6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java @@ -41,6 +41,7 @@ import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag; import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag; +import com.plotsquared.core.plot.flag.implementations.EditSignFlag; import com.plotsquared.core.plot.flag.implementations.EntityCapFlag; import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag; import com.plotsquared.core.plot.flag.implementations.ExplosionFlag; @@ -151,6 +152,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(DeviceInteractFlag.DEVICE_INTERACT_FALSE); this.addFlag(DisablePhysicsFlag.DISABLE_PHYSICS_FALSE); this.addFlag(DropProtectionFlag.DROP_PROTECTION_FALSE); + this.addFlag(EditSignFlag.EDIT_SIGN_FALSE); this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE); this.addFlag(ExplosionFlag.EXPLOSION_FALSE); this.addFlag(ForcefieldFlag.FORCEFIELD_FALSE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java new file mode 100644 index 000000000..3464f753f --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java @@ -0,0 +1,20 @@ +package com.plotsquared.core.plot.flag.implementations; + +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.plot.flag.types.BooleanFlag; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class EditSignFlag extends BooleanFlag { + public static final EditSignFlag EDIT_SIGN_TRUE = new EditSignFlag(true); + public static final EditSignFlag EDIT_SIGN_FALSE = new EditSignFlag(false); + + private EditSignFlag(final boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_edit_sign")); + } + + @Override + protected EditSignFlag flagOf(@NonNull final Boolean value) { + return value ? EDIT_SIGN_TRUE : EDIT_SIGN_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 9434ab814..51e5a2d81 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -554,6 +554,7 @@ "flags.flag_description_device_interact": "Set to `true` to allow devices to be interacted with in the plot.", "flags.flag_description_disable_physics": "Set to `true` to disable block physics in the plot.", "flags.flag_description_drop_protection": "Set to `true` to prevent dropped items from being picked up by non-members of the plot.", + "flags.flag_description_edit_sign": "Set to `true` to allow editing signs in the plot.", "flags.flag_description_feed": "Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).", "flags.flag_description_forcefield": "Set to `true` to enable member forcefield in the plot.", "flags.flag_description_grass_grow": "Set to `false` to prevent grass from growing within the plot.", diff --git a/build.gradle.kts b/build.gradle.kts index f81bccdd5..0efb605f5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import com.diffplug.gradle.spotless.SpotlessPlugin import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin -import java.net.URI import xyz.jpenilla.runpaper.task.RunServer +import java.net.URI plugins { java @@ -218,16 +218,18 @@ tasks.getByName("jar") { enabled = false } -val supportedVersions = listOf("1.16.5", "1.17", "1.17.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20") +val supportedVersions = listOf("1.16.5", "1.17.1", "1.18.2", "1.19.4", "1.20.1") tasks { - supportedVersions.forEach { - register("runServer-$it") { - minecraftVersion(it) - pluginJars(*project(":plotsquared-bukkit").getTasksByName("shadowJar", false).map { (it as Jar).archiveFile } + supportedVersions.forEach { version -> + register("runServer-$version") { + minecraftVersion(version) + pluginJars(*project(":plotsquared-bukkit") + .getTasksByName("shadowJar", false) + .map { (it as Jar).archiveFile } .toTypedArray()) jvmArgs("-DPaper.IgnoreJavaVersion=true", "-Dcom.mojang.eula.agree=true") group = "run paper" - runDirectory.set(file("run-$it")) + runDirectory.set(file("run-$version")) } } }