From ae2867136aa809c35912cc9eca53cc896e7adfb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 16:39:19 +0200 Subject: [PATCH 1/5] Make the fly flag an enum flag instead. It now accepts: `true`, `false` and `default`, where `default` is the default value, and does not change the flight status at all. --- .../plotsquared/plot/config/Captions.java | 4 +- .../plot/flags/GlobalFlagContainer.java | 6 +- .../flags/implementations/FlightFlag.java | 19 ------ .../plot/flags/implementations/FlyFlag.java | 64 +++++++++++++++++++ .../plot/listener/PlotListener.java | 8 ++- 5 files changed, 75 insertions(+), 26 deletions(-) delete mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 9e7fa737b..366b33e4c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -567,13 +567,15 @@ public enum Captions implements Caption { FLAG_CATEGORY_ENUM("Generic Enum Flags", "Flags"), FLAG_CATEGORY_DECIMAL("Decimal Flags", "Flags"), FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"), + FLAG_CATEGORY_FLY("Flight Flags", "Flags"), FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"), // // FLAG_DESCRIPTION_ENTITY_CAP("Set to an integer value to limit the amount of entities on the plot.", "Flags"), FLAG_DESCRIPTION_EXPLOSION("Set to `true` to enable explosions in the plot, and `false` to disable them.", "Flags"), FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot.", "Flags"), - FLAG_DESCRIPTION_FLIGHT("Set to `true` to enable flight within the plot when in survival or adventure mode.", "Flags"), + FLAG_DESCRIPTION_FLIGHT("Set to `true` to enable flight within the plot when in survival or adventure mode," + + " set to `default` to use the gamemode default, and `false` to disable flight entirely.", "Flags"), FLAG_DESCRIPTION_UNTRUSTED("Set to `false` to disallow untrusted players from visiting the plot.", "Flags"), FLAG_DESCRIPTION_DENY_EXIT("Set to `true` to disallow players from exiting the plot.", "Flags"), FLAG_DESCRIPTION_DESCRIPTION("Plot description. Supports '&' color codes.", "Flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java index 5a9223a61..3aa7759ba 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java @@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Block import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockedCmdsFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.CoralDryFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; @@ -19,7 +20,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Entit import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag; -import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlyFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.GamemodeFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag; @@ -60,7 +61,6 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Serve import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowFormFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowMeltFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.SoilDryFlag; -import com.github.intellectualsites.plotsquared.plot.flags.implementations.CoralDryFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedAttackFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag; @@ -96,7 +96,6 @@ public final class GlobalFlagContainer extends FlagContainer { // Register all default flags here // Boolean flags this.addFlag(ExplosionFlag.EXPLOSION_FALSE); - this.addFlag(FlightFlag.FLIGHT_FLAG_FALSE); this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE); this.addFlag(DenyExitFlag.DENY_EXIT_FLAG_FALSE); this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY); @@ -150,6 +149,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE); this.addFlag(TitlesFlag.TITLES_NONE); + this.addFlag(FlyFlag.FLIGHT_FLAG_DEFAULT); // Integer flags this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java deleted file mode 100644 index ffe9df063..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.flags.implementations; - -import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flags.types.BooleanFlag; -import org.jetbrains.annotations.NotNull; - -public class FlightFlag extends BooleanFlag { - - public static final FlightFlag FLIGHT_FLAG_FALSE = new FlightFlag(false); - - protected FlightFlag(final boolean value) { - super(value, Captions.FLAG_DESCRIPTION_FLIGHT); - } - - @Override protected FlightFlag flagOf(@NotNull Boolean value) { - return new FlightFlag(value); - } - -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java new file mode 100644 index 000000000..2da869b1e --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java @@ -0,0 +1,64 @@ +package com.github.intellectualsites.plotsquared.plot.flags.implementations; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; +import org.jetbrains.annotations.NotNull; + +public class FlyFlag extends PlotFlag { + + public static final FlyFlag FLIGHT_FLAG_DISABLED = new FlyFlag(FlyStatus.DISABLED); + public static final FlyFlag FLIGHT_FLAG_ENABLED = new FlyFlag(FlyStatus.ENABLED); + public static final FlyFlag FLIGHT_FLAG_DEFAULT = new FlyFlag(FlyStatus.DEFAULT); + + protected FlyFlag(final FlyStatus value) { + super(value, Captions.FLAG_CATEGORY_BOOLEAN, Captions.FLAG_DESCRIPTION_FLIGHT); + } + + @Override public FlyFlag parse(@NotNull final String input) { + switch (input.toLowerCase()) { + case "true": + case "enabled": + case "allow": + return FLIGHT_FLAG_ENABLED; + case "false": + case "disabled": + case "disallow": + return FLIGHT_FLAG_DISABLED; + default: + return FLIGHT_FLAG_DEFAULT; + } + } + + @Override public FlyFlag merge(@NotNull final FlyStatus newValue) { + if (newValue == FlyStatus.ENABLED || this.getValue() == FlyStatus.ENABLED) { + return FLIGHT_FLAG_ENABLED; + } + return flagOf(newValue); + } + + @Override public String toString() { + return this.getValue().name().toLowerCase(); + } + + @Override public String getExample() { + return "true"; + } + + @Override protected FlyFlag flagOf(@NotNull final FlyStatus value) { + switch (value) { + case ENABLED: + return FLIGHT_FLAG_ENABLED; + case DISABLED: + return FLIGHT_FLAG_DISABLED; + default: + return FLIGHT_FLAG_DEFAULT; + } + } + + public enum FlyStatus { + ENABLED, + DISABLED, + DEFAULT + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index 12f70a40e..942c5e101 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -124,7 +124,8 @@ public class PlotListener { } } - if (plot.getFlag(FlightFlag.class)) { + final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class); + if (flyStatus != FlyFlag.FlyStatus.DEFAULT) { boolean flight = player.getFlight(); GameMode gamemode = player.getGameMode(); if (flight != (gamemode == GameModes.CREATIVE @@ -132,7 +133,7 @@ public class PlotListener { player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight())); } - player.setFlight(true); + player.setFlight(flyStatus == FlyFlag.FlyStatus.ENABLED); } final GameMode gameMode = plot.getFlag(GamemodeFlag.class); @@ -299,7 +300,8 @@ public class PlotListener { } } - if (plot.getFlag(FlightFlag.class)) { + final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class); + if (flyStatus != FlyFlag.FlyStatus.DEFAULT) { if (player.hasPersistentMeta("flight")) { player.setFlight( ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight"))); From 4ca7a81e964e21a58a919cda858517a8d3c392c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 16:52:10 +0200 Subject: [PATCH 2/5] Fix untrusted-visit. --- .../plotsquared/plot/commands/Visit.java | 8 ++++++-- .../plotsquared/plot/config/Captions.java | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java index 0e70d2acc..f9057307a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java @@ -143,11 +143,15 @@ public class Visit extends Command { return CompletableFuture.completedFuture(false); } } else { - if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER) && !plot - .getFlag(UntrustedVisitFlag.class)) { + if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) { Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER); return CompletableFuture.completedFuture(false); } + if (!plot.getFlag(UntrustedVisitFlag.class) && + !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) { + Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED); + return CompletableFuture.completedFuture(false); + } } confirm.run(this, () -> { if (plot.teleportPlayer(player, TeleportCause.COMMAND)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 366b33e4c..a8bc65c15 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -53,6 +53,7 @@ public enum Captions implements Caption { PERMISSION_ADMIN_UPDATE_NOTIFICATION("plots.admin.update.notify", "static.permissions"), PERMISSION_ADMIN_EXIT_DENIED("plots.admin.exit.denied", "static.permissions"), PERMISSION_ADMIN_ENTRY_DENIED("plots.admin.entry.denied", "static.permissions"), + PERMISSION_ADMIN_VISIT_UNTRUSTED("plots.admin.visit.untrusted", "static.permissions"), PERMISSION_ADMIN_ENTRY_FORCEFIELD("plots.admin.entry.forcefield", "static.permissions"), PERMISSION_COMMANDS_CHAT("plots.admin.command.chat", "static.permissions"), PERMISSION_MERGE_OTHER("plots.merge.other", "static.permissions"), From f6332d2cd91790d733160f7756ea9b6f18c8b0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 16:53:39 +0200 Subject: [PATCH 3/5] Add tab completions to flyflag --- .../plotsquared/plot/flags/implementations/FlyFlag.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java index 2da869b1e..85bbb5335 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlyFlag.java @@ -4,6 +4,9 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.Collection; + public class FlyFlag extends PlotFlag { public static final FlyFlag FLIGHT_FLAG_DISABLED = new FlyFlag(FlyStatus.DISABLED); @@ -55,6 +58,10 @@ public class FlyFlag extends PlotFlag { } } + @Override public Collection getTabCompletions() { + return Arrays.asList("true", "false", "default"); + } + public enum FlyStatus { ENABLED, DISABLED, From 616d22ceac7556e02036b97f840f3a949a791a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 17:01:41 +0200 Subject: [PATCH 4/5] Fix liquid-flow --- .../bukkit/listeners/PlayerEvents.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 291c574ed..a4c5f8ce5 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1439,6 +1439,18 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChange(BlockFromToEvent event) { Block from = event.getBlock(); + + // Check liquid flow flag inside of origin plot too + final Location fLocation = BukkitUtil.getLocation(from.getLocation()); + final PlotArea fromArea = fLocation.getPlotArea(); + if (fromArea != null) { + final Plot plot = fromArea.getOwnedPlot(fLocation); + if (plot != null && !plot.getFlag(LiquidFlowFlag.class) && event.getBlock().isLiquid()) { + event.setCancelled(true); + return; + } + } + Block to = event.getToBlock(); Location tLocation = BukkitUtil.getLocation(to.getLocation()); PlotArea area = tLocation.getPlotArea(); @@ -1446,7 +1458,6 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlot(tLocation); - Location fLocation = BukkitUtil.getLocation(from.getLocation()); if (plot != null) { if (plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); @@ -1456,12 +1467,8 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); return; } - if (!plot.getFlag(LiquidFlowFlag.class)) { - switch (to.getType()) { - case WATER: - case LAVA: - event.setCancelled(true); - } + if (!plot.getFlag(LiquidFlowFlag.class) && event.getBlock().isLiquid()) { + event.setCancelled(true); } } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects .equals(null, area.getOwnedPlot(fLocation))) { From 7ac389b698699a9472005785dd66c57ba23ad97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 17:15:17 +0200 Subject: [PATCH 5/5] Fix block ignition location check --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index a4c5f8ce5..bf4fc32eb 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -2222,7 +2222,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } - Plot plot = area.getOwnedPlotAbs(location1); + Plot plot = area.getOwnedPlot(location1); if (player != null) { PlotPlayer pp = BukkitUtil.getPlayer(player); if (plot == null) {