diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java index e8c4ac63c..6f28f707c 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.events; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList; /** * Called when a Flag is added to a plot. */ -public class PlotFlagAddEvent extends PlotEvent implements Cancellable { +public class PlotFlagAddEvent extends PlotFlagEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final Flag flag; private boolean cancelled; /** @@ -20,24 +19,14 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable { * @param flag Flag that was added * @param plot Plot to which the flag was added */ - public PlotFlagAddEvent(Flag flag, Plot plot) { - super(plot); - this.flag = flag; + public PlotFlagAddEvent(PlotFlag flag, Plot plot) { + super(plot, flag); } public static HandlerList getHandlerList() { return handlers; } - /** - * Get the flag involved. - * - * @return Flag - */ - public Flag getFlag() { - return this.flag; - } - @Override public HandlerList getHandlers() { return handlers; } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java new file mode 100644 index 000000000..424349239 --- /dev/null +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java @@ -0,0 +1,22 @@ +package com.github.intellectualsites.plotsquared.bukkit.events; + +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; +import com.github.intellectualsites.plotsquared.plot.object.Plot; + +public abstract class PlotFlagEvent extends PlotEvent { + private final PlotFlag flag; + + protected PlotFlagEvent(Plot plot, PlotFlag flag) { + super(plot); + this.flag = flag; + } + + /** + * Get the flag involved + * + * @return the flag involved + */ + public PlotFlag getFlag() { + return flag; + } +} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java index 3e3e48b55..d0d5724d4 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.events; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList; /** * Called when a flag is removed from a plot */ -public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable { +public class PlotFlagRemoveEvent extends PlotFlagEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final Flag flag; private boolean cancelled; /** @@ -20,24 +19,14 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable { * @param flag Flag that was removed * @param plot Plot from which the flag was removed */ - public PlotFlagRemoveEvent(Flag flag, Plot plot) { - super(plot); - this.flag = flag; + public PlotFlagRemoveEvent(PlotFlag flag, Plot plot) { + super(plot, flag); } public static HandlerList getHandlerList() { return handlers; } - /** - * Get the flag involved - * - * @return Flag - */ - public Flag getFlag() { - return this.flag; - } - @Override public HandlerList getHandlers() { return handlers; } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java index a982f39fd..b55aa0245 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -118,7 +118,7 @@ public class EntitySpawnListener implements Listener { } return; } - if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { event.setCancelled(true); } switch (entity.getType()) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java index d2d588970..d16723db0 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -80,7 +80,7 @@ import java.util.UUID; } public static void handleForcefield(Player player, PlotPlayer plotPlayer, Plot plot) { - if (Flags.FORCEFIELD.isTrue(plot)) { + if (plot.getFlag(ForcefieldFlag.class)) { UUID uuid = plotPlayer.getUUID(); if (plot.isAdded(uuid)) { Set players = getNearbyPlayers(player, plot); 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 3063586ef..5a6c7be5f 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 @@ -7,10 +7,63 @@ import com.github.intellectualsites.plotsquared.bukkit.util.UpdateUtility; 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.AnimalAttackFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag; +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.DenyTeleportFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.EntityCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileAttackFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceFormFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceMeltFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.KelpGrowFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.LiquidFlowFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscBreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobPlaceFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MycelGrowFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlayerInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PveFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PvpFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.RedstoneFlag; +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.TamedAttackFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleBreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleCapFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleUseFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VineGrowFlag; +import com.github.intellectualsites.plotsquared.plot.flags.types.BlockTypeWrapper; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotHandler; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.util.EntityUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; @@ -135,7 +188,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.regex.Pattern; @@ -185,7 +237,7 @@ import java.util.regex.Pattern; public static boolean checkEntity(Entity entity, Plot plot) { if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot - .getArea().DEFAULT_FLAGS.isEmpty()) { + .getArea().getFlagContainer().getFlagMap().isEmpty()) { return false; } switch (entity.getType()) { @@ -220,11 +272,13 @@ import java.util.regex.Pattern; case UNKNOWN: case WITHER_SKULL: // non moving / unmovable - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP); + return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED); case ARMOR_STAND: case ITEM_FRAME: case PAINTING: - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MiscCapFlag.MISC_CAP_UNLIMITED); // misc case BOAT: case MINECART: @@ -234,7 +288,9 @@ import java.util.regex.Pattern; case MINECART_HOPPER: case MINECART_MOB_SPAWNER: case MINECART_TNT: - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + VehicleCapFlag.VEHICLE_CAP_UNLIMITED); case BAT: case CHICKEN: case CAT: @@ -267,8 +323,10 @@ import java.util.regex.Pattern; case WOLF: case ZOMBIE_HORSE: // animal - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + AnimalCapFlag.ANIMAL_CAP_UNLIMITED); case BLAZE: case CAVE_SPIDER: case CREEPER: @@ -303,26 +361,39 @@ import java.util.regex.Pattern; case RAVAGER: // monster return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); + .checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + HostileCapFlag.HOSTILE_CAP_UNLIMITED); default: if (entity instanceof LivingEntity) { if (entity instanceof Animals || entity instanceof WaterMob) { - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + AnimalCapFlag.ANIMAL_CAP_UNLIMITED); } else if (entity instanceof Monster) { - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + HostileCapFlag.HOSTILE_CAP_UNLIMITED); } else { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED); } } if (entity instanceof Vehicle) { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + VehicleCapFlag.VEHICLE_CAP_UNLIMITED); } if (entity instanceof Hanging) { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MiscCapFlag.MISC_CAP_UNLIMITED); } - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP); + return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED); } } @@ -409,7 +480,7 @@ import java.util.regex.Pattern; if (plot == null) { return; } - if (Flags.REDSTONE.isFalse(plot)) { + if (!plot.getFlag(RedstoneFlag.class)) { event.setNewCurrent(0); return; } @@ -463,7 +534,7 @@ import java.util.regex.Pattern; if (plot == null) { return; } - if (Flags.REDSTONE.isFalse(plot)) { + if (!plot.getFlag(RedstoneFlag.class)) { event.setCancelled(true); } return; @@ -485,7 +556,7 @@ import java.util.regex.Pattern; if (plot == null) { return; } - if (Flags.DISABLE_PHYSICS.isFalse(plot)) { + if (plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); } return; @@ -631,10 +702,10 @@ import java.util.regex.Pattern; if (plot == null) { return; } - Optional> flag = plot.getFlag(Flags.BLOCKED_CMDS); - if (flag.isPresent() && !Permissions + + List blockedCommands = plot.getFlag(BlockedCmdsFlag.class); + if (!blockedCommands.isEmpty() && !Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { - List blockedCommands = flag.get(); String part = parts[0]; if (parts[0].contains(":")) { part = parts[0].split(":")[1]; @@ -771,12 +842,12 @@ import java.util.regex.Pattern; } Plot plot = area.getPlot(location); if (plot != null) { - final boolean result = Flags.DENY_TELEPORT.allowsTeleport(pp, plot); + final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot); // there is one possibility to still allow teleportation: // 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); @@ -1078,11 +1149,13 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + List destroy = plot.getFlag(BreakFlag.class); Block block = event.getBlock(); - if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asBlockType(block.getType()))) { - return; + final BlockType blockType = BukkitAdapter.asBlockType(block.getType()); + for (final BlockTypeWrapper blockTypeWrapper : destroy) { + if (blockTypeWrapper.accepts(blockType)) { + return; + } } if (Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { @@ -1091,7 +1164,7 @@ import java.util.regex.Pattern; MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); - } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); @@ -1129,7 +1202,7 @@ import java.util.regex.Pattern; } Plot plot = area.getOwnedPlot(location); if (plot != null) { - if (Flags.EXPLOSION.isTrue(plot)) { + if (plot.getFlag(ExplosionFlag.class)) { List meta = event.getEntity().getMetadata("plot"); Plot origin; if (meta.isEmpty()) { @@ -1204,7 +1277,7 @@ import java.util.regex.Pattern; PlotArea area = location.getPlotArea(); if (area != null) { Plot plot = area.getOwnedPlot(location); - if (plot != null && Flags.MOB_BREAK.isTrue(plot)) { + if (plot != null && plot.getFlag(MobPlaceFlag.class)) { return; } event.setCancelled(true); @@ -1233,7 +1306,7 @@ import java.util.regex.Pattern; Player player = (Player) entity; if (!plot.hasOwner()) { PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); - if (Flags.ICE_FORM.isTrue(plot)) { + if (plot.getFlag(IceFormFlag.class)) { return; } event.setCancelled(true); @@ -1241,7 +1314,7 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - if (Flags.ICE_FORM.isTrue(plot)) { + if (plot.getFlag(IceFormFlag.class)) { return; } event.setCancelled(true); @@ -1249,7 +1322,7 @@ import java.util.regex.Pattern; } return; } - if (!Flags.ICE_FORM.isTrue(plot)) { + if (!plot.getFlag(IceFormFlag.class)) { event.setCancelled(true); } } @@ -1272,22 +1345,22 @@ import java.util.regex.Pattern; } switch (event.getSource().getType()) { case GRASS: - if (Flags.GRASS_GROW.isFalse(plot)) { + if (!plot.getFlag(GrassGrowFlag.class)) { event.setCancelled(true); } break; case MYCELIUM: - if (Flags.MYCEL_GROW.isFalse(plot)) { + if (!plot.getFlag(MycelGrowFlag.class)) { event.setCancelled(true); } break; case VINE: - if (Flags.VINE_GROW.isFalse(plot)) { + if (!plot.getFlag(VineGrowFlag.class)) { event.setCancelled(true); } break; case KELP: - if (Flags.KELP_GROW.isFalse(plot)) { + if (!plot.getFlag(KelpGrowFlag.class)) { event.setCancelled(true); } break; @@ -1313,14 +1386,14 @@ import java.util.regex.Pattern; switch (event.getNewState().getType()) { case SNOW: case SNOW_BLOCK: - if (Flags.SNOW_FORM.isFalse(plot)) { + if (!plot.getFlag(SnowFormFlag.class)) { event.setCancelled(true); } return; case ICE: case FROSTED_ICE: case PACKED_ICE: - if (Flags.ICE_FORM.isFalse(plot)) { + if (!plot.getFlag(IceFormFlag.class)) { event.setCancelled(true); } } @@ -1351,10 +1424,9 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + List destroy = plot.getFlag(BreakFlag.class); Block block = event.getBlock(); - if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asBlockType(block.getType())) || Permissions + if (destroy.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType()))) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } @@ -1385,17 +1457,17 @@ import java.util.regex.Pattern; } switch (block.getType()) { case ICE: - if (Flags.ICE_MELT.isFalse(plot)) { + if (!plot.getFlag(IceMeltFlag.class)) { event.setCancelled(true); } break; case SNOW: - if (Flags.SNOW_MELT.isFalse(plot)) { + if (!plot.getFlag(SnowMeltFlag.class)) { event.setCancelled(true); } break; case FARMLAND: - if (Flags.SOIL_DRY.isFalse(plot)) { + if (!plot.getFlag(SoilDryFlag.class)) { event.setCancelled(true); } break; @@ -1414,7 +1486,7 @@ import java.util.regex.Pattern; Plot plot = area.getOwnedPlot(tLocation); Location fLocation = BukkitUtil.getLocation(from.getLocation()); if (plot != null) { - if (Flags.DISABLE_PHYSICS.isFalse(plot)) { + if (plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); return; } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects @@ -1422,7 +1494,7 @@ import java.util.regex.Pattern; event.setCancelled(true); return; } - if (Flags.LIQUID_FLOW.isFalse(plot)) { + if (!plot.getFlag(LiquidFlowFlag.class)) { switch (to.getType()) { case WATER: case LAVA: @@ -1816,7 +1888,7 @@ import java.util.regex.Pattern; e.setCancelled(true); } } else { - if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); e.setCancelled(true); @@ -1834,7 +1906,7 @@ import java.util.regex.Pattern; if (plot.isAdded(uuid)) { return; } - if (Flags.MISC_INTERACT.isTrue(plot)) { + if (plot.getFlag(MiscInteractFlag.class)) { return; } if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { @@ -1866,7 +1938,7 @@ import java.util.regex.Pattern; return; } Plot plot = area.getOwnedPlot(location); - if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) { + if (plot == null || !plot.getFlag(ExplosionFlag.class)) { event.setCancelled(true); } event.blockList().removeIf( @@ -2119,7 +2191,7 @@ import java.util.regex.Pattern; return; } Plot plot = area.getOwnedPlotAbs(location); - if (plot == null || plot.getFlag(Flags.DISABLE_PHYSICS, false)) { + if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); return; } @@ -2155,7 +2227,7 @@ import java.util.regex.Pattern; } Plot plot = location.getOwnedPlot(); - if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) { + if (plot == null || !plot.getFlag(BlockBurnFlag.class)) { event.setCancelled(true); } @@ -2198,7 +2270,7 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } - } else if (Flags.BLOCK_IGNITION.isFalse(plot)) { + } else if (!plot.getFlag(BlockIgnitionFlag.class)) { event.setCancelled(true); } } else { @@ -2207,7 +2279,7 @@ import java.util.regex.Pattern; return; } if (ignitingEntity != null) { - if (!plot.getFlag(Flags.BLOCK_IGNITION, false)) { + if (!plot.getFlag(BlockIgnitionFlag.class)) { event.setCancelled(true); return; } @@ -2233,11 +2305,11 @@ import java.util.regex.Pattern; Block ignitingBlock = event.getIgnitingBlock(); Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot(); if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && ( - !plot.getFlag(Flags.BLOCK_IGNITION, false) || plotIgnited == null + !plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited.equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( - !plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null + !plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited.equals(plot))) { event.setCancelled(true); } @@ -2273,8 +2345,12 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { - if (Flags.USE.contains(plot, BukkitAdapter.asItemType(block.getType()))) { - return; + List use = plot.getFlag(UseFlag.class); + final BlockType blockType = BukkitAdapter.asBlockType(block.getType()); + for (final BlockTypeWrapper blockTypeWrapper : use) { + if (blockTypeWrapper.accepts(blockType)) { + return; + } } if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { return; @@ -2282,7 +2358,7 @@ import java.util.regex.Pattern; MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); - } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); @@ -2333,10 +2409,13 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> use = plot.getFlag(Flags.USE); + List use = plot.getFlag(UseFlag.class); Block block = event.getBlockClicked(); - if (use.isPresent() && use.get().contains(BukkitAdapter.asBlockType(block.getType()))) { - return; + final BlockType blockType = BukkitAdapter.asBlockType(block.getType()); + for (final BlockTypeWrapper blockTypeWrapper : use) { + if (blockTypeWrapper.accepts(blockType)) { + return; + } } if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { return; @@ -2344,7 +2423,7 @@ import java.util.regex.Pattern; MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); - } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); @@ -2404,7 +2483,7 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(pp.getUUID())) { - if (!plot.getFlag(Flags.HANGING_PLACE, false)) { + if (!plot.getFlag(HangingPlaceFlag.class)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); @@ -2445,7 +2524,7 @@ import java.util.regex.Pattern; event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (plot.getFlag(Flags.HANGING_BREAK, false)) { + if (plot.getFlag(HangingBreakFlag.class)) { return; } if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { @@ -2474,7 +2553,7 @@ import java.util.regex.Pattern; event.setCancelled(true); } } else if (!plot.isAdded(player.getUUID())) { - if (!plot.getFlag(Flags.HANGING_BREAK, false)) { + if (!plot.getFlag(HangingBreakFlag.class)) { if (!Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, @@ -2514,26 +2593,26 @@ import java.util.regex.Pattern; } } else if (!plot.isAdded(pp.getUUID())) { Entity entity = event.getRightClicked(); - if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT, false)) { + if (entity instanceof Monster && plot.getFlag(HostileInteractFlag.class)) { return; } - if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT, false)) { + if (entity instanceof Animals && plot.getFlag(AnimalInteractFlag.class)) { return; } - if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot - .getFlag(Flags.TAMED_INTERACT, false)) { + if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot.getFlag( + TamedInteractFlag.class)) { return; } - if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE, false)) { + if (entity instanceof Vehicle && plot.getFlag(VehicleUseFlag.class)) { return; } - if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) { + if (entity instanceof Player && plot.getFlag(PlayerInteractFlag.class)) { return; } - if (entity instanceof Villager && plot.getFlag(Flags.VILLAGER_INTERACT, false)) { + if (entity instanceof Villager && plot.getFlag(VillagerInteractFlag.class)) { return; } - if (entity instanceof ItemFrame && plot.getFlag(Flags.MISC_INTERACT, false)) { + if (entity instanceof ItemFrame && plot.getFlag(MiscInteractFlag.class)) { return; } if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) { @@ -2573,7 +2652,7 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(pp.getUUID())) { - if (plot.getFlag(Flags.VEHICLE_BREAK, false)) { + if (plot.getFlag(VehicleBreakFlag.class)) { return; } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { @@ -2739,9 +2818,9 @@ import java.util.regex.Pattern; if (player != null) { PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (victim instanceof Hanging) { // hanging - if (plot != null && (plot.getFlag(Flags.HANGING_BREAK, false) || plot - .isAdded(plotPlayer.getUUID()))) { - if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot + .isAdded(plotPlayer.getUUID())) { + if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); return false; @@ -2755,7 +2834,7 @@ import java.util.regex.Pattern; return false; } } else if (victim.getType() == EntityType.ARMOR_STAND) { - if (plot != null && (plot.getFlag(Flags.MISC_BREAK, false) || plot + if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot .isAdded(plotPlayer.getUUID()))) { return true; } @@ -2766,8 +2845,8 @@ import java.util.regex.Pattern; } } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster - if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK, false) || plot - .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) { + if (plot != null && (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || + plot.isAdded(plotPlayer.getUUID()))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2776,8 +2855,8 @@ import java.util.regex.Pattern; return false; } } else if (victim instanceof Tameable) { // victim is tameable - if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot - .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) { + if (plot != null && (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || + plot.isAdded(plotPlayer.getUUID()))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2787,7 +2866,7 @@ import java.util.regex.Pattern; } } else if (victim instanceof Player) { if (plot != null) { - if (Flags.PVP.isFalse(plot) && !Permissions + if (!plot.getFlag(PvpFlag.class) && !Permissions .hasPermission(plotPlayer, "plots.admin.pvp." + stub)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub); @@ -2802,8 +2881,8 @@ import java.util.regex.Pattern; return false; } } else if (victim instanceof Creature) { // victim is animal - if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK, false) || plot - .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) { + if (plot != null && (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) + || plot.isAdded(plotPlayer.getUUID()))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2814,7 +2893,7 @@ import java.util.regex.Pattern; } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event return true; } else { // victim is something else - if (plot != null && (plot.getFlag(Flags.PVE, false) || plot + if (plot != null && (plot.getFlag(PveFlag.class) || plot .isAdded(plotPlayer.getUUID()))) { return true; } @@ -2827,7 +2906,7 @@ import java.util.regex.Pattern; return true; } else if (dplot != null && (!dplot.equals(vplot) || Objects .equals(dplot.guessOwner(), vplot.guessOwner()))) { - return vplot != null && Flags.PVE.isTrue(vplot); + return vplot != null && vplot.getFlag(PveFlag.class); } //disable the firework damage. too much of a headache to support at the moment. if (vplot != null) { @@ -2836,7 +2915,7 @@ import java.util.regex.Pattern; return false; } } - return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow + return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow && !(victim instanceof Creature))); } @@ -2896,10 +2975,10 @@ import java.util.regex.Pattern; return; } } else if (!plot.isAdded(pp.getUUID())) { - Set place = plot.getFlag(Flags.PLACE, null); + List place = plot.getFlag(PlaceFlag.class); if (place != null) { Block block = event.getBlock(); - if (place.contains(BukkitAdapter.asBlockType(block.getType()))) { + if (place.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) { return; } } @@ -2909,7 +2988,7 @@ import java.util.regex.Pattern; event.setCancelled(true); return; } - } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); @@ -2917,7 +2996,7 @@ import java.util.regex.Pattern; return; } } - if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) { + if (plot.getFlag(DisablePhysicsFlag.class)) { Block block = event.getBlockPlaced(); if (block.getType().hasGravity()) { sendBlockChange(block.getLocation(), block.getBlockData()); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java index b103ed7de..05cb01894 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -3,8 +3,13 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.flag.IntervalFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DropProtectionFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.InstabreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.InvincibleFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.ItemDropFlag; +import com.github.intellectualsites.plotsquared.plot.flags.types.TimedFlag; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -28,7 +33,6 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; -import java.util.Optional; import java.util.UUID; @SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener { @@ -90,7 +94,7 @@ import java.util.UUID; if (plot == null) { return; } - if (Flags.INSTABREAK.isTrue(plot)) { + if (plot.getFlag(InstabreakFlag.class)) { Block block = event.getBlock(); BlockBreakEvent call = new BlockBreakEvent(block, player); Bukkit.getServer().getPluginManager().callEvent(call); @@ -108,7 +112,7 @@ import java.util.UUID; if (plot == null) { return; } - if (Flags.INVINCIBLE.isTrue(plot)) { + if (plot.getFlag(InvincibleFlag.class)) { event.setCancelled(true); } } @@ -122,7 +126,7 @@ import java.util.UUID; } UUID uuid = pp.getUUID(); if (!plot.isAdded(uuid)) { - if (Flags.ITEM_DROP.isFalse(plot)) { + if (!plot.getFlag(ItemDropFlag.class)) { event.setCancelled(true); } } @@ -131,12 +135,14 @@ import java.util.UUID; @EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) { Player player = event.getPlayer(); Plot plot = event.getPlot(); - Optional feed = plot.getFlag(Flags.FEED); - feed.ifPresent(value -> feedRunnable - .put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20))); - Optional heal = plot.getFlag(Flags.HEAL); - heal.ifPresent(value -> healRunnable - .put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20))); + TimedFlag.Timed feed = plot.getFlag(FeedFlag.class); + if (feed.getInterval() != 0 && feed.getValue() != 0) { + feedRunnable.put(player.getUniqueId(), new Interval(feed.getInterval(), feed.getValue(), 20)); + } + TimedFlag.Timed heal = plot.getFlag(HealFlag.class); + if (heal.getInterval() != 0 && heal.getValue() != 0) { + healRunnable.put(player.getUniqueId(), new Interval(heal.getInterval(), heal.getValue(), 20)); + } } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { @@ -166,7 +172,7 @@ import java.util.UUID; return; } UUID uuid = pp.getUUID(); - if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) { + if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) { event.setCancelled(true); } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java index e76a1e23e..58d6b6c11 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java @@ -18,7 +18,7 @@ import com.github.intellectualsites.plotsquared.bukkit.events.PlotMergeEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlotRateEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -75,11 +75,11 @@ public final class BukkitEventUtil extends EventUtil { return callEvent(new PlotDeleteEvent(plot)); } - @Override public boolean callFlagAdd(Flag flag, Plot plot) { + @Override public boolean callFlagAdd(PlotFlag flag, Plot plot) { return callEvent(new PlotFlagAddEvent(flag, plot)); } - @Override public boolean callFlagRemove(Flag flag, Plot plot, Object value) { + @Override public boolean callFlagRemove(PlotFlag flag, Plot plot, Object value) { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } diff --git a/Core/build.gradle b/Core/build.gradle index 83de66a50..a5f7c8be2 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -15,6 +15,7 @@ dependencies { annotationProcessor("org.projectlombok:lombok:1.18.8") testAnnotationProcessor("org.projectlombok:lombok:1.18.8") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61") + implementation("org.jetbrains:annotations:18.0.0") } sourceCompatibility = 1.8 diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java index 610362953..7e7b4dc73 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java @@ -2,9 +2,8 @@ package com.github.intellectualsites.plotsquared.api; import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.Caption; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -164,19 +163,10 @@ import java.util.UUID; * @see #sendConsoleMessage(String) * @see Captions */ - public void sendConsoleMessage(Captions caption) { + public void sendConsoleMessage(Caption caption) { sendConsoleMessage(caption.getTranslated()); } - /** - * Registers a flag for use in plots. - * - * @param flag the flag to register - */ - public void addFlag(Flag flag) { - Flags.registerFlag(flag); - } - /** * Gets the PlotSquared class. * diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index d09918d3d..8758a5fe0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -81,7 +81,8 @@ public abstract class Command { && types[2] == String[].class && types[3] == RunnableVal3.class && types[4] == RunnableVal2.class) { Command tmp = new Command(this, true) { - @Override public CompletableFuture execute(PlotPlayer player, String[] args, + @Override + public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { try { @@ -264,14 +265,13 @@ public abstract class Command { if (totalPages != 0) { // Back new PlotMessage().text("<-").color("$1").command(baseCommand + " " + page).text(" | ") .color("$3").text("->").color("$3").text(Captions.CLICKABLE.getTranslated()) - .color("$2") - .send(player); + .color("$2").send(player); } } /** * @param player Caller - * @param args Arguments + * @param args Arguments * @param confirm Instance, Success, Failure * @return CompletableFuture true if the command executed fully, false in * any other case diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java index 965e95644..283383df9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java @@ -186,7 +186,7 @@ public class JSONObject { * @param object An object that has fields that should be used to make a JSONObject. * @param names An array of strings, the names of the fields to be obtained from the object. */ - public JSONObject(Object object, String names[]) { + public JSONObject(Object object, String[] names) { this(); Class c = object.getClass(); for (String name : names) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 429e1396b..4356891ab 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -5,6 +5,8 @@ import com.github.intellectualsites.plotsquared.configuration.MemorySection; import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration; import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerialization; import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere; +import com.github.intellectualsites.plotsquared.plot.config.Caption; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.Settings; @@ -151,7 +153,7 @@ import java.util.zip.ZipInputStream; // // Register configuration serializable classes // -// ConfigurationSerialization.registerClass(BlockState.class, "BlockState"); + // ConfigurationSerialization.registerClass(BlockState.class, "BlockState"); ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket"); try { @@ -193,6 +195,17 @@ import java.util.zip.ZipInputStream; if (Settings.Enabled_Components.DATABASE) { setupDatabase(); } + + // Check if we need to convert old flag values, etc + if (!getConfigurationVersion().equalsIgnoreCase("v5")) { + // Perform upgrade + if (DBFunc.dbManager.convertFlags()) { + log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!"); + // Update the config version + setConfigurationVersion("v5"); + } + } + // Comments CommentManager.registerDefaultInboxes(); // Kill entities @@ -243,7 +256,8 @@ import java.util.zip.ZipInputStream; if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { if (this.IMP.initWorldEdit()) { - PlotSquared.log(Captions.PREFIX + "&6" + IMP.getPluginName() + " hooked into WorldEdit."); + PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName() + + " hooked into WorldEdit."); this.worldedit = WorldEdit.getInstance(); WorldEdit.getInstance().getEventBus().register(new WESubscriber()); if (Settings.Enabled_Components.COMMANDS) { @@ -280,7 +294,7 @@ import java.util.zip.ZipInputStream; } if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { debug("`" + world + "` was not properly loaded - " + IMP.getPluginName() - + " will now try to load it properly: "); + + " will now try to load it properly: "); debug( " - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); debug( @@ -316,7 +330,7 @@ import java.util.zip.ZipInputStream; e.printStackTrace(); } - PlotSquared.log(Captions.PREFIX + Captions + PlotSquared.log(Captions.PREFIX + CaptionUtility .format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(), IMP.getPluginName())); } @@ -343,7 +357,9 @@ import java.util.zip.ZipInputStream; * @see IPlotMain#log(String) */ public static void log(Object message) { - if (message == null || message.toString().isEmpty()) { + if (message == null || (message instanceof Caption ? + ((Caption) message).getTranslated().isEmpty() : + message.toString().isEmpty())) { return; } if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { @@ -1644,9 +1660,9 @@ import java.util.zip.ZipInputStream; this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile); if (this.worlds.contains("worlds")) { - if (!this.worlds.contains("configuration_version") || !this.worlds - .getString("configuration_version") - .equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION)) { + if (!this.worlds.contains("configuration_version") || + (!this.worlds.getString("configuration_version").equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && + !this.worlds.getString("configuration_version").equalsIgnoreCase("v5"))) { // Conversion needed log(Captions.LEGACY_CONFIG_FOUND.getTranslated()); try { @@ -1657,10 +1673,8 @@ import java.util.zip.ZipInputStream; this.worlds.getConfigurationSection("worlds"); final LegacyConverter converter = new LegacyConverter(worlds); converter.convert(); - this.worlds - .set("configuration_version", LegacyConverter.CONFIGURATION_VERSION); - this.worlds.set("worlds", worlds); // Redundant, but hey... ¯\_(ツ)_/¯ - this.worlds.save(this.worldsFile); + this.worlds.set("worlds", worlds); + this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION); log(Captions.LEGACY_CONFIG_DONE.getTranslated()); } catch (final Exception e) { log(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated()); @@ -1736,6 +1750,15 @@ import java.util.zip.ZipInputStream; return true; } + public String getConfigurationVersion() { + return this.worlds.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION).toString(); + } + + public void setConfigurationVersion(final String newVersion) throws IOException { + this.worlds.set("configuration_version", newVersion); + this.worlds.save(this.worldsFile); + } + /** * Setup the storage file (load + save missing nodes). */ @@ -1766,7 +1789,8 @@ import java.util.zip.ZipInputStream; if (this.version != null) { this.style.set("Version", this.version.toString()); } - this.style.set("Information", "Left Row: PlotSquared color codes ($), right row: Minecraft color codes (&)"); + this.style.set("Information", + "Left Row: PlotSquared color codes ($), right row: Minecraft color codes (&)"); Map object = new HashMap<>(16); object.put("color.1", "6"); object.put("color.2", "7"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java index 6c2423021..70e3a71eb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java @@ -19,8 +19,11 @@ import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "add", description = "Allow a user to build in a plot while the plot owner is online.", - usage = "/plot add ", category = CommandCategory.SETTINGS, permission = "plots.add", - requiredType = RequiredType.PLAYER) public class Add extends Command { + usage = "/plot add ", + category = CommandCategory.SETTINGS, + permission = "plots.add", + requiredType = RequiredType.PLAYER) +public class Add extends Command { public Add() { super(MainCommand.getInstance(), true); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Alias.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Alias.java index f569674f8..e2bbde0c3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Alias.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Alias.java @@ -12,11 +12,14 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -@CommandDeclaration(command = "setalias", permission = "plots.alias", - description = "Set the plot name", usage = "/plot alias ", +@CommandDeclaration(command = "setalias", + permission = "plots.alias", + description = "Set the plot name", + usage = "/plot alias ", aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"}, - category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class Alias - extends SubCommand { + category = CommandCategory.SETTINGS, + requiredType = RequiredType.PLAYER) +public class Alias extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java index 2a9195028..9c4a548f9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java @@ -33,11 +33,15 @@ import java.util.ArrayList; import java.util.Objects; import java.util.Set; -@CommandDeclaration(command = "area", permission = "plots.area", - category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, - description = "Create a new PlotArea", aliases = "world", - usage = "/plot area ", confirmation = true) public class Area - extends SubCommand { +@CommandDeclaration(command = "area", + permission = "plots.area", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.NONE, + description = "Create a new PlotArea", + aliases = "world", + usage = "/plot area ", + confirmation = true) +public class Area extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { @@ -135,14 +139,14 @@ import java.util.Set; if (WorldUtil.IMP.isWorld(world)) { PlotSquared.get().loadWorld(world, null); Captions.SETUP_FINISHED.send(player); - player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND); + player.teleport(WorldUtil.IMP.getSpawn(world), + TeleportCause.COMMAND); if (area.TERRAIN != 3) { ChunkManager.largeRegionTask(world, region, new RunnableVal() { @Override public void run(BlockVector2 value) { - AugmentedUtils - .generate(world, value.getX(), value.getZ(), - null); + AugmentedUtils.generate(world, value.getX(), + value.getZ(), null); } }, null); } @@ -258,7 +262,8 @@ import java.util.Set; String world = SetupUtils.manager.setupWorld(object); if (WorldUtil.IMP.isWorld(world)) { Captions.SETUP_FINISHED.send(player); - player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND); + player.teleport(WorldUtil.IMP.getSpawn(world), + TeleportCause.COMMAND); } else { MainUtil.sendMessage(player, "An error occurred while creating the world: " @@ -285,13 +290,15 @@ import java.util.Set; } if (WorldUtil.IMP.isWorld(pa.worldname)) { if (!player.getLocation().getWorld().equals(pa.worldname)) { - player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), TeleportCause.COMMAND); + player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), + TeleportCause.COMMAND); } } else { object.terrain = 0; object.type = 0; SetupUtils.manager.setupWorld(object); - player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), TeleportCause.COMMAND); + player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), + TeleportCause.COMMAND); } player.setMeta("area_create_area", pa); MainUtil.sendMessage(player, @@ -432,10 +439,11 @@ import java.util.Set; "$4Stop the server and delete: " + area.worldname + "/region"); return false; } - ChunkManager - .largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { + ChunkManager.largeRegionTask(area.worldname, area.getRegion(), + new RunnableVal() { @Override public void run(BlockVector2 value) { - AugmentedUtils.generate(area.worldname, value.getX(), value.getZ(), null); + AugmentedUtils + .generate(area.worldname, value.getX(), value.getZ(), null); } }, () -> player.sendMessage("Regen complete")); return true; @@ -463,9 +471,10 @@ import java.util.Set; center = WorldUtil.IMP.getSpawn(area.worldname); } else { CuboidRegion region = area.getRegion(); - center = - new Location(area.worldname, region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, - 0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); + center = new Location(area.worldname, region.getMinimumPoint().getX() + + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, + 0, region.getMinimumPoint().getZ() + + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); center.setY(1 + WorldUtil.IMP .getHighestBlock(area.worldname, center.getX(), center.getZ())); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index 8f751a316..86c540a42 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; @@ -22,9 +23,13 @@ import org.jetbrains.annotations.Nullable; import java.util.Set; -@CommandDeclaration(command = "auto", permission = "plots.auto", - category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, - description = "Claim the nearest plot", aliases = "a", usage = "/plot auto [length,width]") +@CommandDeclaration(command = "auto", + permission = "plots.auto", + category = CommandCategory.CLAIMING, + requiredType = RequiredType.NONE, + description = "Claim the nearest plot", + aliases = "a", + usage = "/plot auto [length,width]") public class Auto extends SubCommand { @Deprecated public static PlotId getNextPlotId(PlotId id, int step) { @@ -176,7 +181,7 @@ public class Auto extends SubCommand { try { String[] split = args[0].split(",|;"); if (split[1] == null) { - MainUtil.sendMessage(player,"Correct use /plot auto [length,width]"); + MainUtil.sendMessage(player, "Correct use /plot auto [length,width]"); size_x = 1; size_z = 1; } else { @@ -219,12 +224,13 @@ public class Auto extends SubCommand { sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent: " + schematic); return true; } - if (!Permissions.hasPermission(player, - Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)); + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), + schematic)); return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java index df48c1aed..b0bb41bef 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java @@ -9,16 +9,21 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; -@CommandDeclaration(command = "setbiome", permission = "plots.set.biome", - description = "Set the plot biome", usage = "/plot biome [biome]", - aliases = {"biome", "sb", "setb", "b"}, category = CommandCategory.APPEARANCE, - requiredType = RequiredType.NONE) public class Biome extends SetCommand { +@CommandDeclaration(command = "setbiome", + permission = "plots.set.biome", + description = "Set the plot biome", + usage = "/plot biome [biome]", + aliases = {"biome", "sb", "setb", "b"}, + category = CommandCategory.APPEARANCE, + requiredType = RequiredType.NONE) +public class Biome extends SetCommand { @Override public boolean set(final PlotPlayer player, final Plot plot, final String value) { BiomeType biome = null; try { biome = BiomeTypes.get(value.toLowerCase()); - } catch (final Exception ignore) {} + } catch (final Exception ignore) { + } if (biome == null) { String biomes = StringMan .join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.getTranslated()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index dbfd37768..dbfee3067 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; @@ -12,13 +12,16 @@ import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "buy", description = "Buy the plot you are standing on", - usage = "/plot buy", permission = "plots.buy", category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE) public class Buy extends Command { +@CommandDeclaration(command = "buy", + description = "Buy the plot you are standing on", + usage = "/plot buy", + permission = "plots.buy", + category = CommandCategory.CLAIMING, + requiredType = RequiredType.NONE) +public class Buy extends Command { public Buy() { super(MainCommand.getInstance(), true); @@ -41,11 +44,10 @@ import java.util.concurrent.CompletableFuture; Set plots = plot.getConnectedPlots(); checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(), Captions.CANT_CLAIM_MORE_PLOTS); - Optional flag = plot.getFlag(Flags.PRICE); - if (!flag.isPresent()) { + double price = plot.getFlag(PriceFlag.class); + if (price <= 0) { throw new CommandException(Captions.NOT_FOR_SALE); } - final double price = flag.get(); checkTrue(player.getMoney() >= price, Captions.CANNOT_AFFORD_PLOT); player.withdraw(price); // Failure @@ -58,7 +60,7 @@ import java.util.concurrent.CompletableFuture; if (owner != null) { Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } - plot.removeFlag(Flags.PRICE); + plot.removeFlag(PriceFlag.class); plot.setOwner(player.getUUID()); Captions.CLAIMED.send(player); whenDone.run(Buy.this, CommandResult.SUCCESS); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java index c2a3daf84..c5aee38de 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java @@ -3,9 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -@CommandDeclaration(command = "chat", description = "Toggle plot chat on or off", - usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT, - requiredType = RequiredType.PLAYER) public class Chat extends SubCommand { +@CommandDeclaration(command = "chat", + description = "Toggle plot chat on or off", + usage = "/plot chat [on|off]", + permission = "plots.chat", + category = CommandCategory.CHAT, + requiredType = RequiredType.PLAYER) +public class Chat extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { MainCommand.getInstance().toggle.chat(this, player, new String[0], null, null); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java index 367cbdea7..d07cb96c5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; @@ -16,9 +17,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.google.common.primitives.Ints; -@CommandDeclaration(command = "claim", aliases = "c", - description = "Claim the current plot you're standing on", category = CommandCategory.CLAIMING, - requiredType = RequiredType.PLAYER, permission = "plots.claim", usage = "/plot claim") +@CommandDeclaration(command = "claim", + aliases = "c", + description = "Claim the current plot you're standing on", + category = CommandCategory.CLAIMING, + requiredType = RequiredType.PLAYER, + permission = "plots.claim", + usage = "/plot claim") public class Claim extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -37,8 +42,7 @@ public class Claim extends SubCommand { int grants = 0; if (currentPlots >= player.getAllowedPlots()) { if (player.hasPersistentMeta("grantedPlots")) { - grants = - Ints.fromByteArray(player.getPersistentMeta("grantedPlots")); + grants = Ints.fromByteArray(player.getPersistentMeta("grantedPlots")); if (grants <= 0) { player.removePersistentMeta("grantedPlots"); return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS); @@ -57,9 +61,8 @@ public class Claim extends SubCommand { return sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent: " + schematic); } - if (!Permissions - .hasPermission(player, Captions - .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { return sendMessage(player, Captions.NO_SCHEMATIC_PERMISSION, schematic); @@ -85,8 +88,7 @@ public class Claim extends SubCommand { if (grants == 1) { player.removePersistentMeta("grantedPlots"); } else { - player.setPersistentMeta("grantedPlots", - Ints.toByteArray(grants - 1)); + player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1)); } sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1)); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java index d736154fd..d9a2bb1e1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java @@ -4,8 +4,8 @@ import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnalysisFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; @@ -16,9 +16,15 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "clear", description = "Clear the plot you stand on", requiredType = RequiredType.NONE, - permission = "plots.clear", category = CommandCategory.APPEARANCE, usage = "/plot clear", - aliases = "reset", confirmation = true) public class Clear extends Command { +@CommandDeclaration(command = "clear", + description = "Clear the plot you stand on", + requiredType = RequiredType.NONE, + permission = "plots.clear", + category = CommandCategory.APPEARANCE, + usage = "/plot clear", + aliases = "reset", + confirmation = true) +public class Clear extends Command { // Note: To clear a specific plot use /plot clear // The syntax also works with any command: /plot @@ -36,7 +42,7 @@ import java.util.concurrent.CompletableFuture; .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_CLEAR), Captions.NO_PLOT_PERMS); checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER); - checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions + checkTrue(!Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot) || Permissions .hasPermission(player, Captions.PERMISSION_CONTINUE), Captions.DONE_ALREADY_DONE); confirm.run(this, () -> { final long start = System.currentTimeMillis(); @@ -45,11 +51,11 @@ import java.util.concurrent.CompletableFuture; GlobalBlockQueue.IMP.addEmptyTask(() -> { plot.removeRunning(); // If the state changes, then mark it as no longer done - if (plot.getFlag(Flags.DONE).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.DONE); + if (DoneFlag.isDone(plot)) { + plot.removeFlag(DoneFlag.class); } - if (plot.getFlag(Flags.ANALYSIS).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.ANALYSIS); + if (!plot.getFlag(AnalysisFlag.class).isEmpty()) { + plot.removeFlag(AnalysisFlag.class); } MainUtil.sendMessage(player, Captions.CLEARING_DONE, "" + (System.currentTimeMillis() - start)); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java index f1f9a401c..2a5aa6a66 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java @@ -22,10 +22,13 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "cluster", aliases = "clusters", - category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, - permission = "plots.cluster", description = "Manage a plot cluster") public class Cluster - extends SubCommand { +@CommandDeclaration(command = "cluster", + aliases = "clusters", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.NONE, + permission = "plots.cluster", + description = "Manage a plot cluster") +public class Cluster extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java index 3958f2d39..4b8ae5101 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java @@ -6,7 +6,8 @@ import lombok.RequiredArgsConstructor; /** * CommandCategory. */ -@RequiredArgsConstructor public enum CommandCategory { +@RequiredArgsConstructor +public enum CommandCategory { /** * Claiming CommandConfig. * Such as: /plot claim diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java index 171a5bfe5..98d2406a1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java @@ -16,8 +16,12 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.Arrays; import java.util.Map.Entry; -@CommandDeclaration(command = "comment", aliases = {"msg"}, description = "Comment on a plot", - category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER, permission = "plots.comment") +@CommandDeclaration(command = "comment", + aliases = {"msg"}, + description = "Comment on a plot", + category = CommandCategory.CHAT, + requiredType = RequiredType.PLAYER, + permission = "plots.comment") public class Comment extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java index a9341f373..442c0808d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java @@ -19,10 +19,13 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -@CommandDeclaration(command = "condense", permission = "plots.admin", +@CommandDeclaration(command = "condense", + permission = "plots.admin", usage = "/plot condense [radius]", - description = "Condense a plotworld", category = CommandCategory.ADMINISTRATION, - requiredType = RequiredType.CONSOLE) public class Condense extends SubCommand { + description = "Condense a plotworld", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.CONSOLE) +public class Condense extends SubCommand { public static boolean TASK = false; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Confirm.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Confirm.java index 75a4709b8..477abfcc4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Confirm.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Confirm.java @@ -9,9 +9,11 @@ import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -@CommandDeclaration(command = "confirm", permission = "plots.use", - description = "Confirm an action", category = CommandCategory.INFO) public class Confirm - extends SubCommand { +@CommandDeclaration(command = "confirm", + permission = "plots.use", + description = "Confirm an action", + category = CommandCategory.INFO) +public class Confirm extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { CmdInstance command = CmdConfirm.getPending(player); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Continue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Continue.java index 961742c1b..76dae49ff 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Continue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Continue.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; 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.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; @@ -11,8 +11,10 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; @CommandDeclaration(command = "continue", description = "Continue a plot that was previously marked as done", - permission = "plots.continue", category = CommandCategory.SETTINGS, - requiredType = RequiredType.PLAYER) public class Continue extends SubCommand { + permission = "plots.continue", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.PLAYER) +public class Continue extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { Plot plot = player.getCurrentPlot(); @@ -24,7 +26,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); return false; } - if (!plot.hasFlag(Flags.DONE)) { + if (!DoneFlag.isDone(plot)) { MainUtil.sendMessage(player, Captions.DONE_NOT_DONE); return false; } @@ -39,7 +41,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); return false; } - plot.removeFlag(Flags.DONE); + plot.removeFlag(DoneFlag.class); MainUtil.sendMessage(player, Captions.DONE_REMOVED); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Copy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Copy.java index de77513bc..7ffce21e4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Copy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Copy.java @@ -8,9 +8,14 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; -@CommandDeclaration(command = "copy", permission = "plots.copy", aliases = {"copypaste"}, - category = CommandCategory.CLAIMING, description = "Copy a plot", usage = "/plot copy ", - requiredType = RequiredType.NONE) public class Copy extends SubCommand { +@CommandDeclaration(command = "copy", + permission = "plots.copy", + aliases = {"copypaste"}, + category = CommandCategory.CLAIMING, + description = "Copy a plot", + usage = "/plot copy ", + requiredType = RequiredType.NONE) +public class Copy extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CreateRoadSchematic.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CreateRoadSchematic.java index 70b5952b1..f0b430b52 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CreateRoadSchematic.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CreateRoadSchematic.java @@ -9,11 +9,14 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -@CommandDeclaration(command = "createroadschematic", aliases = {"crs"}, - category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.PLAYER, +@CommandDeclaration(command = "createroadschematic", + aliases = {"crs"}, + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.PLAYER, permission = "plots.createroadschematic", description = "Add a road schematic to your world using the roads around your current plot", - usage = "/plot createroadschematic") public class CreateRoadSchematic extends SubCommand { + usage = "/plot createroadschematic") +public class CreateRoadSchematic extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { Location location = player.getLocation(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DatabaseCommand.java similarity index 95% rename from Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java rename to Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DatabaseCommand.java index abbddc9ca..ec089ba29 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DatabaseCommand.java @@ -22,11 +22,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map.Entry; -@CommandDeclaration(command = "database", aliases = {"convert"}, - category = CommandCategory.ADMINISTRATION, permission = "plots.database", - description = "Convert/Backup Storage", requiredType = RequiredType.CONSOLE, - usage = "/plot database [area] ") public class Database - extends SubCommand { +@CommandDeclaration(command = "database", + aliases = {"convert"}, + category = CommandCategory.ADMINISTRATION, + permission = "plots.database", + description = "Convert/Backup Storage", + requiredType = RequiredType.CONSOLE, + usage = "/plot database [area] ") +public class DatabaseCommand extends SubCommand { public static void insertPlots(final SQLManager manager, final List plots, final PlotPlayer player) { @@ -159,7 +162,7 @@ import java.util.Map.Entry; } try { SQLManager manager = new SQLManager(implementation, prefix, true); - Database.insertPlots(manager, plots, player); + DatabaseCommand.insertPlots(manager, plots, player); return true; } catch (ClassNotFoundException | SQLException e) { MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java index ce9a6d3a5..ad1fc6d2e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java @@ -9,8 +9,11 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.Map; -@CommandDeclaration(command = "debug", category = CommandCategory.DEBUG, - description = "Show debug information", usage = "/plot debug [msg]", permission = "plots.admin") +@CommandDeclaration(command = "debug", + category = CommandCategory.DEBUG, + description = "Show debug information", + usage = "/plot debug [msg]", + permission = "plots.admin") public class Debug extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugAllowUnsafe.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugAllowUnsafe.java index 8413eae22..621593873 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugAllowUnsafe.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugAllowUnsafe.java @@ -9,9 +9,12 @@ import java.util.List; import java.util.UUID; @CommandDeclaration(command = "debugallowunsafe", - description = "Allow unsafe actions until toggled off", usage = "/plot debugallowunsafe", - category = CommandCategory.DEBUG, requiredType = RequiredType.NONE, - permission = "plots.debugallowunsafe") public class DebugAllowUnsafe extends SubCommand { + description = "Allow unsafe actions until toggled off", + usage = "/plot debugallowunsafe", + category = CommandCategory.DEBUG, + requiredType = RequiredType.NONE, + permission = "plots.debugallowunsafe") +public class DebugAllowUnsafe extends SubCommand { public static final List unsafeAllowed = new ArrayList<>(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java index 3c8b854e5..b3afca084 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java @@ -22,9 +22,13 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "debugclaimtest", description = - "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. " - + "Execution time may vary", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, permission = "plots.debugclaimtest") +@CommandDeclaration(command = "debugclaimtest", + description = + "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. " + + "Execution time may vary", + category = CommandCategory.DEBUG, + requiredType = RequiredType.CONSOLE, + permission = "plots.debugclaimtest") public class DebugClaimTest extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -56,7 +60,8 @@ public class DebugClaimTest extends SubCommand { PlotManager manager = area.getPlotManager(); CompletableFuture.runAsync(() -> { ArrayList ids = MainUtil.getPlotSelectionIds(min, max); - MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!"); + MainUtil.sendMessage(player, + "&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!"); for (PlotId id : ids) { Plot plot = area.getPlotAbs(id); if (plot.hasOwner()) { @@ -74,7 +79,8 @@ public class DebugClaimTest extends SubCommand { BiMap map = UUIDHandler.getUuidMap(); UUID uuid = map.get(new StringWrapper(line)); if (uuid == null) { - for (Map.Entry stringWrapperUUIDEntry : map.entrySet()) { + for (Map.Entry stringWrapperUUIDEntry : map + .entrySet()) { if (stringWrapperUUIDEntry.getKey().value.toLowerCase() .startsWith(line.toLowerCase())) { uuid = stringWrapperUUIDEntry.getValue(); @@ -86,11 +92,13 @@ public class DebugClaimTest extends SubCommand { uuid = UUIDHandler.getUUID(line, null); } if (uuid != null) { - MainUtil.sendMessage(player, " - &aFound plot: " + plot.getId() + " : " + line); + MainUtil.sendMessage(player, + " - &aFound plot: " + plot.getId() + " : " + line); plot.setOwner(uuid); MainUtil.sendMessage(player, " - &8Updated plot: " + plot.getId()); } else { - MainUtil.sendMessage(player, " - &cInvalid PlayerName: " + plot.getId() + " : " + line); + MainUtil.sendMessage(player, + " - &cInvalid PlayerName: " + plot.getId() + " : " + line); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java index 8bafa55b7..0a40120a9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java @@ -6,8 +6,8 @@ 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.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; +import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.listener.WEManager; import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; @@ -55,9 +55,12 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "debugexec", permission = "plots.admin", - description = "Mutli-purpose debug command", aliases = {"exec", "$"}, - category = CommandCategory.DEBUG) public class DebugExec extends SubCommand { +@CommandDeclaration(command = "debugexec", + permission = "plots.admin", + description = "Mutli-purpose debug command", + aliases = {"exec", "$"}, + category = CommandCategory.DEBUG) +public class DebugExec extends SubCommand { private ScriptEngine engine; private Bindings scope; @@ -120,7 +123,6 @@ import java.util.concurrent.CompletableFuture; this.scope.put("Settings", new Settings()); this.scope.put("StringMan", new StringMan()); this.scope.put("MathMan", new MathMan()); - this.scope.put("FlagManager", new FlagManager()); // Classes this.scope.put("Location", Location.class); @@ -220,10 +222,11 @@ import java.util.concurrent.CompletableFuture; return false; } String flag = args[1]; - for (Plot plot : PlotSquared.get().getBasePlots()) { - Flag flag1 = FlagManager.getFlag(flag); - if (plot.getFlag(flag1).isPresent()) { - plot.removeFlag(flag1); + final PlotFlag flagInstance = + GlobalFlagContainer.getInstance().getFlagFromString(flag); + if (flagInstance != null) { + for (Plot plot : PlotSquared.get().getBasePlots()) { + plot.removeFlag(flagInstance); } } return MainUtil.sendMessage(player, "Cleared flag: " + flag); @@ -306,8 +309,8 @@ import java.util.concurrent.CompletableFuture; System.getProperty("line.separator")); new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null, RequiredType.NONE, CommandCategory.DEBUG) { - @Override public CompletableFuture execute(PlotPlayer player, String[] args, - RunnableVal3 confirm, + @Override public CompletableFuture execute(PlotPlayer player, + String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { try { DebugExec.this.scope.put("PlotPlayer", player); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugFixFlags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugFixFlags.java deleted file mode 100644 index ca848a6bb..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugFixFlags.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.commands; - -import com.github.intellectualsites.plotsquared.commands.Argument; -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.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -@CommandDeclaration(command = "debugfixflags", usage = "/plot debugfixflags ", - permission = "plots.debugfixflags", description = "Attempt to fix all flags for a world", - requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG) -public class DebugFixFlags extends SubCommand { - - public DebugFixFlags() { - super(Argument.String); - } - - @Override public boolean onCommand(PlotPlayer player, String[] args) { - PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]); - if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[0]); - return false; - } - MainUtil.sendMessage(player, "&8--- &6Starting task &8 ---"); - for (Plot plot : area.getPlots()) { - HashMap, Object> flags = plot.getFlags(); - Iterator, Object>> i = flags.entrySet().iterator(); - boolean changed = false; - while (i.hasNext()) { - if (i.next().getKey() == null) { - changed = true; - i.remove(); - } - } - if (changed) { - DBFunc.setFlags(plot, plot.getFlags()); - } - } - MainUtil.sendMessage(player, "&aDone!"); - return true; - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java index 978c95e34..7d1f1ca6f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java @@ -18,9 +18,12 @@ import java.io.File; import java.util.UUID; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "debugimportworlds", permission = "plots.admin", - description = "Import worlds by player name", requiredType = RequiredType.CONSOLE, - category = CommandCategory.TELEPORT) public class DebugImportWorlds extends Command { +@CommandDeclaration(command = "debugimportworlds", + permission = "plots.admin", + description = "Import worlds by player name", + requiredType = RequiredType.CONSOLE, + category = CommandCategory.TELEPORT) +public class DebugImportWorlds extends Command { public DebugImportWorlds() { super(MainCommand.getInstance(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugLoadTest.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugLoadTest.java index f12ce8d1e..d66315966 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugLoadTest.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugLoadTest.java @@ -5,10 +5,13 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -@CommandDeclaration(command = "debugloadtest", permission = "plots.debugloadtest", +@CommandDeclaration(command = "debugloadtest", + permission = "plots.debugloadtest", description = "This debug command will force the reload of all plots in the DB", - usage = "/plot debugloadtest", category = CommandCategory.DEBUG, - requiredType = RequiredType.CONSOLE) public class DebugLoadTest extends SubCommand { + usage = "/plot debugloadtest", + category = CommandCategory.DEBUG, + requiredType = RequiredType.CONSOLE) +public class DebugLoadTest extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { PlotSquared.get().plots_tmp = DBFunc.getPlots(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java index 56232ef0b..64934cecb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java @@ -28,9 +28,14 @@ import java.util.stream.Collectors; import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.getDownloadID; import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.getUserID; -@CommandDeclaration(command = "debugpaste", aliases = "dp", usage = "/plot debugpaste", +@CommandDeclaration(command = "debugpaste", + aliases = "dp", + usage = "/plot debugpaste", description = "Upload settings.yml, worlds.yml, PlotSquared.use_THIS.yml your latest.log and Multiverse's worlds.yml (if being used) to https://athion.net/ISPaster/paste", - permission = "plots.debugpaste", category = CommandCategory.DEBUG, confirmation = true, requiredType = RequiredType.NONE) + permission = "plots.debugpaste", + category = CommandCategory.DEBUG, + confirmation = true, + requiredType = RequiredType.NONE) public class DebugPaste extends SubCommand { private static String readFile(@NonNull final File file) throws IOException { @@ -54,14 +59,16 @@ public class DebugPaste extends SubCommand { "# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your " + "problem\n\n"); b.append("# PlotSquared Information\n"); - b.append("This PlotSquared version is licensed to the spigot user ").append(getUserID()).append(" under ").append(getDownloadID()).append("\n"); + b.append("This PlotSquared version is licensed to the spigot user ") + .append(getUserID()).append(" under ").append(getDownloadID()).append("\n"); b.append("# Server Information\n"); b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation()) .append("\n"); b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';') .append(!Settings.UUID.OFFLINE).append('\n'); b.append("Plugins:"); - for (Map.Entry, Boolean> pluginInfo : PlotSquared.get().IMP.getPluginIds()) { + for (Map.Entry, Boolean> pluginInfo : PlotSquared + .get().IMP.getPluginIds()) { Map.Entry nameVersion = pluginInfo.getKey(); String name = nameVersion.getKey(); String version = nameVersion.getValue(); @@ -72,12 +79,17 @@ public class DebugPaste extends SubCommand { b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n"); Runtime runtime = Runtime.getRuntime(); RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); - b.append("Uptime: ").append(TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS) + " minutes").append('\n'); + b.append("Uptime: ").append( + TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS) + " minutes") + .append('\n'); b.append("JVM Flags: ").append(rb.getInputArguments()).append('\n'); - b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB").append('\n'); - b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB").append('\n'); + b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB") + .append('\n'); + b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB") + .append('\n'); b.append("Java Name: ").append(rb.getVmName()).append('\n'); - b.append("Java Version: '").append(System.getProperty("java.version")).append("'\n"); + b.append("Java Version: '").append(System.getProperty("java.version")) + .append("'\n"); b.append("Java Vendor: '").append(System.getProperty("java.vendor")).append("'\n"); b.append("Operating System: '").append(System.getProperty("os.name")).append("'\n"); b.append("OS Version: ").append(System.getProperty("os.version")).append('\n'); @@ -124,12 +136,13 @@ public class DebugPaste extends SubCommand { } try { - final File MultiverseWorlds = - new File(PlotSquared.get().IMP.getDirectory(), "../Multiverse-Core/worlds.yml"); - incendoPaster - .addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml", readFile(MultiverseWorlds))); + final File MultiverseWorlds = new File(PlotSquared.get().IMP.getDirectory(), + "../Multiverse-Core/worlds.yml"); + incendoPaster.addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml", + readFile(MultiverseWorlds))); } catch (final IOException ignored) { - MainUtil.sendMessage(player, "&cSkipping Multiverse worlds.yml because the plugin is not in use"); + MainUtil.sendMessage(player, + "&cSkipping Multiverse worlds.yml because the plugin is not in use"); } try { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java index a268f8903..0c902f7b2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java @@ -13,10 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.util.Arrays; -@CommandDeclaration(command = "debugroadregen", usage = DebugRoadRegen.USAGE, +@CommandDeclaration(command = "debugroadregen", + usage = DebugRoadRegen.USAGE, requiredType = RequiredType.NONE, description = "Regenerate roads in the plot or region the user is, based on the road schematic", - category = CommandCategory.DEBUG, permission = "plots.debugroadregen") + category = CommandCategory.DEBUG, + permission = "plots.debugroadregen") public class DebugRoadRegen extends SubCommand { public static final String USAGE = "/plot debugroadregen "; @@ -67,13 +69,11 @@ public class DebugRoadRegen extends SubCommand { height = Integer.parseInt(args[0]); } catch (NumberFormatException ignored) { MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0, 256)"); - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - DebugRoadRegen.USAGE); + MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE); return false; } } else if (args.length != 0) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - DebugRoadRegen.USAGE); + MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugSaveTest.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugSaveTest.java index 0c544d096..06b939abd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugSaveTest.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugSaveTest.java @@ -9,8 +9,10 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.util.ArrayList; -@CommandDeclaration(command = "debugsavetest", permission = "plots.debugsavetest", - category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, +@CommandDeclaration(command = "debugsavetest", + permission = "plots.debugsavetest", + category = CommandCategory.DEBUG, + requiredType = RequiredType.CONSOLE, usage = "/plot debugsavetest", description = "This command will force the recreation of all plots in the DB") public class DebugSaveTest extends SubCommand { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java index 72c6da126..4ec8dcc48 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java @@ -15,10 +15,15 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -@CommandDeclaration(command = "delete", permission = "plots.delete", - description = "Delete the plot you stand on", usage = "/plot delete", - aliases = {"dispose", "del", "unclaim"}, category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE, confirmation = true) public class Delete extends SubCommand { +@CommandDeclaration(command = "delete", + permission = "plots.delete", + description = "Delete the plot you stand on", + usage = "/plot delete", + aliases = {"dispose", "del", "unclaim"}, + category = CommandCategory.CLAIMING, + requiredType = RequiredType.NONE, + confirmation = true) +public class Delete extends SubCommand { // Note: To delete a specific plot use /plot delete // The syntax also works with any command: /plot diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java index b50e68762..e062197da 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java @@ -18,10 +18,13 @@ import com.sk89q.worldedit.world.gamemode.GameModes; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "deny", aliases = {"d", "ban"}, - description = "Deny a user from entering a plot", usage = "/plot deny ", - category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class Deny - extends SubCommand { +@CommandDeclaration(command = "deny", + aliases = {"d", "ban"}, + description = "Deny a user from entering a plot", + usage = "/plot deny ", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.PLAYER) +public class Deny extends SubCommand { public Deny() { super(Argument.PlayerName); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Desc.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Desc.java index d3b261ba8..76883593e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Desc.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Desc.java @@ -2,24 +2,30 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -@CommandDeclaration(command = "setdescription", permission = "plots.set.desc", - description = "Set the plot description", usage = "/plot desc ", - aliases = {"desc", "setdesc", "setd", "description"}, category = CommandCategory.SETTINGS, - requiredType = RequiredType.PLAYER) public class Desc extends SetCommand { +@CommandDeclaration(command = "setdescription", + permission = "plots.set.desc", + description = "Set the plot description", + usage = "/plot desc ", + aliases = {"desc", "setdesc", "setd", "description"}, + category = CommandCategory.SETTINGS, + requiredType = RequiredType.PLAYER) +public class Desc extends SetCommand { @Override public boolean set(PlotPlayer player, Plot plot, String desc) { if (desc.isEmpty()) { - plot.removeFlag(Flags.DESCRIPTION); + plot.removeFlag(DescriptionFlag.class); MainUtil.sendMessage(player, Captions.DESC_UNSET); return true; } - boolean result = FlagManager.addPlotFlag(plot, Flags.DESCRIPTION, desc); + boolean result = plot.setFlag( + GlobalFlagContainer.getInstance().getFlag(DescriptionFlag.class) + .createFlagInstance(desc)); if (!result) { MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); return false; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Dislike.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Dislike.java index 372231481..2ff639336 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Dislike.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Dislike.java @@ -3,10 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -@CommandDeclaration(command = "dislike", permission = "plots.dislike", - description = "Dislike the plot", usage = "/plot dislike [next|purge]", - category = CommandCategory.INFO, requiredType = RequiredType.PLAYER) public class Dislike - extends SubCommand { +@CommandDeclaration(command = "dislike", + permission = "plots.dislike", + description = "Dislike the plot", + usage = "/plot dislike [next|purge]", + category = CommandCategory.INFO, + requiredType = RequiredType.PLAYER) +public class Dislike extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { return Like.handleLike(player, args, false); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Done.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Done.java index 055cfabd9..444d6b748 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Done.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Done.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; 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.DoneFlag; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -14,9 +14,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; -@CommandDeclaration(command = "done", aliases = {"submit"}, description = "Mark a plot as done", - permission = "plots.done", category = CommandCategory.SETTINGS, - requiredType = RequiredType.NONE) public class Done extends SubCommand { +@CommandDeclaration(command = "done", + aliases = {"submit"}, + description = "Mark a plot as done", + permission = "plots.done", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE) +public class Done extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); @@ -29,7 +33,7 @@ import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); return false; } - if (plot.hasFlag(Flags.DONE)) { + if (DoneFlag.isDone(plot)) { MainUtil.sendMessage(player, Captions.DONE_ALREADY_DONE); return false; } @@ -59,7 +63,7 @@ import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; private void finish(Plot plot, PlotPlayer pp, boolean success) { if (success) { long flagValue = System.currentTimeMillis() / 1000; - plot.setFlag(Flags.DONE, flagValue); + plot.setFlag(DoneFlag.class, Long.toString(flagValue)); MainUtil.sendMessage(pp, Captions.DONE_SUCCESS); } else { MainUtil.sendMessage(pp, Captions.DONE_INSUFFICIENT_COMPLEXITY); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Download.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Download.java index 776cff0f8..2ab9bfa43 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Download.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Download.java @@ -4,7 +4,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.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; @@ -17,10 +17,14 @@ import com.sk89q.jnbt.CompoundTag; import java.net.URL; -@CommandDeclaration(usage = "/plot download [schematic|world]", command = "download", - aliases = {"dl"}, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, - description = "Download your plot", permission = "plots.download") public class Download - extends SubCommand { +@CommandDeclaration(usage = "/plot download [schematic|world]", + command = "download", + aliases = {"dl"}, + category = CommandCategory.SCHEMATIC, + requiredType = RequiredType.NONE, + description = "Download your plot", + permission = "plots.download") +public class Download extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); @@ -35,8 +39,8 @@ import java.net.URL; MainUtil.sendMessage(player, Captions.PLOT_UNOWNED); return false; } - if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!plot.getFlag(Flags.DONE).isPresent())) - && !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) { + if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!DoneFlag.isDone(plot))) && !Permissions + .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) { MainUtil.sendMessage(player, Captions.DONE_NOT_DONE); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java deleted file mode 100644 index 04d752155..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ /dev/null @@ -1,343 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.commands; - -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.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.BlockStateListFlag; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag; -import com.github.intellectualsites.plotsquared.plot.flag.ListFlag; -import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.Permissions; -import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; -import com.github.intellectualsites.plotsquared.plot.util.StringComparison; -import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.sk89q.worldedit.world.block.BlockType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -@CommandDeclaration(command = "setflag", aliases = {"f", "flag", - "setflag"}, usage = "/plot flag ", description = "Set plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag") -public class FlagCmd extends SubCommand { - - private boolean checkPermValue(PlotPlayer player, Flag flag, String key, String value) { - key = key.toLowerCase(); - value = value.toLowerCase(); - String perm = Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), - value.toLowerCase()); - if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { - try { - int numeric = Integer.parseInt(value); - perm = perm.substring(0, perm.length() - value.length() - 1); - if (numeric > 0) { - int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ? - numeric : - Settings.Limit.MAX_PLOTS; - final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric; - if (!result) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), - key.toLowerCase(), value.toLowerCase())); - } - return result; - } - - } catch (NumberFormatException ignore) { - } - } else if (flag instanceof BlockStateListFlag) { - final BlockStateListFlag blockListFlag = (BlockStateListFlag) flag; - Set parsedBlocks = blockListFlag.parseValue(value); - for (final BlockType block : parsedBlocks) { - final String permission = Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), - key.toLowerCase(), block.toString().toLowerCase()); - final boolean result = Permissions.hasPermission(player, permission); - if (!result) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), - key.toLowerCase(), value.toLowerCase())); - return false; - } - } - return true; - } - final boolean result = Permissions.hasPermission(player, perm); - if (!result) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), - value.toLowerCase())); - } - return result; - } - - @Override public boolean onCommand(PlotPlayer player, String[] args) { - - /* - * plot flag set fly true - * plot flag remove fly - * plot flag remove use 1,3 - * plot flag add use 2,4 - * plot flag list - */ - if (args.length == 0) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, getUsage()); - return false; - } - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); - if (plot == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_PLOT); - return false; - } - if (!plot.hasOwner()) { - sendMessage(player, Captions.PLOT_NOT_CLAIMED); - return false; - } - if (!plot.isOwner(player.getUUID()) && !Permissions - .hasPermission(player, Captions.PERMISSION_SET_FLAG_OTHER)) { - MainUtil - .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG_OTHER); - return false; - } - Flag flag = null; - if (args.length > 1) { - flag = FlagManager.getFlag(args[1]); - if (flag == null || flag.isReserved()) { - boolean suggested = false; - try { - StringComparison> stringComparison = - new StringComparison<>(args[1], Flags.getFlags()); - String best = stringComparison.getBestMatch(); - if (best != null) { - MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG_SUGGESTED, best); - suggested = true; - } - } catch (final Exception ignored) { /* Happens sometimes because of mean code */ } - if (!suggested) { - MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG); - } - return false; - } - } - switch (args[0].toLowerCase()) { - case "info": { - if (!Permissions.hasPermission(player, Captions.PERMISSION_SET_FLAG)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, "plots.flag.info"); - return false; - } - if (args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag info "); - return false; - } - // flag key - MainUtil.sendMessage(player, Captions.FLAG_KEY, flag.getName()); - // flag type - MainUtil.sendMessage(player, Captions.FLAG_TYPE, flag.getClass().getSimpleName()); - // Flag type description - MainUtil.sendMessage(player, Captions.FLAG_DESC, flag.getValueDescription()); - return true; - } - case "set": { - if (!Permissions.hasPermission(player, Captions.PERMISSION_SET_FLAG)) { - MainUtil - .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG); - return false; - } - if (args.length < 3) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot flag set "); - return false; - } - String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - if (!checkPermValue(player, flag, args[1], value)) { - return false; - } - Object parsed = flag.parseValue(value); - if (parsed == null) { - MainUtil.sendMessage(player, "&c" + flag.getValueDescription()); - return false; - } - if (flag instanceof ListFlag) { - if (!(parsed instanceof Collection) || ((Collection) parsed).isEmpty()) { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - } - } - boolean result = plot.setFlag(flag, parsed); - if (!result) { - MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - return false; - } - MainUtil.sendMessage(player, Captions.FLAG_ADDED); - return true; - } - case "remove": { - if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_REMOVE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_FLAG_REMOVE); - return false; - } - if (args.length != 2 && args.length != 3) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot flag remove [values]"); - return false; - } - if (!Permissions.hasPermission(player, Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), - args[1].toLowerCase()))) { - if (args.length != 3) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), - args[1].toLowerCase())); - return false; - } - for (String entry : args[2].split(",")) { - if (!checkPermValue(player, flag, args[1], entry)) { - return false; - } - } - } - if (args.length == 3 && flag instanceof ListFlag) { - String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - final ListFlag listFlag = (ListFlag) flag; - final Optional collectionOptional = plot.getFlag(listFlag); - if (collectionOptional.isPresent()) { - final Collection parsedCollection = (Collection) flag.parseValue(value); - if (parsedCollection.isEmpty()) { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - } - final Collection flagCollection = collectionOptional.get(); - if (flagCollection.removeAll(parsedCollection)) { - if (flagCollection.isEmpty()) { - if (plot.removeFlag(flag)) { - return MainUtil.sendMessage(player, Captions.FLAG_REMOVED); - } else { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - } - } else { - MainUtil.sendMessage(player, Captions.FLAG_REMOVED); - } - } else { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - } - } - DBFunc.setFlags(plot, plot.getFlags()); - return true; - } else { - boolean result = plot.removeFlag(flag); - if (!result) { - MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - return false; - } - } - if (flag == Flags.TIME) { - player.setTime(Long.MAX_VALUE); - } else if (flag == Flags.WEATHER) { - player.setWeather(PlotWeather.RESET); - } - MainUtil.sendMessage(player, Captions.FLAG_REMOVED); - return true; - } - case "add": - if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_ADD)) { - MainUtil - .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_FLAG_ADD); - return false; - } - if (args.length < 3) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot flag add "); - return false; - } - for (String entry : args[2].split(",")) { - if (!checkPermValue(player, flag, args[1], entry)) { - return false; - } - } - String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - Object parsed = flag.parseValue(value); - if (parsed == null) { - MainUtil.sendMessage(player, "&c" + flag.getValueDescription()); - return false; - } - Object val = parsed; - if (flag instanceof ListFlag) { - final Collection parsedCollection = (Collection) parsed; - if (parsedCollection.isEmpty()) { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - } - final ListFlag listFlag = (ListFlag) flag; - final Optional collectionOptional = plot.getFlag(listFlag); - if (collectionOptional.isPresent()) { - final Collection flagCollection = collectionOptional.get(); - if (flagCollection.addAll(parsedCollection)) { - MainUtil.sendMessage(player, Captions.FLAG_ADDED); - val = flagCollection; - } else { - return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - } - } - } - boolean result = plot.setFlag(flag, val); - if (!result) { - MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - return false; - } - MainUtil.sendMessage(player, Captions.FLAG_ADDED); - return true; - case "list": - if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_LIST)) { - MainUtil - .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_FLAG_LIST); - return false; - } - if (args.length > 1) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag list"); - return false; - } - final Map> flags = new HashMap<>(); - for (Flag flag1 : Flags.getFlags()) { - final String category = flag1.getCategoryCaption(); - final Collection flagList = - flags.computeIfAbsent(category, k -> new ArrayList<>()); - flagList.add(flag1.getName()); - } - - final StringBuilder message = new StringBuilder(); - final Iterator>> iterator = - flags.entrySet().iterator(); - while (iterator.hasNext()) { - final Map.Entry> flagsEntry = iterator.next(); - final List flagNames = flagsEntry.getValue(); - Collections.sort(flagNames); - message.append(String.format(Captions.FLAG_LIST_ENTRY.formatted(), - flagsEntry.getKey(), StringMan.join(flagNames, ", "))); - if (iterator.hasNext()) { - message.append("\n"); - } - } - MainUtil.sendMessage(player, message.toString()); - return true; - } - MainUtil - .sendMessage(player, Captions.COMMAND_SYNTAX, getUsage()); - return false; - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java new file mode 100644 index 000000000..b9a0abf5d --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java @@ -0,0 +1,519 @@ +package com.github.intellectualsites.plotsquared.plot.commands; + +import com.github.intellectualsites.plotsquared.commands.Command; +import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; +import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.config.Settings; +import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException; +import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; +import com.github.intellectualsites.plotsquared.plot.flags.types.IntegerFlag; +import com.github.intellectualsites.plotsquared.plot.flags.types.ListFlag; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.StringComparison; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.helpmenu.HelpMenu; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@CommandDeclaration(command = "flag", + aliases = {"f", "flag"}, + usage = "/plot flag ", + description = "Manage plot flags", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.flag") +@SuppressWarnings("unused") +public final class FlagCommand extends Command { + + public FlagCommand() { + super(MainCommand.getInstance(), true); + } + + private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { + message.send(player, args); + return true; + } + + private static boolean checkPermValue(@Nonnull final PlotPlayer player, + @NotNull final PlotFlag flag, @NotNull String key, @NotNull String value) { + key = key.toLowerCase(); + value = value.toLowerCase(); + String perm = CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + key.toLowerCase(), value.toLowerCase()); + if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { + try { + int numeric = Integer.parseInt(value); + perm = perm.substring(0, perm.length() - value.length() - 1); + if (numeric > 0) { + int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ? + numeric : + Settings.Limit.MAX_PLOTS; + final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric; + if (!result) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + key.toLowerCase(), value.toLowerCase())); + } + return result; + } + } catch (NumberFormatException ignore) { + } + } else if (flag instanceof ListFlag) { + final ListFlag listFlag = (ListFlag) flag; + try { + PlotFlag, ?> parsedFlag = listFlag.parse(value); + for (final Object entry : parsedFlag.getValue()) { + final String permission = CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + key.toLowerCase(), entry.toString().toLowerCase()); + final boolean result = Permissions.hasPermission(player, permission); + if (!result) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + key.toLowerCase(), value.toLowerCase())); + return false; + } + } + } catch (final FlagParseException e) { + MainUtil.sendMessage(player, + Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName()) + .replace("%flag_value%", e.getValue()) + .replace("%error%", e.getErrorMessage())); + return false; + } catch (final Exception e) { + return false; + } + return true; + } + final boolean result = Permissions.hasPermission(player, perm); + if (!result) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + key.toLowerCase(), value.toLowerCase())); + } + return result; + } + + /** + * Checks if the player is allowed to modify the flags at their current location + * + * @return true if the player is allowed to modify the flags at their current location + */ + private static boolean checkRequirements(@NotNull final PlotPlayer player) { + final Location location = player.getLocation(); + final Plot plot = location.getPlotAbs(); + if (plot == null) { + MainUtil.sendMessage(player, Captions.NOT_IN_PLOT); + return false; + } + if (!plot.hasOwner()) { + sendMessage(player, Captions.PLOT_NOT_CLAIMED); + return false; + } + if (!plot.isOwner(player.getUUID()) && !Permissions + .hasPermission(player, Captions.PERMISSION_SET_FLAG_OTHER)) { + MainUtil + .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG_OTHER); + return false; + } + return true; + } + + /** + * Attempt to extract the plot flag from the command arguments. If the flag cannot + * be found, a flag suggestion may be sent to the player. + * + * @param player Player executing the command + * @param arg String to extract flag from + * @return The flag, if found, else null + */ + @Nullable private static PlotFlag getFlag(@NotNull final PlotPlayer player, + @NotNull final String arg) { + if (arg != null && arg.length() > 0) { + final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(arg); + if (flag instanceof InternalFlag || flag == null) { + boolean suggested = false; + try { + final StringComparison> stringComparison = + new StringComparison<>(arg, + GlobalFlagContainer.getInstance().getFlagMap().values()); + final String best = stringComparison.getBestMatch(); + if (best != null) { + MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG_SUGGESTED, best); + suggested = true; + } + } catch (final Exception ignored) { /* Happens sometimes because of mean code */ } + if (!suggested) { + MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG); + } + return null; + } + return flag; + } + return null; + } + + @Override public CompletableFuture execute(PlotPlayer player, String[] args, + RunnableVal3 confirm, + RunnableVal2 whenDone) throws CommandException { + if (args.length == 0 || !Arrays + .asList("set", "s", "list", "l", "delete", "remove", "r", "add", "a", "info", "i") + .contains(args[0].toLowerCase(Locale.ENGLISH))) { + new HelpMenu(player).setCategory(CommandCategory.SETTINGS) + .setCommands(this.getCommands()).generateMaxPages() + .generatePage(0, getParent().toString()).render(); + return CompletableFuture.completedFuture(true); + } + return super.execute(player, args, confirm, whenDone); + } + + @Override public Collection tab(final PlotPlayer player, final String[] args, + final boolean space) { + if (args.length == 1) { + return Stream + .of("s", "set", "add", "a", "remove", "r", "delete", "info", "i", "list", "l") + .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) + .map(value -> new Command(null, false, value, "", RequiredType.NONE, null) { + }).collect(Collectors.toList()); + } else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete", "info", "i") + .contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 2) { + return GlobalFlagContainer.getInstance().getRecognizedPlotFlags().stream() + .filter(flag -> !(flag instanceof InternalFlag)) + .filter(flag -> flag.getName().startsWith(args[1].toLowerCase(Locale.ENGLISH))) + .map(flag -> new Command(null, false, flag.getName(), "", RequiredType.NONE, null) { + }).collect(Collectors.toList()); + } else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete") + .contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 3) { + try { + final PlotFlag flag = + GlobalFlagContainer.getInstance().getFlagFromString(args[1]); + if (flag != null) { + Stream stream = flag.getTabCompletions().stream(); + if (flag instanceof ListFlag && args[2].contains(",")) { + final String[] split = args[2].split(","); + // Prefix earlier values onto all suggestions + StringBuilder prefix = new StringBuilder(); + for (int i = 0; i < split.length - 1; i++) { + prefix.append(split[i]).append(","); + } + final String cmp; + if (!args[2].endsWith(",")) { + cmp = split[split.length - 1]; + } else { + prefix.append(split[split.length - 1]).append(","); + cmp = ""; + } + return stream + .filter(value -> value.startsWith(cmp.toLowerCase(Locale.ENGLISH))).map( + value -> new Command(null, false, prefix + value, "", + RequiredType.NONE, null) { + }).collect(Collectors.toList()); + } else { + return stream + .filter(value -> value.startsWith(args[2].toLowerCase(Locale.ENGLISH))) + .map(value -> new Command(null, false, value, "", RequiredType.NONE, + null) { + }).collect(Collectors.toList()); + } + } + } catch (final Exception e) { + } + } + return tabOf(player, args, space); + } + + @CommandDeclaration(command = "set", + aliases = {"s", "set"}, + usage = "/plot flag set ", + description = "Set a plot flag", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.set.flag") + public void set(final Command command, final PlotPlayer player, final String[] args, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + if (!checkRequirements(player)) { + return; + } + if (args.length < 2) { + MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag set "); + return; + } + final PlotFlag plotFlag = getFlag(player, args[0]); + if (plotFlag == null) { + return; + } + final String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " "); + if (!checkPermValue(player, plotFlag, args[0], value)) { + return; + } + final PlotFlag parsed; + try { + parsed = plotFlag.parse(value); + } catch (final FlagParseException e) { + MainUtil.sendMessage(player, + Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", plotFlag.getName()) + .replace("%flag_value%", e.getValue()).replace("%error%", e.getErrorMessage())); + return; + } + player.getLocation().getPlotAbs().setFlag(parsed); + MainUtil.sendMessage(player, Captions.FLAG_ADDED); + } + + @CommandDeclaration(command = "add", + aliases = {"a", "add"}, + usage = "/plot flag add ", + description = "Add a plot flag value", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.flag.add") + public void add(final Command command, PlotPlayer player, final String[] args, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + if (!checkRequirements(player)) { + return; + } + if (args.length < 2) { + MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag add "); + return; + } + final PlotFlag flag = getFlag(player, args[0]); + if (flag == null) { + return; + } + final PlotFlag localFlag = + player.getLocation().getPlotAbs().getFlagContainer().getFlag(flag.getClass()); + for (String entry : args[1].split(",")) { + if (!checkPermValue(player, flag, args[0], entry)) { + return; + } + } + final String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " "); + final PlotFlag parsed; + try { + parsed = flag.parse(value); + } catch (FlagParseException e) { + MainUtil.sendMessage(player, + Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName()) + .replace("%flag_value%", e.getValue()).replace("%error%", e.getErrorMessage())); + return; + } + boolean result = + player.getLocation().getPlotAbs().setFlag(localFlag.merge(parsed.getValue())); + if (!result) { + MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); + return; + } + MainUtil.sendMessage(player, Captions.FLAG_ADDED); + } + + @CommandDeclaration(command = "remove", + aliases = {"r", "remove", "delete"}, + usage = "/plot flag remove [values]", + description = "Remove a flag", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.flag.add") + public void remove(final Command command, PlotPlayer player, final String[] args, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + if (!checkRequirements(player)) { + return; + } + if (args.length != 1 && args.length != 2) { + MainUtil + .sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag remove [values]"); + return; + } + final PlotFlag flag = getFlag(player, args[0]); + if (flag == null) { + return; + } + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), + args[0].toLowerCase()))) { + if (args.length != 2) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), + args[0].toLowerCase())); + return; + } + } + final Plot plot = player.getLocation().getPlotAbs(); + if (args.length == 2 && flag instanceof ListFlag) { + String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " "); + final ListFlag listFlag = (ListFlag) flag; + final List list = + new ArrayList(plot.getFlag((Class>) listFlag.getClass())); + final PlotFlag parsedFlag; + try { + parsedFlag = listFlag.parse(value); + } catch (final FlagParseException e) { + MainUtil.sendMessage(player, + Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName()) + .replace("%flag_value%", e.getValue()) + .replace("%error%", e.getErrorMessage())); + return; + } + if (((List) parsedFlag.getValue()).isEmpty()) { + MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return; + } + if (list.removeAll((List) parsedFlag.getValue())) { + if (list.isEmpty()) { + if (plot.removeFlag(flag)) { + MainUtil.sendMessage(player, Captions.FLAG_REMOVED); + return; + } else { + MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return; + } + } else { + // MainUtil.sendMessage(player, Captions.FLAG_REMOVED); + if (plot.setFlag(parsedFlag.createFlagInstance(list))) { + MainUtil.sendMessage(player, Captions.FLAG_PARTIALLY_REMOVED); + return; + } else { + MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return; + } + } + } else { + MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return; + } + } else { + boolean result = plot.removeFlag(flag); + if (!result) { + MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return; + } + } + MainUtil.sendMessage(player, Captions.FLAG_REMOVED); + } + + @CommandDeclaration(command = "list", + aliases = {"l", "list", "flags"}, + usage = "/plot flag list", + description = "List all available plot flags", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.flag.list") + public void list(final Command command, final PlotPlayer player, final String[] args, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + if (!checkRequirements(player)) { + return; + } + + final Map> flags = new HashMap<>(); + for (PlotFlag plotFlag : GlobalFlagContainer.getInstance().getRecognizedPlotFlags()) { + if (plotFlag instanceof InternalFlag) { + continue; + } + final String category = plotFlag.getFlagCategory().getTranslated(); + final Collection flagList = + flags.computeIfAbsent(category, k -> new ArrayList<>()); + flagList.add(plotFlag.getName()); + } + + for (final Map.Entry> entry : flags.entrySet()) { + Collections.sort(entry.getValue()); + PlotMessage plotMessage = new PlotMessage(entry.getKey() + ": ") + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()); + final Iterator flagIterator = entry.getValue().iterator(); + while (flagIterator.hasNext()) { + final String flag = flagIterator.next(); + plotMessage = plotMessage.text(flag).command("/plot flag info " + flag) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).tooltip( + new PlotMessage(Captions.FLAG_LIST_SEE_INFO.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated())); + if (flagIterator.hasNext()) { + plotMessage = plotMessage.text(", ") + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()); + } + } + plotMessage.send(player); + } + } + + @CommandDeclaration(command = "info", + aliases = {"i", "info"}, + usage = "/plot flag info ", + description = "View information about a flag", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.flag.info") + public void info(final Command command, final PlotPlayer player, final String[] args, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + if (!checkRequirements(player)) { + return; + } + if (args.length < 1) { + MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag info "); + return; + } + final PlotFlag plotFlag = getFlag(player, args[0]); + if (plotFlag != null) { + Captions.FLAG_INFO_HEADER.send(player); + // Flag name + new PlotMessage(Captions.FLAG_INFO_NAME.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(plotFlag.getName()) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); + // Flag category + new PlotMessage(Captions.FLAG_INFO_CATEGORY.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()) + .text(plotFlag.getFlagCategory().getTranslated()) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); + // Flag description + new PlotMessage(Captions.FLAG_INFO_DESCRIPTION.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).send(player); + new PlotMessage(plotFlag.getFlagDescription().getTranslated()) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); + // Flag example + new PlotMessage(Captions.FLAG_INFO_EXAMPLE.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()) + .text("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample()) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()) + .suggest("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample()) + .send(player); + // Default value + final String defaultValue = player.getLocation().getPlotArea().getFlagContainer() + .getFlagErased(plotFlag.getClass()).toString(); + new PlotMessage(Captions.FLAG_INFO_DEFAULT_VALUE.getTranslated()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(defaultValue) + .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); + // Footer. Done this way to prevent the duplicate-message-thingy from catching it + MainUtil.sendMessage(player, "&r" + Captions.FLAG_INFO_FOOTER.getTranslated()); + } + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java index fc8fb6b50..6225e7902 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java @@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -16,9 +17,12 @@ import com.google.common.primitives.Ints; import java.util.UUID; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "grant", category = CommandCategory.CLAIMING, - usage = "/plot grant [player]", permission = "plots.grant", - requiredType = RequiredType.NONE) public class Grant extends Command { +@CommandDeclaration(command = "grant", + category = CommandCategory.CLAIMING, + usage = "/plot grant [player]", + permission = "plots.grant", + requiredType = RequiredType.NONE) +public class Grant extends Command { public Grant() { super(MainCommand.getInstance(), true); @@ -32,10 +36,10 @@ import java.util.concurrent.CompletableFuture; switch (arg0) { case "add": case "check": - if (!Permissions.hasPermission(player, - Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0))) { - Captions.NO_PERMISSION.send(player, - Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0)); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0))) { + Captions.NO_PERMISSION.send(player, CaptionUtility + .format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0)); return CompletableFuture.completedFuture(false); } if (args.length > 2) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java index d2f0e5a71..04031a01a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java @@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.helpmenu.HelpMenu; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "help", description = "Get this help menu", aliases = "?", - category = CommandCategory.INFO, usage = "help [category|#]", permission = "plots.use") +@CommandDeclaration(command = "help", + description = "Get this help menu", + aliases = "?", + category = CommandCategory.INFO, + usage = "help [category|#]", + permission = "plots.use") public class Help extends Command { public Help(Command parent) { super(parent, true); @@ -55,7 +59,8 @@ public class Help extends Command { return CompletableFuture.completedFuture(true); } - public CompletableFuture displayHelp(final PlotPlayer player, final String catRaw, final int page) { + public CompletableFuture displayHelp(final PlotPlayer player, final String catRaw, + final int page) { return CompletableFuture.supplyAsync(() -> { String cat = catRaw; @@ -80,12 +85,11 @@ public class Help extends Command { for (CommandCategory c : CommandCategory.values()) { builder.append("\n").append(StringMan .replaceAll(Captions.HELP_INFO_ITEM.getTranslated(), "%category%", - c.toString().toLowerCase(), - "%category_desc%", c.toString())); + c.toString().toLowerCase(), "%category_desc%", c.toString())); } - builder.append("\n") - .append(Captions.HELP_INFO_ITEM.getTranslated().replaceAll("%category%", "all") - .replaceAll("%category_desc%", "Display all commands")); + builder.append("\n").append( + Captions.HELP_INFO_ITEM.getTranslated().replaceAll("%category%", "all") + .replaceAll("%category_desc%", "Display all commands")); builder.append("\n").append(Captions.HELP_FOOTER.getTranslated()); MainUtil.sendMessage(player, builder.toString(), false); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java index 030ef0f44..ca13056e3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java @@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.List; -@CommandDeclaration(command = "inbox", description = "Review the comments for a plot", - usage = "/plot inbox [inbox] [delete |clear|page]", permission = "plots.inbox", category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER) +@CommandDeclaration(command = "inbox", + description = "Review the comments for a plot", + usage = "/plot inbox [inbox] [delete |clear|page]", + permission = "plots.inbox", + category = CommandCategory.CHAT, + requiredType = RequiredType.PLAYER) public class Inbox extends SubCommand { public void displayComments(PlotPlayer player, List oldComments, int page) { @@ -40,8 +44,7 @@ public class Inbox extends SubCommand { StringBuilder string = new StringBuilder(); string.append(StringMan .replaceAll(Captions.COMMENT_LIST_HEADER_PAGED.getTranslated(), "%amount%", - comments.length, "%cur", - page + 1, "%max", totalPages + 1, "%word", "all") + '\n'); + comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + '\n'); // This might work xD for (int x = page * 12; x < max; x++) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java index 3db27bdd6..1156fd1cf 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java @@ -4,19 +4,17 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HideInfoFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; -import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import java.util.UUID; - -@CommandDeclaration(command = "info", aliases = "i", description = "Display plot info", - usage = "/plot info [-f, to force info]", category = CommandCategory.INFO) +@CommandDeclaration(command = "info", + aliases = "i", + description = "Display plot info", + usage = "/plot info [-f, to force info]", + category = CommandCategory.INFO) public class Info extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -70,7 +68,7 @@ public class Info extends SubCommand { } // hide-info flag - if (plot.getFlag(Flags.HIDE_INFO).orElse(false)) { + if (plot.getFlag(HideInfoFlag.class)) { boolean allowed = false; for (final String argument : args) { if (argument.equalsIgnoreCase("-f")) { @@ -89,37 +87,6 @@ public class Info extends SubCommand { } } - if (args.length == 1 && args[0].equalsIgnoreCase("inv")) { - PlotInventory inv = new PlotInventory(player) { - @Override public boolean onClick(int index) { - // TODO InfoInventory not implemented yet!!!!!!!! - // See plot rating or musicsubcommand on examples - return false; - } - }; - UUID uuid = player.getUUID(); - String name = MainUtil.getName(plot.getOwner()); - inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", - "&cID: &6" + plot.getId().toString(), "&cOwner:&6" + name, - "&cAlias: &6" + plot.getAlias(), - "&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(), - "&cCan Build: &6" + plot.isAdded(uuid), - "&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)), - "&cIs Denied: &6" + plot.isDenied(uuid))); - inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", - "&cAmount: &6" + plot.getTrusted().size(), - "&8Click to view a list of the trusted users")); - inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", - "&cAmount: &6" + plot.getMembers().size(), - "&8Click to view a list of plot members")); - inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", "&cDenied", - "&cAmount: &6" + plot.getDenied().size(), - "&8Click to view a list of denied players")); - inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", "&cFlags", - "&cAmount: &6" + plot.getFlags().size(), "&8Click to view a list of plot flags")); - inv.openInventory(); - return true; - } boolean hasOwner = plot.hasOwner(); // Wildcard player {added} boolean containsEveryone = plot.getTrusted().contains(DBFunc.EVERYONE); @@ -130,7 +97,7 @@ public class Info extends SubCommand { plot.getId().x + ";" + plot.getId().y); return true; } - String info = Captions.PLOT_INFO.getTranslated(); + String info = Captions.PLOT_INFO_FORMAT.getTranslated(); boolean full; if (arg != null) { info = getCaption(arg); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java index b453abeb3..653dfe697 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java @@ -17,9 +17,14 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "kick", aliases = "k", description = "Kick a player from your plot", - permission = "plots.kick", usage = "/plot kick ", category = CommandCategory.TELEPORT, - requiredType = RequiredType.PLAYER) public class Kick extends SubCommand { +@CommandDeclaration(command = "kick", + aliases = "k", + description = "Kick a player from your plot", + permission = "plots.kick", + usage = "/plot kick ", + category = CommandCategory.TELEPORT, + requiredType = RequiredType.PLAYER) +public class Kick extends SubCommand { public Kick() { super(Argument.PlayerName); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java index 187977b2b..658cc383f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java @@ -15,8 +15,11 @@ import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "leave", description = "Removes self from being trusted or a member of the plot", - permission = "plots.leave", usage = "/plot leave", category = CommandCategory.CLAIMING, - requiredType = RequiredType.PLAYER) public class Leave extends Command { + permission = "plots.leave", + usage = "/plot leave", + category = CommandCategory.CLAIMING, + requiredType = RequiredType.PLAYER) +public class Leave extends Command { public Leave() { super(MainCommand.getInstance(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java index bf6162769..2d94a9e39 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java @@ -5,7 +5,7 @@ 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.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.Rating; @@ -21,9 +21,13 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -@CommandDeclaration(command = "like", permission = "plots.like", description = "Like the plot", - usage = "/plot like [next|purge]", category = CommandCategory.INFO, - requiredType = RequiredType.PLAYER) public class Like extends SubCommand { +@CommandDeclaration(command = "like", + permission = "plots.like", + description = "Like the plot", + usage = "/plot like [next|purge]", + category = CommandCategory.INFO, + requiredType = RequiredType.PLAYER) +public class Like extends SubCommand { protected static boolean handleLike(final PlotPlayer player, String[] args, final boolean like) { @@ -41,8 +45,8 @@ import java.util.UUID; return v2 > v1 ? 1 : -1; }); for (final Plot plot : plots) { - if ((!Settings.Done.REQUIRED_FOR_RATINGS || plot.hasFlag(Flags.DONE)) - && plot.isBasePlot() && (!plot.getLikes().containsKey(uuid))) { + if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(plot)) && plot + .isBasePlot() && (!plot.getLikes().containsKey(uuid))) { plot.teleportPlayer(player, TeleportCause.COMMAND); MainUtil.sendMessage(player, Captions.RATE_THIS); return true; @@ -78,7 +82,7 @@ import java.util.UUID; sendMessage(player, Captions.RATING_NOT_YOUR_OWN); return false; } - if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) { + if (Settings.Done.REQUIRED_FOR_RATINGS && !DoneFlag.isDone(plot)) { sendMessage(player, Captions.RATING_NOT_DONE); return false; } @@ -105,15 +109,15 @@ import java.util.UUID; } } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index fefcea46e..8ea0f369c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -3,8 +3,10 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared.SortType; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; @@ -24,11 +26,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; -import java.util.Optional; import java.util.UUID; -@CommandDeclaration(command = "list", aliases = {"l", "find", "search"}, description = "List plots", - permission = "plots.list", category = CommandCategory.INFO, +@CommandDeclaration(command = "list", + aliases = {"l", "find", "search"}, + description = "List plots", + permission = "plots.list", + category = CommandCategory.INFO, usage = "/plot list > [#]") public class ListCmd extends SubCommand { @@ -136,11 +140,11 @@ public class ListCmd extends SubCommand { Captions.PERMISSION_LIST_WORLD); return false; } - if (!Permissions - .hasPermission(player, - Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), + world)); return false; } plots = new ArrayList<>(PlotSquared.get().getPlots(world)); @@ -161,11 +165,11 @@ public class ListCmd extends SubCommand { .sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_AREA); return false; } - if (!Permissions - .hasPermission(player, - Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), + world)); return false; } plots = area == null ? new ArrayList() : new ArrayList<>(area.getPlots()); @@ -186,14 +190,13 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PlotSquared.get().getPlots()) { - Optional flag = plot.getFlag(Flags.DONE); - if (flag.isPresent()) { + if (DoneFlag.isDone(plot)) { plots.add(plot); } } plots.sort((a, b) -> { - String va = "" + a.getFlags().get(Flags.DONE); - String vb = "" + b.getFlags().get(Flags.DONE); + String va = a.getFlag(DoneFlag.class); + String vb = b.getFlag(DoneFlag.class); if (MathMan.isInteger(va)) { if (MathMan.isInteger(vb)) { return Integer.parseInt(vb) - Integer.parseInt(va); @@ -248,8 +251,7 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PlotSquared.get().getPlots()) { - Optional price = plot.getFlag(Flags.PRICE); - if (price.isPresent()) { + if (plot.getFlag(PriceFlag.class) > 0) { plots.add(plot); } } @@ -309,11 +311,12 @@ public class ListCmd extends SubCommand { Captions.PERMISSION_LIST_WORLD); return false; } - if (!Permissions - .hasPermission(player, Captions - .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0]))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0])); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), + args[0]))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), + args[0])); return false; } plots = new ArrayList<>(PlotSquared.get().getPlots(args[0])); @@ -383,18 +386,10 @@ public class ListCmd extends SubCommand { Captions.PLOT_INFO_MEMBERS.getTranslated() .replaceAll("%members%", MainUtil.getPlayerList(plot.getMembers())))) .color("$1"); - String strFlags = StringMan.join(plot.getFlags().values(), ","); - if (strFlags.isEmpty()) { - strFlags = Captions.NONE.getTranslated(); - } - PlotMessage flags = new PlotMessage().text(Captions.color( - Captions.PLOT_INFO_FLAGS.getTranslated().replaceAll("%flags%", strFlags))) - .color("$1"); message.text("[").color("$3").text(i + "") .command("/plot visit " + plot.getArea() + ";" + plot.getId()) .tooltip("/plot visit " + plot.getArea() + ";" + plot.getId()).color("$1") - .text("]").color("$3").text(" " + plot.toString()) - .tooltip(trusted, members, flags) + .text("]").color("$3").text(" " + plot.toString()).tooltip(trusted, members) .command("/plot info " + plot.getArea() + ";" + plot.getId()).color(color) .text(" - ").color("$2"); String prefix = ""; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java index 4b0305969..3a6bca7e0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java @@ -19,9 +19,14 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.List; -@CommandDeclaration(command = "load", aliases = "restore", category = CommandCategory.SCHEMATIC, - requiredType = RequiredType.NONE, description = "Load your plot", permission = "plots.load", - usage = "/plot load") public class Load extends SubCommand { +@CommandDeclaration(command = "load", + aliases = "restore", + category = CommandCategory.SCHEMATIC, + requiredType = RequiredType.NONE, + description = "Load your plot", + permission = "plots.load", + usage = "/plot load") +public class Load extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java index c262d6018..0d8d23dfe 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java @@ -79,15 +79,14 @@ public class MainCommand extends Command { new DebugClaimTest(); new Inbox(); new Comment(); - new Database(); + new DatabaseCommand(); new Swap(); new Music(); new DebugRoadRegen(); new Trust(); new DebugExec(); - new FlagCmd(); + new FlagCommand(); new Target(); - new DebugFixFlags(); new Move(); new Condense(); new Copy(); @@ -206,7 +205,8 @@ public class MainCommand extends Command { PlotArea area = player.getApplicablePlotArea(); Plot newPlot = Plot.fromString(area, args[0]); if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea() - .equals(area) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_SUDO_AREA)) + .equals(area) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN) + || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_SUDO_AREA)) && !newPlot.isDenied(player.getUUID())) { Location newLoc = newPlot.getCenter(); if (player.canTeleport(newLoc)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Merge.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Merge.java index 43204b266..b89eb6ec3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Merge.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Merge.java @@ -20,10 +20,14 @@ import java.util.UUID; import static com.github.intellectualsites.plotsquared.plot.object.Direction.getFromIndex; -@CommandDeclaration(command = "merge", aliases = "m", +@CommandDeclaration(command = "merge", + aliases = "m", description = "Merge the plot you are standing on with another plot", - permission = "plots.merge", usage = "/plot merge [removeroads]", - category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, confirmation = true) + permission = "plots.merge", + usage = "/plot merge [removeroads]", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + confirmation = true) public class Merge extends SubCommand { public static final String[] values = new String[] {"north", "east", "south", "west", "auto"}; @@ -160,8 +164,7 @@ public class Merge extends SubCommand { } Plot adjacent = plot.getRelative(direction); if (adjacent == null || !adjacent.hasOwner() || adjacent - .getMerged((direction.getIndex() + 2) % 4) - || adjacent.isOwner(uuid)) { + .getMerged((direction.getIndex() + 2) % 4) || adjacent.isOwner(uuid)) { MainUtil.sendMessage(player, Captions.NO_AVAILABLE_AUTOMERGE); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java index 95e07f9cd..9cc828f21 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java @@ -10,10 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.TeleportCause; /** * @author manuelgu, altered by Citymonstret */ -@CommandDeclaration(command = "middle", aliases = {"center", "centre"}, - description = "Teleports you to the center of the plot", usage = "/plot middle", - category = CommandCategory.TELEPORT, requiredType = RequiredType.PLAYER) public class Middle - extends SubCommand { +@CommandDeclaration(command = "middle", + aliases = {"center", "centre"}, + description = "Teleports you to the center of the plot", + usage = "/plot middle", + category = CommandCategory.TELEPORT, + requiredType = RequiredType.PLAYER) +public class Middle extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] arguments) { Location location = player.getLocation(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Move.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Move.java index 02c7494cb..bc6f885d7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Move.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Move.java @@ -10,9 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; -@CommandDeclaration(usage = "/plot move ", command = "move", description = "Move a plot", - permission = "plots.move", category = CommandCategory.CLAIMING, - requiredType = RequiredType.PLAYER) public class Move extends SubCommand { +@CommandDeclaration(usage = "/plot move ", + command = "move", + description = "Move a plot", + permission = "plots.move", + category = CommandCategory.CLAIMING, + requiredType = RequiredType.PLAYER) +public class Move extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java index 482a1f050..4d712eeba 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java @@ -2,7 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; @@ -14,10 +15,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Locale; -@CommandDeclaration(command = "music", permission = "plots.music", - description = "Play music in your plot", usage = "/plot music", - category = CommandCategory.APPEARANCE, requiredType = RequiredType.PLAYER) public class Music - extends SubCommand { +@CommandDeclaration(command = "music", + permission = "plots.music", + description = "Play music in your plot", + usage = "/plot music", + category = CommandCategory.APPEARANCE, + requiredType = RequiredType.PLAYER) +public class Music extends SubCommand { private static final Collection DISCS = Arrays .asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp", @@ -41,10 +45,11 @@ import java.util.Locale; return true; } if (item.getType() == ItemTypes.BEDROCK) { - plot.removeFlag(Flags.MUSIC); + plot.removeFlag(MusicFlag.class); Captions.FLAG_REMOVED.send(player); } else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) { - plot.setFlag(Flags.MUSIC, item.getType().getId()); + plot.setFlag(GlobalFlagContainer.getInstance().getFlag(MusicFlag.class) + .createFlagInstance(item.getType())); Captions.FLAG_ADDED.send(player); } else { Captions.FLAG_NOT_ADDED.send(player); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java index d897fb3cf..3119e216a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java @@ -11,8 +11,12 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players", - usage = "/plot near", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER) +@CommandDeclaration(command = "near", + aliases = "n", + description = "Display nearby players", + usage = "/plot near", + category = CommandCategory.INFO, + requiredType = RequiredType.PLAYER) public class Near extends Command { public Near() { super(MainCommand.getInstance(), true); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java index 82ec9f652..41f340ea1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java @@ -14,10 +14,15 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "setowner", permission = "plots.set.owner", - description = "Set the plot owner", usage = "/plot setowner ", - aliases = {"owner", "so", "seto"}, category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE, confirmation = true) public class Owner extends SetCommand { +@CommandDeclaration(command = "setowner", + permission = "plots.set.owner", + description = "Set the plot owner", + usage = "/plot setowner ", + aliases = {"owner", "so", "seto"}, + category = CommandCategory.CLAIMING, + requiredType = RequiredType.NONE, + confirmation = true) +public class Owner extends SetCommand { @Override public boolean set(final PlotPlayer player, final Plot plot, String value) { if (value == null || value.isEmpty()) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java index 5cbb7926d..c731c1b11 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java @@ -8,15 +8,23 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.isPremium; -@CommandDeclaration(command = "plugin", permission = "plots.use", - description = "Show plugin information", usage = "/plot plugin", aliases = "version", - category = CommandCategory.INFO) public class PluginCmd extends SubCommand { +@CommandDeclaration(command = "plugin", + permission = "plots.use", + description = "Show plugin information", + usage = "/plot plugin", + aliases = "version", + category = CommandCategory.INFO) +public class PluginCmd extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { TaskManager.IMP.taskAsync(() -> { - MainUtil.sendMessage(player, String.format("$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)", PlotSquared.get().getVersion())); - MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault"); - MainUtil.sendMessage(player, "$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki"); + MainUtil.sendMessage(player, String.format( + "$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)", + PlotSquared.get().getVersion())); + MainUtil.sendMessage(player, + "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault"); + MainUtil.sendMessage(player, + "$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki"); MainUtil.sendMessage(player, "$2>> $1&lPremium$2: $1" + isPremium()); }); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java index 0825b9610..7d31439aa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java @@ -18,11 +18,14 @@ import java.util.HashSet; import java.util.Map.Entry; import java.util.UUID; -@CommandDeclaration( - usage = "/plot purge world: area: id: owner: shared: unknown:[true|false]", - command = "purge", permission = "plots.admin", description = "Purge all plots for a world", - category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE, - confirmation = true) public class Purge extends SubCommand { +@CommandDeclaration(usage = "/plot purge world: area: id: owner: shared: unknown:[true|false]", + command = "purge", + permission = "plots.admin", + description = "Purge all plots for a world", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.CONSOLE, + confirmation = true) +public class Purge extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java index 603433b7f..e1c17b80d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java @@ -6,7 +6,7 @@ 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.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack; @@ -24,9 +24,14 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.UUID; -@CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot", - usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO, - requiredType = RequiredType.PLAYER) public class Rate extends SubCommand { +@CommandDeclaration(command = "rate", + permission = "plots.rate", + description = "Rate the plot", + usage = "/plot rate [#|next|purge]", + aliases = "rt", + category = CommandCategory.INFO, + requiredType = RequiredType.PLAYER) +public class Rate extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 1) { @@ -53,7 +58,7 @@ import java.util.UUID; }); UUID uuid = player.getUUID(); for (Plot p : plots) { - if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p + if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(p)) && p .isBasePlot() && (!p.getRatings().containsKey(uuid)) && !p .isAdded(uuid)) { p.teleportPlayer(player, TeleportCause.COMMAND); @@ -91,7 +96,7 @@ import java.util.UUID; sendMessage(player, Captions.RATING_NOT_YOUR_OWN); return false; } - if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) { + if (Settings.Done.REQUIRED_FOR_RATINGS && !DoneFlag.isDone(plot)) { sendMessage(player, Captions.RATING_NOT_DONE); return false; } @@ -146,15 +151,15 @@ import java.util.UUID; inventory.openInventory(); } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; @@ -187,15 +192,15 @@ import java.util.UUID; sendMessage(player, Captions.RATING_APPLIED, plot.getId().toString()); } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java index e47cb610f..224dc128e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java @@ -12,9 +12,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; @CommandDeclaration(command = "regenallroads", description = "Regenerate all roads in the map using the set road schematic", - aliases = {"rgar"}, usage = "/plot regenallroads [height]", - category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE, - permission = "plots.regenallroads") public class RegenAllRoads extends SubCommand { + aliases = {"rgar"}, + usage = "/plot regenallroads [height]", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.CONSOLE, + permission = "plots.regenallroads") +public class RegenAllRoads extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { int height = 0; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java index cc5c8c21a..abb56f493 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java @@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import java.util.concurrent.CompletableFuture; -@CommandDeclaration(command = "relight", description = "Relight your plot", usage = "/plot relight", - category = CommandCategory.DEBUG, requiredType = RequiredType.PLAYER) public class Relight extends Command { +@CommandDeclaration(command = "relight", + description = "Relight your plot", + usage = "/plot relight", + category = CommandCategory.DEBUG, + requiredType = RequiredType.PLAYER) +public class Relight extends Command { public Relight() { super(MainCommand.getInstance(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java index db900e91e..d536590e4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java @@ -12,9 +12,13 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.io.IOException; import java.util.Objects; -@CommandDeclaration(command = "reload", aliases = "rl", permission = "plots.admin.command.reload", - description = "Reload translations and world settings", usage = "/plot reload", - category = CommandCategory.ADMINISTRATION) public class Reload extends SubCommand { +@CommandDeclaration(command = "reload", + aliases = "rl", + permission = "plots.admin.command.reload", + description = "Reload translations and world settings", + usage = "/plot reload", + category = CommandCategory.ADMINISTRATION) +public class Reload extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { try { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java index debf93c28..f20d63a92 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java @@ -17,10 +17,14 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "remove", aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"}, - description = "Remove a player from a plot", usage = "/plot remove ", - category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, - permission = "plots.remove") public class Remove extends SubCommand { +@CommandDeclaration(command = "remove", + aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"}, + description = "Remove a player from a plot", + usage = "/plot remove ", + category = CommandCategory.SETTINGS, + requiredType = RequiredType.NONE, + permission = "plots.remove") +public class Remove extends SubCommand { public Remove() { super(Argument.PlayerName); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java index d000f55e2..e9272c1b7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java @@ -18,9 +18,13 @@ import java.net.URL; import java.util.List; import java.util.UUID; -@CommandDeclaration(command = "save", aliases = {"backup"}, description = "Save your plot", - category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, - permission = "plots.save") public class Save extends SubCommand { +@CommandDeclaration(command = "save", + aliases = {"backup"}, + description = "Save your plot", + category = CommandCategory.SCHEMATIC, + requiredType = RequiredType.NONE, + permission = "plots.save") +public class Save extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java index 130f2ad1d..6e2bf739c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java @@ -23,9 +23,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.UUID; -@CommandDeclaration(command = "schematic", permission = "plots.schematic", - description = "Schematic command", aliases = {"sch", "schem"}, - category = CommandCategory.SCHEMATIC, usage = "/plot schematic ") +@CommandDeclaration(command = "schematic", + permission = "plots.schematic", + description = "Schematic command", + aliases = {"sch", "schem"}, + category = CommandCategory.SCHEMATIC, + usage = "/plot schematic ") public class SchematicCmd extends SubCommand { private boolean running = false; @@ -136,7 +139,8 @@ public class SchematicCmd extends SubCommand { return false; } else { MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_STARTED); - MainUtil.sendMessage(player, "&3Plot&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots..."); + MainUtil.sendMessage(player, + "&3Plot&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots..."); } break; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java index c633ff61e..c55c399eb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java @@ -2,10 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -19,16 +17,18 @@ import com.sk89q.worldedit.function.pattern.Pattern; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -@CommandDeclaration(command = "set", description = "Set a plot value", aliases = {"s"}, - usage = "/plot set ", permission = "plots.set", - category = CommandCategory.APPEARANCE, requiredType = RequiredType.NONE) public class Set - extends SubCommand { +@CommandDeclaration(command = "set", + description = "Set a plot value", + aliases = {"s"}, + usage = "/plot set ", + permission = "plots.set", + category = CommandCategory.APPEARANCE, + requiredType = RequiredType.NONE) +public class Set extends SubCommand { - public static final String[] values = new String[] {"biome", "alias", "home", "flag"}; - public static final String[] aliases = new String[] {"b", "w", "wf", "f", "a", "h", "fl"}; + public static final String[] values = new String[] {"biome", "alias", "home"}; + public static final String[] aliases = new String[] {"b", "w", "wf", "a", "h"}; private final SetCommand component; @@ -50,9 +50,10 @@ import java.util.stream.IntStream; for (String component : components) { if (component.equalsIgnoreCase(args[0])) { - if (!Permissions.hasPermission(player, Captions - .format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), component))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), + component))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility .format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), component)); return false; @@ -82,16 +83,14 @@ import java.util.stream.IntStream; } public boolean noArgs(PlotPlayer player) { - ArrayList newValues = - new ArrayList<>(Arrays.asList("biome", "alias", "home", "flag")); + ArrayList newValues = new ArrayList<>(Arrays.asList("biome", "alias", "home")); Plot plot = player.getCurrentPlot(); if (plot != null) { - newValues.addAll( - Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); + newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); } - MainUtil - .sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + StringMan - .join(newValues, Captions.BLOCK_LIST_SEPARATOR.formatted())); + MainUtil.sendMessage(player, + Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + StringMan + .join(newValues, Captions.BLOCK_LIST_SEPARATOR.formatted())); return false; } @@ -114,22 +113,11 @@ import java.util.stream.IntStream; return false; } // components - HashSet components = new HashSet<>( - Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); + HashSet components = + new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); if (components.contains(args[0].toLowerCase())) { return this.component.onCommand(player, Arrays.copyOfRange(args, 0, args.length)); } - // flag - Flag flag = FlagManager.getFlag(args[0].toLowerCase()); - if (Flags.getFlags().contains(flag)) { - String a = ""; - if (args.length > 1) { - a = IntStream.range(1, args.length).mapToObj(x -> " " + args[x]) - .collect(Collectors.joining()); - } - MainCommand.onCommand(player, ("flag set " + args[0] + a).split(" ")); - return true; - } return noArgs(player); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java index cfb45fa95..e3190b3a9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.commands; +import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -17,21 +18,21 @@ public abstract class SetCommand extends SubCommand { return !sendMessage(player, Captions.NOT_IN_PLOT); } if (!plot.hasOwner()) { - if (!Permissions - .hasPermission(player, - Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), + getFullId())); MainUtil.sendMessage(player, Captions.PLOT_NOT_CLAIMED); return false; } } if (!plot.isOwner(player.getUUID())) { - if (!Permissions - .hasPermission(player, - Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); + if (!Permissions.hasPermission(player, CaptionUtility + .format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility + .format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), + getFullId())); MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java index 4b742ad94..7754644f3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java @@ -8,9 +8,13 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -@CommandDeclaration(command = "sethome", permission = "plots.set.home", - description = "Set the plot home to your current position", usage = "/plot sethome [none]", - aliases = {"sh", "seth"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) +@CommandDeclaration(command = "sethome", + permission = "plots.set.home", + description = "Set the plot home to your current position", + usage = "/plot sethome [none]", + aliases = {"sh", "seth"}, + category = CommandCategory.SETTINGS, + requiredType = RequiredType.PLAYER) public class SetHome extends SetCommand { @Override public boolean set(PlotPlayer player, Plot plot, String value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java index 8b8b22653..3e0dc86ae 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java @@ -34,9 +34,19 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; -@CommandDeclaration(command = "setup", permission = "plots.admin.command.setup", - description = "Setup wizard for plot worlds", usage = "/plot setup", aliases = {"create"}, - category = CommandCategory.ADMINISTRATION) public class Setup extends SubCommand { +@CommandDeclaration(command = "setup", + permission = "plots.admin.command.setup", + description = "Setup wizard for plot worlds", + usage = "/plot setup", + aliases = {"create"}, + category = CommandCategory.ADMINISTRATION) +public class Setup extends SubCommand { + + private static boolean d(String s) { + return s.chars().allMatch((i) -> { + return i == 95 || i == 45 || i >= 97 && i <= 122 || i >= 48 && i <= 57 || i == 46; + }); + } public void displayGenerators(PlotPlayer player) { StringBuilder message = new StringBuilder(); @@ -336,11 +346,7 @@ import java.util.UUID; return false; } - private static boolean d(String s) { - return s.chars().allMatch((i) -> { - return i == 95 || i == 45 || i >= 97 && i <= 122 || i >= 48 && i <= 57 || i == 46; - }); - } + private static final class StepPickGenerator extends SetupStep { @Getter private String generator; @@ -414,7 +420,7 @@ import java.util.UUID; } @Override public boolean parseInput(String input) { - if (!WORLD_TYPES.keySet().contains(input.toLowerCase())) { + if (!WORLD_TYPES.containsKey(input.toLowerCase())) { return false; } this.worldType = input.toLowerCase(); @@ -427,7 +433,9 @@ import java.util.UUID; } - @ToString @EqualsAndHashCode(of = "uuid") @AllArgsConstructor + @ToString + @EqualsAndHashCode(of = "uuid") + @AllArgsConstructor private static class SetupContext { private final UUID uuid; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Swap.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Swap.java index b3ec2ff05..d942c069f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Swap.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Swap.java @@ -8,8 +8,12 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; -@CommandDeclaration(usage = "/plot swap ", command = "swap", description = "Swap two plots", - aliases = {"switch"}, category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER) +@CommandDeclaration(usage = "/plot swap ", + command = "swap", + description = "Swap two plots", + aliases = {"switch"}, + category = CommandCategory.CLAIMING, + requiredType = RequiredType.PLAYER) public class Swap extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Target.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Target.java index 4dd37bdb0..6d9f618e2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Target.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Target.java @@ -10,10 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -@CommandDeclaration(command = "target", usage = "/plot target <|nearest>", - description = "Target a plot with your compass", permission = "plots.target", - requiredType = RequiredType.PLAYER, category = CommandCategory.INFO) public class Target - extends SubCommand { +@CommandDeclaration(command = "target", + usage = "/plot target <|nearest>", + description = "Target a plot with your compass", + permission = "plots.target", + requiredType = RequiredType.PLAYER, + category = CommandCategory.INFO) +public class Target extends SubCommand { public Target() { super(Argument.PlotID); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java index d001388ea..90660e5e5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java @@ -29,10 +29,12 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -@CommandDeclaration(command = "template", permission = "plots.admin", +@CommandDeclaration(command = "template", + permission = "plots.admin", description = "Create or use a world template", usage = "/plot template [import|export]