From a7c4b40fcc60e0f244a563dc9cee75af5ed50a95 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Fri, 14 May 2021 15:51:20 +0200 Subject: [PATCH] Add `no-portals` and `deny-portal-travel` flag --- .../bukkit/listener/PlayerEventListener.java | 48 +++++++++++++++++++ .../core/plot/flag/GlobalFlagContainer.java | 4 ++ .../implementations/DenyPortalTravelFlag.java | 46 ++++++++++++++++++ .../flag/implementations/DenyPortalsFlag.java | 46 ++++++++++++++++++ Core/src/main/resources/lang/messages_en.json | 2 + 5 files changed, 146 insertions(+) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalTravelFlag.java create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalsFlag.java 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 b4dd2fd3b..7473e15c6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -51,6 +51,8 @@ import com.plotsquared.core.plot.flag.FlagContainer; import com.plotsquared.core.plot.flag.implementations.AnimalInteractFlag; import com.plotsquared.core.plot.flag.implementations.BlockedCmdsFlag; import com.plotsquared.core.plot.flag.implementations.ChatFlag; +import com.plotsquared.core.plot.flag.implementations.DenyPortalTravelFlag; +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; @@ -131,12 +133,14 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLocaleChangeEvent; 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.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; import org.bukkit.event.vehicle.VehicleMoveEvent; +import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -1689,4 +1693,48 @@ public class PlayerEventListener extends PlotListener implements Listener { player.setLocale(Locale.forLanguageTag(event.getLocale().substring(0, 2))); } + @EventHandler + public void onPortalEnter(PlayerPortalEvent 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(DenyPortalTravelFlag.class)) { + event.setCancelled(true); + } + return; + } + if (plot.getFlag(DenyPortalTravelFlag.class)) { + if (plot.getFlag(DenyPortalTravelFlag.class)) { + plot.debug(event.getPlayer().getName() + " did not travel thru a portal because of deny-portal-travel = true"); + event.setCancelled(true); + } + } + } + + @EventHandler + public void onPortalCreation(PortalCreateEvent event) { + Location location = BukkitUtil.adapt(event.getEntity().getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (area.isRoadFlags() && area.getRoadFlag(DenyPortalsFlag.class)) { + event.setCancelled(true); + } + return; + } + if (plot.getFlag(DenyPortalsFlag.class)) { + if (plot.getFlag(DenyPortalsFlag.class)) { + plot.debug(event.getEntity().getName() + " did not create a portal because of deny-portals = true"); + 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 603a85e6f..80feb0a01 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 @@ -38,6 +38,8 @@ import com.plotsquared.core.plot.flag.implementations.ChatFlag; import com.plotsquared.core.plot.flag.implementations.CoralDryFlag; import com.plotsquared.core.plot.flag.implementations.CropGrowFlag; import com.plotsquared.core.plot.flag.implementations.DenyExitFlag; +import com.plotsquared.core.plot.flag.implementations.DenyPortalTravelFlag; +import com.plotsquared.core.plot.flag.implementations.DenyPortalsFlag; import com.plotsquared.core.plot.flag.implementations.DenyTeleportFlag; import com.plotsquared.core.plot.flag.implementations.DescriptionFlag; import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag; @@ -185,6 +187,8 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(PreventCreativeCopyFlag.PREVENT_CREATIVE_COPY_FALSE); this.addFlag(LeafDecayFlag.LEAF_DECAY_TRUE); this.addFlag(CropGrowFlag.CROP_GROW_TRUE); + this.addFlag(DenyPortalTravelFlag.DENY_PORTAL_TRAVEL_FALSE); + this.addFlag(DenyPortalsFlag.DENY_PORTALS_FALSE); // Enum Flags this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalTravelFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalTravelFlag.java new file mode 100644 index 000000000..be036a2a2 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalTravelFlag.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 DenyPortalTravelFlag extends BooleanFlag { + + public static final DenyPortalTravelFlag DENY_PORTAL_TRAVEL_TRUE = new DenyPortalTravelFlag(true); + public static final DenyPortalTravelFlag DENY_PORTAL_TRAVEL_FALSE = new DenyPortalTravelFlag(false); + + private DenyPortalTravelFlag(final boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_deny_portal_travel")); + } + + @Override + protected DenyPortalTravelFlag flagOf(final @NonNull Boolean value) { + return value ? DENY_PORTAL_TRAVEL_TRUE : DENY_PORTAL_TRAVEL_FALSE; + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalsFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalsFlag.java new file mode 100644 index 000000000..66f1c6273 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyPortalsFlag.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 DenyPortalsFlag extends BooleanFlag { + + public static final DenyPortalsFlag DENY_PORTALS_TRUE = new DenyPortalsFlag(true); + public static final DenyPortalsFlag DENY_PORTALS_FALSE = new DenyPortalsFlag(false); + + private DenyPortalsFlag(final boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_deny_portals")); + } + + @Override + protected DenyPortalsFlag flagOf(final @NonNull Boolean value) { + return value ? DENY_PORTALS_TRUE : DENY_PORTALS_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index b86cdd4fd..0fa937cbb 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -573,6 +573,8 @@ "flags.flag_description_blocked_cmds": "A list of commands that are blocked in the plot.", "flags.flag_description_keep": "Prevents the plot from expiring. Can be set to: true, false, the number of milliseconds to keep the plot for or a timestamp (3w 2d 5h).", "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_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).",