Add lectern-read-book flag

Fixes https://github.com/IntellectualSites/PlotSquared/issues/2980
This commit is contained in:
NotMyFault 2021-05-14 18:22:02 +02:00
parent a7c4b40fcc
commit 0341111f8f
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
5 changed files with 74 additions and 1 deletions

View File

@ -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);
}
}
}
}

View File

@ -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 -> {
});

View File

@ -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);

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<LecternReadBookFlag> {
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;
}
}

View File

@ -575,6 +575,7 @@
"flags.flag_description_keep_inventory": "<gray>Prevents players from dropping their items when they die inside of the plot.</gray>",
"flags.flag_description_deny_portal_travel": "<gray>Prevents players from travelling across dimensions by using portals.</gray>",
"flags.flag_description_deny_portals": "<gray>Prevents players from creating portals of any kind.</gray>",
"flags.flag_description_lectern_read_book": "<gray>Prevents players taking books from lecterns.</gray>",
"flags.flag_description_prevent_creative_copy": "<gray>Prevents people from copying item NBT data in the plot unless they're added as members.</gray>",
"flags.flag_description_leaf_decay": "<gray>Set to `false` to prevent leaves from decaying.",
"flags.flag_error_boolean": "Flag value must be a boolean (true | false).",