mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 12:46:46 +01:00
feature: implement road flags as widely as seems reasonable (#3870)
* feature: implement road flags as widely as seems reasonable - Closes #3047 - Any further road flag implementations would be very specific from what I can gather, and thus the gist of #3047 is now implemented * Add javadoc since tag Co-authored-by: Alexander Brandes <mc.cache@web.de> * Create util class for method Co-authored-by: Alexander Brandes <mc.cache@web.de>
This commit is contained in:
parent
2147012beb
commit
b5bc1988e5
@ -56,6 +56,7 @@ import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
|
||||
import com.plotsquared.core.plot.flag.types.BooleanFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -166,7 +167,7 @@ public class BlockEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && !area.getRoadFlag(RedstoneFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, RedstoneFlag.class, false)) {
|
||||
event.setNewCurrent(0);
|
||||
}
|
||||
return;
|
||||
@ -1084,7 +1085,10 @@ public class BlockEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, BlockIgnitionFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_BUILD_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||
@ -1092,7 +1096,10 @@ public class BlockEventListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, BlockIgnitionFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_BUILD_UNOWNED
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||
|
@ -26,6 +26,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.CopperOxideFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -91,7 +92,8 @@ public class BlockEventListener117 implements Listener {
|
||||
}
|
||||
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null || !plot.getFlag(MiscInteractFlag.class)) {
|
||||
if (plot == null && !PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, MiscInteractFlag.class, true) || plot != null && !plot.getFlag(
|
||||
MiscInteractFlag.class)) {
|
||||
if (plotPlayer != null) {
|
||||
if (plot != null) {
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
|
@ -38,6 +38,7 @@ import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.bukkit.Material;
|
||||
@ -261,7 +262,7 @@ public class EntityEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, InvincibleFlag.class, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
|
@ -44,6 +44,7 @@ import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
|
||||
import com.plotsquared.core.plot.flag.types.BooleanFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
@ -326,14 +327,18 @@ public class PaperListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
||||
|
@ -68,6 +68,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -889,8 +890,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
} else {
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
if (area != null && area.isRoadFlags() && area
|
||||
.getRoadFlag(PreventCreativeCopyFlag.class)) {
|
||||
if (area != null && PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, PreventCreativeCopyFlag.class, true)) {
|
||||
final ItemStack newStack =
|
||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||
event.setCursor(newStack);
|
||||
@ -998,8 +998,10 @@ public class PlayerEventListener implements Listener {
|
||||
Plot plot = location.getPlotAbs();
|
||||
BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer());
|
||||
if (plot == null) {
|
||||
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
|
||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, MiscInteractFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_INTERACT_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
||||
@ -1009,9 +1011,7 @@ public class PlayerEventListener implements Listener {
|
||||
} else {
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("done.building_restricted")
|
||||
);
|
||||
pp.sendMessage(TranslatableCaption.of("done.building_restricted"));
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1594,7 +1594,10 @@ public class PlayerEventListener implements Listener {
|
||||
BukkitPlayer pp = BukkitUtil.adapt(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, VehicleBreakFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD))
|
||||
@ -1642,7 +1645,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && !area.getRoadFlag(ItemDropFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ItemDropFlag.class, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
@ -1668,7 +1671,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DropProtectionFlag.class, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
@ -1690,17 +1693,15 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, KeepInventoryFlag.class, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(KeepInventoryFlag.class)) {
|
||||
if (plot.getFlag(KeepInventoryFlag.class)) {
|
||||
plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true");
|
||||
event.getDrops().clear();
|
||||
event.setKeepInventory(true);
|
||||
}
|
||||
plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true");
|
||||
event.getDrops().clear();
|
||||
event.setKeepInventory(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1725,16 +1726,14 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalTravelFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DenyPortalTravelFlag.class, true)) {
|
||||
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);
|
||||
}
|
||||
plot.debug(event.getPlayer().getName() + " did not travel thru a portal because of deny-portal-travel = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1772,7 +1771,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalsFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DenyPortalsFlag.class, true)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1801,16 +1800,14 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(LecternReadBookFlag.class)) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, LecternReadBookFlag.class, true)) {
|
||||
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);
|
||||
}
|
||||
plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ import com.plotsquared.core.plot.PlotHandler;
|
||||
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -97,14 +98,18 @@ public class ProjectileEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
||||
@ -154,6 +159,8 @@ public class ProjectileEventListener implements Listener {
|
||||
if (plot.isAdded(((Player) shooter).getUniqueId()) || plot.getFlag(ProjectilesFlag.class)) {
|
||||
return;
|
||||
}
|
||||
} else if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.remove();
|
||||
@ -163,7 +170,10 @@ public class ProjectileEventListener implements Listener {
|
||||
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
|
||||
pp,
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED
|
||||
)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -194,7 +204,6 @@ public class ProjectileEventListener implements Listener {
|
||||
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* 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.util;
|
||||
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Util class for generic methods relating to plot flags.
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public final class PlotFlagUtil {
|
||||
|
||||
private PlotFlagUtil() {
|
||||
//No-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value of a {@link PlotFlag} matches the given value. If
|
||||
* road flags are disabled for the given plot area, returns false.
|
||||
*
|
||||
* @param flagClass boolean flag to get value of
|
||||
* @param value boolean value to check flag value against
|
||||
* @param <T> The flag value type
|
||||
* @return true if road flag value matches with road flags enabled
|
||||
* @since TODO
|
||||
*/
|
||||
public static <T> boolean isAreaRoadFlagsAndFlagEquals(
|
||||
PlotArea area, final Class<? extends PlotFlag<T, ?>> flagClass, T value
|
||||
) {
|
||||
return area.isRoadFlags() && Objects.equals(area.getRoadFlag(flagClass), value);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user