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 939a9b266..5d56f0ba9 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 @@ -9,6 +9,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.Location; @@ -790,7 +791,7 @@ import java.util.regex.Pattern; // to is identical to the plot's home location, and untrusted-visit is true // i.e. untrusted-visit can override deny-teleport // this is acceptable, because otherwise it wouldn't make sense to have both flags set - if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) { + if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); event.setCancelled(true); 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 5a1056811..0c0526580 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 @@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -140,7 +140,7 @@ import java.util.concurrent.CompletableFuture; } } else { if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER) && - !Flags.UNTRUSTED_VISIT.isTrue(plot)) { + !plot.getFlag(UntrustedVisitFlag.class)) { Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER); return CompletableFuture.completedFuture(false); } 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 3ef4bc00d..7b96bc654 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 @@ -550,6 +550,7 @@ public enum Captions implements Caption { 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_UNTRUSTED("Set to 'false' to disallow untrusted players from visiting the plot", "Flags"), // // FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java index 8c566742f..443dfbeb9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java @@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -131,6 +132,11 @@ public class FlagManager { return getSettingFlag(plot.getArea(), plot.getSettings(), flag); } + public static boolean addPlotFlag(Plot origin, PlotFlag flag, Object value) { + // TODO: Implement this + return true; + } + /** * Add a flag to a plot. * @@ -194,6 +200,11 @@ public class FlagManager { return getPlotFlags(area, settings, false); } + public static boolean removePlotFlag(Plot origin, PlotFlag flag) { + // TODO: Implement + return true; + } + /** * Removes a flag from a certain plot. * diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index b2829b047..d59ba25e9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -1,15 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.flag; -import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.StringMan; - -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; public final class Flags { @@ -114,85 +107,8 @@ public final class Flags { return Captions.FLAG_ERROR_KEEP.getTranslated(); } }; + public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport"); public static final BooleanFlag DENY_EXIT = new BooleanFlag("deny-exit"); - public static final BooleanFlag UNTRUSTED_VISIT = new BooleanFlag("untrusted-visit"); - - private static final HashMap> flags; - - static { - flags = new HashMap<>(); - try { - for (Field field : Flags.class.getFields()) { - String fieldName = field.getName().replace("_", "-").toLowerCase(); - Object fieldValue = field.get(null); - if (!(fieldValue instanceof Flag)) { - continue; - } - Flag flag = (Flag) fieldValue; - if (!flag.getName().equals(fieldName)) { - PlotSquared.debug( - Flags.class + "Field doesn't match: " + fieldName + " != " + flag - .getName()); - } - flags.put(flag.getName(), flag); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Get an immutable collection of registered flags. - * - * @return a collection of registered flags. - */ - public static Collection> getFlags() { - return Collections.unmodifiableCollection(flags.values()); - } - - public static Flag getFlag(String flag) { - return flags.get(flag); - } - - public static void registerFlag(final Flag flag) { - final Flag duplicate = flags.put(flag.getName(), flag); - if (duplicate != null) { - PlotSquared.get().forEachPlotArea(value -> { - if (value.DEFAULT_FLAGS.containsKey(duplicate)) { - Object remove = value.DEFAULT_FLAGS.remove(duplicate); - try { - if (remove instanceof Collection - && remove.getClass().getMethod("toString").getDeclaringClass() - == Object.class) { - value.DEFAULT_FLAGS.put(flag, - flag.parseValue(StringMan.join((Collection) remove, ','))); - } else { - value.DEFAULT_FLAGS.put(flag, flag.parseValue("" + remove)); - } - } catch (NoSuchMethodException neverHappens) { - neverHappens.printStackTrace(); - } - } - }); - PlotSquared.get().forEachPlotRaw(value -> { - if (value.hasFlag(duplicate)) { - Object remove = value.getFlags().remove(duplicate); - try { - if (remove instanceof Collection - && remove.getClass().getMethod("toString").getDeclaringClass() - == Object.class) { - value.getFlags().put(flag, - flag.parseValue(StringMan.join((Collection) remove, ','))); - } else { - value.getFlags().put(flag, flag.parseValue("" + remove)); - } - } catch (NoSuchMethodException neverHappens) { - neverHappens.printStackTrace(); - } - } - }); - } - } } 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 b86085f26..4def71bb4 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 @@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.flags; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; import lombok.Getter; import javax.annotation.Nonnull; @@ -42,6 +43,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(ExplosionFlag.EXPLOSION_FALSE); this.addFlag(MusicFlag.MUSIC_FLAG_NONE); this.addFlag(FlightFlag.FLIGHT_FLAG_FALSE); + this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE); } @Override public void addFlag(PlotFlag flag) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java new file mode 100644 index 000000000..94ec7aabf --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java @@ -0,0 +1,22 @@ +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 UntrustedVisitFlag extends BooleanFlag { + + public static UntrustedVisitFlag UNTRUSTED_VISIT_FLAG_TRUE = new UntrustedVisitFlag(true); + + protected UntrustedVisitFlag(boolean value) { + super(value, Captions.FLAG_DESCRIPTION_UNTRUSTED); + } + + @Override public String getExample() { + return ""; + } + + @Override protected UntrustedVisitFlag flagOf(@NotNull Boolean value) { + return new UntrustedVisitFlag(value); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index dc0e7a3ee..d98f85cc2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -1089,7 +1089,7 @@ public class Plot { * @param flag Flag to set * @param value Flag value */ - public boolean setFlag(Flag flag, Object value) { + public boolean setFlag(PlotFlag flag, Object value) { if (flag == Flags.KEEP && ExpireManager.IMP != null) { ExpireManager.IMP.updateExpired(this); } @@ -1102,7 +1102,7 @@ public class Plot { * @param flag the flag to remove * @return success */ - public boolean removeFlag(Flag flag) { + public boolean removeFlag(PlotFlag flag) { return FlagManager.removePlotFlag(this, flag); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index d96c71c7f..e1105cb46 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -72,7 +72,6 @@ public abstract class PlotArea { public boolean SCHEMATIC_ON_CLAIM = false; public String SCHEMATIC_FILE = "null"; public List SCHEMATICS = null; - public Map, Object> DEFAULT_FLAGS; public boolean USE_ECONOMY = false; public Map> PRICES = new HashMap<>(); public boolean SPAWN_EGGS = false;