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 7473e15c6..ee1d4d91a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -61,6 +61,7 @@ import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag; import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag; import com.plotsquared.core.plot.flag.implementations.ItemDropFlag; import com.plotsquared.core.plot.flag.implementations.KeepInventoryFlag; +import com.plotsquared.core.plot.flag.implementations.LecternReadBookFlag; import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag; import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag; import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag; @@ -136,6 +137,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.PlayerTakeLecternBookEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; @@ -1737,4 +1739,26 @@ public class PlayerEventListener extends PlotListener implements Listener { } } + @EventHandler + public void onPlayerTakeLecternBook(PlayerTakeLecternBookEvent event) { + Location location = BukkitUtil.adapt(event.getPlayer().getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (area.isRoadFlags() && area.getRoadFlag(LecternReadBookFlag.class)) { + event.setCancelled(true); + } + return; + } + if (plot.getFlag(LecternReadBookFlag.class)) { + if (plot.getFlag(LecternReadBookFlag.class)) { + plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true"); + event.setCancelled(true); + } + } + } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 979699261..b37920e40 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1678,7 +1678,7 @@ public class Plot { updateWorldBorder(); } this.getPlotModificationManager().setSign(player.getName()); - player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", String.valueOf(this.getId()))); + player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", this.getId().toString())); if (teleport && Settings.Teleport.ON_CLAIM) { teleportPlayer(player, TeleportCause.COMMAND, result -> { }); 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 80feb0a01..007095363 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 @@ -72,6 +72,7 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.flag.implementations.KeepInventoryFlag; import com.plotsquared.core.plot.flag.implementations.KelpGrowFlag; import com.plotsquared.core.plot.flag.implementations.LeafDecayFlag; +import com.plotsquared.core.plot.flag.implementations.LecternReadBookFlag; import com.plotsquared.core.plot.flag.implementations.LiquidFlowFlag; import com.plotsquared.core.plot.flag.implementations.MiscBreakFlag; import com.plotsquared.core.plot.flag.implementations.MiscCapFlag; @@ -189,6 +190,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(CropGrowFlag.CROP_GROW_TRUE); this.addFlag(DenyPortalTravelFlag.DENY_PORTAL_TRAVEL_FALSE); this.addFlag(DenyPortalsFlag.DENY_PORTALS_FALSE); + this.addFlag(LecternReadBookFlag.LECTERN_READ_BOOK_FALSE); // Enum Flags this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LecternReadBookFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LecternReadBookFlag.java new file mode 100644 index 000000000..126146ba1 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LecternReadBookFlag.java @@ -0,0 +1,46 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2021 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +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 LecternReadBookFlag extends BooleanFlag { + + public static final LecternReadBookFlag LECTERN_READ_BOOK_TRUE = new LecternReadBookFlag(true); + public static final LecternReadBookFlag LECTERN_READ_BOOK_FALSE = new LecternReadBookFlag(false); + + private LecternReadBookFlag(final boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_lectern_read_book")); + } + + @Override + protected LecternReadBookFlag flagOf(final @NonNull Boolean value) { + return value ? LECTERN_READ_BOOK_TRUE : LECTERN_READ_BOOK_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 0fa937cbb..a36726441 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -575,6 +575,7 @@ "flags.flag_description_keep_inventory": "Prevents players from dropping their items when they die inside of the plot.", "flags.flag_description_deny_portal_travel": "Prevents players from travelling across dimensions by using portals.", "flags.flag_description_deny_portals": "Prevents players from creating portals of any kind.", + "flags.flag_description_lectern_read_book": "Prevents players taking books from lecterns.", "flags.flag_description_prevent_creative_copy": "Prevents people from copying item NBT data in the plot unless they're added as members.", "flags.flag_description_leaf_decay": "Set to `false` to prevent leaves from decaying.", "flags.flag_error_boolean": "Flag value must be a boolean (true | false).",