Add no-portals and deny-portal-travel flag

This commit is contained in:
NotMyFault 2021-05-14 15:51:20 +02:00
parent 58ad9db5ed
commit a7c4b40fcc
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
5 changed files with 146 additions and 0 deletions

View File

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

View File

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

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 DenyPortalTravelFlag extends BooleanFlag<DenyPortalTravelFlag> {
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;
}
}

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 DenyPortalsFlag extends BooleanFlag<DenyPortalsFlag> {
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;
}
}

View File

@ -573,6 +573,8 @@
"flags.flag_description_blocked_cmds": "<gray>A list of commands that are blocked in the plot.</gray>",
"flags.flag_description_keep": "<gray>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).</gray>",
"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_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).",