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
This commit is contained in:
dordsor21 2022-11-12 12:35:06 +00:00
parent 28bd993680
commit 73d57937bb
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
7 changed files with 66 additions and 38 deletions

View File

@ -166,7 +166,7 @@ public class BlockEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && !area.getRoadFlag(RedstoneFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(RedstoneFlag.class, false)) {
event.setNewCurrent(0);
}
return;
@ -1084,7 +1084,10 @@ public class BlockEventListener implements Listener {
return;
}
if (plot == null) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
if (!area.isRoadFlagsAndFlagEquals(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 +1095,10 @@ public class BlockEventListener implements Listener {
event.setCancelled(true);
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
if (!area.isRoadFlagsAndFlagEquals(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))

View File

@ -91,7 +91,8 @@ public class BlockEventListener117 implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null || !plot.getFlag(MiscInteractFlag.class)) {
if (plot == null && !area.isRoadFlagsAndFlagEquals(MiscInteractFlag.class, true) || plot != null && !plot.getFlag(
MiscInteractFlag.class)) {
if (plotPlayer != null) {
if (plot != null) {
if (!plot.isAdded(plotPlayer.getUUID())) {

View File

@ -261,7 +261,7 @@ public class EntityEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(InvincibleFlag.class, true)) {
event.setCancelled(true);
}
return;

View File

@ -326,14 +326,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 (!area.isRoadFlagsAndFlagEquals(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))

View File

@ -889,8 +889,7 @@ public class PlayerEventListener implements Listener {
}
} else {
PlotArea area = pp.getPlotAreaAbs();
if (area != null && area.isRoadFlags() && area
.getRoadFlag(PreventCreativeCopyFlag.class)) {
if (area != null && area.isRoadFlagsAndFlagEquals(PreventCreativeCopyFlag.class, true)) {
final ItemStack newStack =
new ItemStack(newItem.getType(), newItem.getAmount());
event.setCursor(newStack);
@ -998,8 +997,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 (!area.isRoadFlagsAndFlagEquals(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 +1010,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 +1593,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 (!area.isRoadFlagsAndFlagEquals(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 +1644,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && !area.getRoadFlag(ItemDropFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(ItemDropFlag.class, false)) {
event.setCancelled(true);
}
return;
@ -1668,7 +1670,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(DropProtectionFlag.class, true)) {
event.setCancelled(true);
}
return;
@ -1690,17 +1692,15 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(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 +1725,14 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalTravelFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(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 +1770,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalsFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(DenyPortalsFlag.class, true)) {
event.setCancelled(true);
return;
}
@ -1801,16 +1799,14 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadFlags() && area.getRoadFlag(LecternReadBookFlag.class)) {
if (area.isRoadFlagsAndFlagEquals(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);
}
}

View File

@ -97,14 +97,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 (!area.isRoadFlagsAndFlagEquals(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 +158,8 @@ public class ProjectileEventListener implements Listener {
if (plot.isAdded(((Player) shooter).getUniqueId()) || plot.getFlag(ProjectilesFlag.class)) {
return;
}
} else if (area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true)) {
return;
}
entity.remove();
@ -163,7 +169,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 (!area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED
)) {
entity.remove();
event.setCancelled(true);
}
@ -194,7 +203,6 @@ public class ProjectileEventListener implements Listener {
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
entity.remove();
event.setCancelled(true);
return;
}
}
}

View File

@ -46,6 +46,7 @@ import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.MathMan;
@ -1242,6 +1243,18 @@ public abstract class PlotArea {
return this.roadFlagContainer.getFlag(flagClass).getValue();
}
/**
* Check if the value of a {@link BooleanFlag} matches the given boolean. If
* road flags are disabled, returns false.
*
* @param flagClass boolean flag to get value of
* @param value boolean value to check flag value against
* @return Flag value or false if road flags disabled
*/
public boolean isRoadFlagsAndFlagEquals(final Class<? extends BooleanFlag<?>> flagClass, boolean value) {
return this.roadFlags && (getRoadFlag(flagClass) == value);
}
/**
* Get the value associated with the specified road flag. This will look at
* the default values stored in {@link GlobalFlagContainer}.