From aaf9511673c17d2e7223d6a201c4fed33d20b4d4 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Tue, 19 Apr 2016 16:59:10 -0400 Subject: [PATCH] Start implementing new Flag system. --- .../plot/api/PlotAPI.java | 16 +- .../com/plotsquared/bukkit/BukkitMain.java | 13 +- .../database/plotme/APlotMeConnector.java | 11 - .../bukkit/listeners/ForceFieldListener.java | 16 +- .../bukkit/listeners/PlayerEvents.java | 621 +++++++++--------- .../bukkit/listeners/PlayerEvents183.java | 4 +- .../bukkit/listeners/PlotPlusListener.java | 24 +- .../bukkit/titles/DefaultTitleManager.java | 43 +- .../titles/DefaultTitleManager_183.java | 93 +-- .../bukkit/titles/HackTitleManager.java | 34 +- .../bukkit/titles/TitleManager.java | 34 + .../bukkit/util/BukkitChatManager.java | 26 +- .../bukkit/util/BukkitEventUtil.java | 4 +- .../bukkit/util/BukkitPlainChatManager.java | 18 +- Core/build.gradle | 2 +- .../com/intellectualcrafters/plot/PS.java | 22 +- .../plot/commands/Buy.java | 13 +- .../plot/commands/Clear.java | 11 +- .../plot/commands/Continue.java | 4 +- .../plot/commands/DebugExec.java | 6 +- .../plot/commands/DebugFixFlags.java | 9 +- .../plot/commands/Desc.java | 7 +- .../plot/commands/Done.java | 6 +- .../plot/commands/Download.java | 9 +- .../plot/commands/FlagCmd.java | 81 +-- .../plot/commands/ListCmd.java | 14 +- .../plot/commands/Music.java | 7 +- .../plot/commands/Set.java | 4 +- .../plot/database/AbstractDB.java | 7 +- .../plot/database/DBFunc.java | 5 +- .../plot/database/SQLManager.java | 88 +-- .../plot/flag/AbstractFlag.java | 28 +- .../plot/flag/BooleanFlag.java | 29 + .../intellectualcrafters/plot/flag/Flag.java | 114 +--- .../plot/flag/FlagManager.java | 293 +++------ .../plot/flag/FlagValue.java | 89 +-- .../intellectualcrafters/plot/flag/Flags.java | 84 +++ .../plot/flag/GameModeFlag.java | 41 ++ .../plot/flag/IntegerFlag.java | 8 - .../plot/flag/IntegerListFlag.java | 23 + .../plot/flag/IntervalFlag.java | 41 ++ .../plot/flag/ListFlag.java | 18 + .../plot/flag/NumericFlag.java | 16 + .../plot/flag/PlotBlockListFlag.java | 53 ++ .../plot/flag/PlotWeatherFlag.java | 22 + .../plot/flag/StringFlag.java | 21 + .../plot/flag/StringListFlag.java | 18 + .../plot/generator/HybridUtils.java | 5 +- .../plot/object/Plot.java | 48 +- .../plot/object/PlotAnalysis.java | 10 +- .../plot/object/PlotArea.java | 2 +- .../plot/object/PlotSettings.java | 16 +- .../plot/util/ConsoleColors.java | 12 +- .../plot/util/EventUtil.java | 141 ++-- .../plot/util/ExpireManager.java | 11 +- .../plot/util/MainUtil.java | 13 +- .../plot/util/SchematicHandler.java | 8 +- .../plotsquared/listener/PlotListener.java | 74 ++- .../com/plotsquared/listener/WEManager.java | 4 +- .../intellectualcrafters/plot/FlagTest.java | 55 ++ .../plot/database/AbstractDBTEst.java | 243 +++++++ .../plot/util/EventUtilTest.java | 76 +++ .../sponge/listener/MainListener.java | 101 ++- .../sponge/util/SpongeChatManager.java | 28 +- .../sponge/util/SpongeEventUtil.java | 4 +- 65 files changed, 1679 insertions(+), 1322 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/GameModeFlag.java delete mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerListFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/IntervalFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/NumericFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/PlotBlockListFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/PlotWeatherFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/StringFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/StringListFlag.java create mode 100644 Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java create mode 100644 Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java create mode 100644 Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java diff --git a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index a8bfb68e4..37232f521 100644 --- a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -385,18 +385,6 @@ public class PlotAPI { FlagManager.addFlag(flag); } - /** - * get all the currently registered flags. - * - * @return array of Flag[] - * - * @see FlagManager#getFlags() - * @see AbstractFlag - */ - public AbstractFlag[] getFlags() { - return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); - } - /** * Get a plot based on the ID. * @@ -663,7 +651,7 @@ public class PlotAPI { if (world == null) { return new HashSet<>(); } - return BukkitUtil.getPlayer(player).getPlots(world.getName()); + return PlotPlayer.wrap(player).getPlots(world.getName()); } /** @@ -675,7 +663,7 @@ public class PlotAPI { * */ public int getAllowedPlots(Player player) { - PlotPlayer pp = BukkitUtil.getPlayer(player); + PlotPlayer pp = PlotPlayer.wrap(player); return pp.getAllowedPlots(); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1d056379d..b175b5377 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridUtils; @@ -95,7 +94,7 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; -public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { +public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public static WorldEditPlugin worldEdit; @@ -195,14 +194,18 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public void run() { PS.get().foreachPlotArea(new RunnableVal() { @Override - public void run(PlotArea pw) { - World world = Bukkit.getWorld(pw.worldname); + public void run(PlotArea plotArea) { + World world = Bukkit.getWorld(plotArea.worldname); try { if (world == null) { return; } List entities = world.getEntities(); Iterator iterator = entities.iterator(); + for (Entity entity : entities) { + + } + while (iterator.hasNext()) { Entity entity = iterator.next(); switch (entity.getType()) { @@ -211,6 +214,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { case COMPLEX_PART: case FISHING_HOOK: case ENDER_SIGNAL: + case LINGERING_POTION: case AREA_EFFECT_CLOUD: case EXPERIENCE_ORB: case LEASH_HITCH: @@ -507,7 +511,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { if (!checkVersion) { log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); Settings.TITLES = false; - FlagManager.removeFlag(FlagManager.getFlag("titles")); } else { AbstractTitle.TITLE_CLASS = new DefaultTitle_19(); if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java index 444251c8d..e1d54f5bf 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java @@ -5,8 +5,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; -import org.bukkit.Bukkit; -import org.bukkit.World; import java.sql.Connection; import java.sql.SQLException; @@ -21,15 +19,6 @@ abstract class APlotMeConnector { public abstract boolean accepts(String version); - public String getWorld(String world) { - for (World newWorld : Bukkit.getWorlds()) { - if (newWorld.getName().equalsIgnoreCase(world)) { - return newWorld.getName(); - } - } - return world; - } - public boolean isValidConnection(Connection connection) { return connection != null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java index f91432e5c..b6b89b17c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -1,6 +1,7 @@ package com.plotsquared.bukkit.listeners; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.google.common.base.Optional; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -36,7 +37,13 @@ public class ForceFieldListener implements Listener { private PlotPlayer hasNearbyPermitted(Player player, Plot plot) { for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) { PlotPlayer pp; - if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) { + if (!(entity instanceof Player)) { + continue; + } + if ((pp = BukkitUtil.getPlayer((Player) entity)) == null) { + continue; + } + if (!plot.equals(pp.getCurrentPlot())) { continue; } if (plot.isAdded(pp.getUUID())) { @@ -84,8 +91,9 @@ public class ForceFieldListener implements Listener { if (plot == null) { return; } - if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) { - if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) { + Optional forcefield = plot.getFlag(Flags.FORCEFIELD); + if (forcefield.isPresent() && forcefield.get()) { + if (!plot.getFlag(Flags.FORCEFIELD).or(false)) { UUID uuid = pp.getUUID(); if (plot.isAdded(uuid)) { Set players = getNearbyPlayers(player, plot); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 27d78950f..ea151ae83 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,10 +1,11 @@ package com.plotsquared.bukkit.listeners; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.flag.NumericFlag; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -62,7 +63,6 @@ import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.block.BlockIgniteEvent; @@ -196,9 +196,8 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - Flag redstone = FlagManager.getPlotFlagRaw(plot, "redstone"); - if (redstone != null) { - if ((Boolean) redstone.getValue()) { + if (plot.getFlag(Flags.REDSTONE).isPresent()) { + if (plot.getFlag(Flags.REDSTONE).get()) { return; } else { event.setNewCurrent(0); @@ -246,7 +245,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - if (FlagManager.isPlotFlagFalse(plot, "redstone")) { + if (plot.getFlag(Flags.REDSTONE).isPresent() && !plot.getFlag(Flags.REDSTONE).get()) { event.setCancelled(true); } return; @@ -262,7 +261,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlotAbs(loc); - if (plot != null && FlagManager.isPlotFlagTrue(plot, "disable-physics")) { + if (plot != null && plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { event.setCancelled(true); return; } @@ -368,64 +367,63 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "blocked-cmds"); - if (flag == null || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { - return; - } - List v = (List) flag.getValue(); - String[] parts = msg.split(" "); - String c = parts[0]; - if (parts[0].contains(":")) { - c = parts[0].split(":")[1]; - msg = msg.replace(parts[0].split(":")[0] + ":", ""); - } - String l = c; - List aliases = new ArrayList<>(); - for (HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) { - if (c.equals(cmdLabel.getName())) { - break; + Optional> flag = plot.getFlag(Flags.BLOCKED_CMDS); + if (flag.isPresent() && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { + List blocked_cmds = flag.get(); + String[] parts = msg.split(" "); + String c = parts[0]; + if (parts[0].contains(":")) { + c = parts[0].split(":")[1]; + msg = msg.replace(parts[0].split(":")[0] + ":", ""); } - String label = cmdLabel.getName().replaceFirst("/", ""); - if (aliases.contains(label)) { - continue; - } - PluginCommand p; - if ((p = Bukkit.getPluginCommand(label)) != null) { - for (String a : p.getAliases()) { - if (aliases.contains(a)) { - continue; - } - aliases.add(a); - a = a.replaceFirst("/", ""); - if (!a.equals(label) && a.equals(c)) { - c = label; - break; + String l = c; + List aliases = new ArrayList<>(); + for (HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) { + if (c.equals(cmdLabel.getName())) { + break; + } + String label = cmdLabel.getName().replaceFirst("/", ""); + if (aliases.contains(label)) { + continue; + } + PluginCommand p; + if ((p = Bukkit.getPluginCommand(label)) != null) { + for (String a : p.getAliases()) { + if (aliases.contains(a)) { + continue; + } + aliases.add(a); + a = a.replaceFirst("/", ""); + if (!a.equals(label) && a.equals(c)) { + c = label; + break; + } } } } - } - if (!l.equals(c)) { - msg = msg.replace(l, c); - } - for (String s : v) { - Pattern pattern; - if (!RegExUtil.compiledPatterns.containsKey(s)) { - RegExUtil.compiledPatterns.put(s, pattern = Pattern.compile(s)); - } else { - pattern = RegExUtil.compiledPatterns.get(s); + if (!l.equals(c)) { + msg = msg.replace(l, c); } - if (pattern.matcher(msg).matches()) { - MainUtil.sendMessage(pp, C.COMMAND_BLOCKED); - String perm; - if (plot.isAdded(pp.getUUID())) { - perm = "plots.admin.command.blocked-cmds.shared"; + for (String s : blocked_cmds) { + Pattern pattern; + if (!RegExUtil.compiledPatterns.containsKey(s)) { + RegExUtil.compiledPatterns.put(s, pattern = Pattern.compile(s)); } else { - perm = "plots.admin.command.blocked-cmds.other"; + pattern = RegExUtil.compiledPatterns.get(s); } - if (!Permissions.hasPermission(pp, perm)) { - event.setCancelled(true); + if (pattern.matcher(msg).matches()) { + MainUtil.sendMessage(pp, C.COMMAND_BLOCKED); + String perm; + if (plot.isAdded(pp.getUUID())) { + perm = "plots.admin.command.blocked-cmds.shared"; + } else { + perm = "plots.admin.command.blocked-cmds.other"; + } + if (!Permissions.hasPermission(pp, perm)) { + event.setCancelled(true); + } + return; } - return; } } } @@ -636,9 +634,9 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); return; } else if (!plot.isAdded(pp.getUUID())) { - Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); - if (destroy != null && ((HashSet) destroy.getValue()) + if (destroy.isPresent() && destroy.get() .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { return; } @@ -647,7 +645,7 @@ public class PlayerEvents extends PlotListener implements Listener { } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); - } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) { + } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey(Flags.DONE)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); @@ -688,7 +686,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getOwnedPlot(location); if (plot != null) { - if (FlagManager.isPlotFlagTrue(plot, "explosion")) { + if (plot.getFlag(Flags.EXPLOSION).isPresent() && plot.getFlag(Flags.EXPLOSION).get()) { List meta = event.getEntity().getMetadata("plot"); Plot origin; if (meta.isEmpty()) { @@ -734,7 +732,7 @@ public class PlayerEvents extends PlotListener implements Listener { plotExit(pp, plot); } - if (true && PS.get().worldedit != null) { + if (PS.get().worldedit != null) { if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) { if (pp.getAttribute("worldedit")) { pp.removeAttribute("worldedit"); @@ -759,47 +757,65 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityBlockForm(EntityBlockFormEvent e) { - String world = e.getBlock().getWorld().getName(); + public void onEntityBlockForm(EntityBlockFormEvent event) { + String world = event.getBlock().getWorld().getName(); if (!PS.get().hasPlotArea(world)) { return; } - if (BukkitUtil.getLocation(e.getBlock().getLocation()).getPlotArea() != null) { - e.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockSpread(BlockSpreadEvent event) { - onBlockForm(event); //send to super class. - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockForm(BlockFormEvent event) { - Block block = event.getBlock(); - Location loc = BukkitUtil.getLocation(block.getLocation()); - if (loc.isPlotRoad()) { + if (BukkitUtil.getLocation(event.getBlock().getLocation()).getPlotArea() != null) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBD(BlockDamageEvent event) { + public void onBlockSpread(BlockSpreadEvent event) { + Block block = event.getBlock(); + Location location = BukkitUtil.getLocation(block.getLocation()); + if (location.isPlotRoad()) { + event.setCancelled(true); + return; + } + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getOwnedPlot(location); + switch (block.getType()) { + case GRASS: + if (plot.getFlag(Flags.GRASS_GROW).isPresent() && plot.getFlag(Flags.GRASS_GROW).get()) { + event.setCancelled(true); + } + break; + case MYCEL: + if (plot.getFlag(Flags.MYCEL_GROW).isPresent() && plot.getFlag(Flags.MYCEL_GROW).get()) { + event.setCancelled(true); + } + break; + case VINE: + if (plot.getFlag(Flags.VINE_GROW).isPresent() && plot.getFlag(Flags.VINE_GROW).get()) { + event.setCancelled(true); + } + break; + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockDamage(BlockDamageEvent event) { Player player = event.getPlayer(); - Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); + Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); if (player == null) { - if (loc.isPlotRoad()) { + if (location.isPlotRoad()) { event.setCancelled(true); return; } } - PlotArea area = loc.getPlotArea(); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Plot plot = area.getPlotAbs(loc); + Plot plot = area.getPlotAbs(location); if (plot != null) { - if (loc.getY() == 0) { + if (location.getY() == 0) { event.setCancelled(true); return; } @@ -813,10 +829,9 @@ public class PlayerEvents extends PlotListener implements Listener { } PlotPlayer pp = BukkitUtil.getPlayer(player); if (!plot.isAdded(pp.getUUID())) { - Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); - if (destroy != null && ((HashSet) destroy.getValue()) - .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { + if (destroy.isPresent() && destroy.get().contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { return; } if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { @@ -837,35 +852,48 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFade(BlockFadeEvent e) { Block b = e.getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(b.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Plot plot = area.getOwnedPlot(loc); + Plot plot = area.getOwnedPlot(location); if (plot == null) { e.setCancelled(true); return; } switch (b.getType()) { - case WATER: - case STATIONARY_WATER: - if (FlagManager.isPlotFlagFalse(plot, "ice-melt")) { - e.setCancelled(true); + case ICE: + Optional ice_melt = plot.getFlag(Flags.ICE_MELT); + if (ice_melt.isPresent()) { + if (!ice_melt.get()) { + e.setCancelled(true); + } } break; case SNOW: - if (FlagManager.isPlotFlagFalse(plot, "snow-melt")) { - e.setCancelled(true); + Optional snow_melt = plot.getFlag(Flags.SNOW_MELT); + if (snow_melt.isPresent()) { + if (!snow_melt.get()) { + e.setCancelled(true); + } + } + break; + case SOIL: + Optional soil_dry = plot.getFlag(Flags.SOIL_DRY); + if (soil_dry.isPresent()) { + if (!soil_dry.get()) { + e.setCancelled(true); + } } break; } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onChange(BlockFromToEvent e) { - Block from = e.getBlock(); - Block to = e.getToBlock(); + public void onChange(BlockFromToEvent event) { + Block from = event.getBlock(); + Block to = event.getToBlock(); Location tLocation = BukkitUtil.getLocation(to.getLocation()); PlotArea area = tLocation.getPlotArea(); if (area == null) { @@ -873,30 +901,35 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getOwnedPlot(tLocation); Location fLocation = BukkitUtil.getLocation(from.getLocation()); - if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation)) || (plot != null && FlagManager - .isPlotFlagTrue(plot, "disable-physics"))) { - e.setCancelled(true); + if (plot != null) { + if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { + event.setCancelled(true); + } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { + event.setCancelled(true); + } + } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { + event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onGrow(BlockGrowEvent e) { - Block b = e.getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); - if (loc.isUnownedPlotArea()) { - e.setCancelled(true); + public void onGrow(BlockGrowEvent event) { + Block b = event.getBlock(); + Location location = BukkitUtil.getLocation(b.getLocation()); + if (location.isUnownedPlotArea()) { + event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { Block block = event.getBlock(); - Location loc = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.getLocation(block.getLocation()); BlockFace face = event.getDirection(); Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); - PlotArea area = loc.getPlotArea(); + PlotArea area = location.getPlotArea(); if (area == null) { - if (!PS.get().hasPlotArea(loc.getWorld())) { + if (!PS.get().hasPlotArea(location.getWorld())) { return; } for (Block b : event.getBlocks()) { @@ -907,7 +940,7 @@ public class PlayerEvents extends PlotListener implements Listener { } return; } - Plot plot = area.getOwnedPlot(loc); + Plot plot = area.getOwnedPlot(location); if (plot == null) { event.setCancelled(true); return; @@ -929,17 +962,17 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { Block block = event.getBlock(); - Location loc = BukkitUtil.getLocation(block.getLocation()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(block.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { - if (!PS.get().hasPlotArea(loc.getWorld())) { + if (!PS.get().hasPlotArea(location.getWorld())) { return; } if (this.pistonBlocks) { try { for (Block pulled : event.getBlocks()) { - loc = BukkitUtil.getLocation(pulled.getLocation()); - if (loc.getPlotArea() != null) { + location = BukkitUtil.getLocation(pulled.getLocation()); + if (location.getPlotArea() != null) { event.setCancelled(true); return; } @@ -950,24 +983,24 @@ public class PlayerEvents extends PlotListener implements Listener { } if (!this.pistonBlocks && block.getType() != Material.PISTON_BASE) { BlockFace dir = event.getDirection(); - loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); - if (loc.getPlotArea() != null) { + location = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); + if (location.getPlotArea() != null) { event.setCancelled(true); return; } } return; } - Plot plot = area.getOwnedPlot(loc); + Plot plot = area.getOwnedPlot(location); if (this.pistonBlocks) { try { for (Block pulled : event.getBlocks()) { - loc = BukkitUtil.getLocation(pulled.getLocation()); - if (!area.contains(loc.getX(), loc.getZ())) { + location = BukkitUtil.getLocation(pulled.getLocation()); + if (!area.contains(location.getX(), location.getZ())) { event.setCancelled(true); return; } - Plot newPlot = area.getOwnedPlot(loc); + Plot newPlot = area.getOwnedPlot(location); if (!Objects.equals(plot, newPlot)) { event.setCancelled(true); return; @@ -979,12 +1012,12 @@ public class PlayerEvents extends PlotListener implements Listener { } if (!this.pistonBlocks && block.getType() != Material.PISTON_BASE) { BlockFace dir = event.getDirection(); - loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); - if (!area.contains(loc)) { + location = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); + if (!area.contains(location)) { event.setCancelled(true); return; } - Plot newPlot = area.getOwnedPlot(loc); + Plot newPlot = area.getOwnedPlot(location); if (!Objects.equals(plot, newPlot)) { event.setCancelled(true); } @@ -992,64 +1025,64 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockDispense(BlockDispenseEvent e) { - Material type = e.getItem().getType(); + public void onBlockDispense(BlockDispenseEvent event) { + Material type = event.getItem().getType(); if (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET) { return; } - Location loc = BukkitUtil.getLocation(e.getVelocity().toLocation(e.getBlock().getWorld())); - if (loc.isPlotRoad()) { - e.setCancelled(true); + Location location = BukkitUtil.getLocation(event.getVelocity().toLocation(event.getBlock().getWorld())); + if (location.isPlotRoad()) { + event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onStructureGrow(StructureGrowEvent e) { - if (!PS.get().hasPlotArea(e.getWorld().getName())) { + public void onStructureGrow(StructureGrowEvent event) { + if (!PS.get().hasPlotArea(event.getWorld().getName())) { return; } - List blocks = e.getBlocks(); + List blocks = event.getBlocks(); if (blocks.isEmpty()) { return; } - Location loc = BukkitUtil.getLocation(blocks.get(0).getLocation()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(blocks.get(0).getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { for (int i = blocks.size() - 1; i >= 0; i--) { - loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); - if (loc.getPlotArea() != null) { + location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + if (location.getPlotArea() != null) { blocks.remove(i); } } return; } else { - Plot origin = area.getOwnedPlot(loc); + Plot origin = area.getOwnedPlot(location); if (origin == null) { - e.setCancelled(true); + event.setCancelled(true); return; } for (int i = blocks.size() - 1; i >= 0; i--) { - loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); - if (!area.contains(loc.getX(), loc.getZ())) { + location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + if (!area.contains(location.getX(), location.getZ())) { blocks.remove(i); continue; } - Plot plot = area.getOwnedPlot(loc); + Plot plot = area.getOwnedPlot(location); if (!Objects.equals(plot, origin)) { - e.getBlocks().remove(i); + event.getBlocks().remove(i); } } } - Plot origin = area.getPlotAbs(loc); + Plot origin = area.getPlotAbs(location); if (origin == null) { - e.setCancelled(true); + event.setCancelled(true); return; } for (int i = blocks.size() - 1; i >= 0; i--) { - loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); - Plot plot = area.getOwnedPlot(loc); + location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + Plot plot = area.getOwnedPlot(location); if (!Objects.equals(plot, origin)) { - e.getBlocks().remove(i); + event.getBlocks().remove(i); } } } @@ -1064,19 +1097,19 @@ public class PlayerEvents extends PlotListener implements Listener { } PlayerBlockEventType eventType = null; BukkitLazyBlock lb; - Location loc; + Location location; Action action = event.getAction(); switch (action) { case PHYSICAL: { eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; Block block = event.getClickedBlock(); lb = new BukkitLazyBlock(block); - loc = BukkitUtil.getLocation(block.getLocation()); + location = BukkitUtil.getLocation(block.getLocation()); break; } case RIGHT_CLICK_BLOCK: { Block block = event.getClickedBlock(); - loc = BukkitUtil.getLocation(block.getLocation()); + location = BukkitUtil.getLocation(block.getLocation()); Material blockType = block.getType(); int blockId = blockType.getId(); switch (blockType) { @@ -1151,7 +1184,7 @@ public class PlayerEvents extends PlotListener implements Listener { lb = new BukkitLazyBlock(0, block); break; } else if (id < 198) { - loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); + location = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_BLOCK; lb = new BukkitLazyBlock(id, block); break; @@ -1165,7 +1198,7 @@ public class PlayerEvents extends PlotListener implements Listener { break; case ARMOR_STAND: - loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); + location = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_MISC; break; @@ -1209,7 +1242,7 @@ public class PlayerEvents extends PlotListener implements Listener { break; case PAINTING: case ITEM_FRAME: - loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); + location = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_HANGING; break; default: @@ -1220,7 +1253,7 @@ public class PlayerEvents extends PlotListener implements Listener { } case LEFT_CLICK_BLOCK: Block block = event.getClickedBlock(); - loc = BukkitUtil.getLocation(block.getLocation()); + location = BukkitUtil.getLocation(block.getLocation()); eventType = PlayerBlockEventType.BREAK_BLOCK; lb = new BukkitLazyBlock(block); break; @@ -1232,7 +1265,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) { + if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) { event.setCancelled(true); } } @@ -1243,8 +1276,8 @@ public class PlayerEvents extends PlotListener implements Listener { if (entity instanceof Player) { return; } - Location loc = BukkitUtil.getLocation(entity.getLocation()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } @@ -1279,7 +1312,7 @@ public class PlayerEvents extends PlotListener implements Listener { } break; } - Plot plot = area.getOwnedPlotAbs(loc); + Plot plot = area.getOwnedPlotAbs(location); if (plot == null) { if (!area.MOB_SPAWNING) { event.setCancelled(true); @@ -1302,17 +1335,17 @@ public class PlayerEvents extends PlotListener implements Listener { if (!PS.get().hasPlotArea(worldName)) { return; } - Location loc = BukkitUtil.getLocation(block.getLocation()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(block.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Plot plot = area.getOwnedPlotAbs(loc); + Plot plot = area.getOwnedPlotAbs(location); if (plot == null) { event.setCancelled(true); return; } - if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) { + if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { event.setCancelled(true); return; } @@ -1337,11 +1370,11 @@ public class PlayerEvents extends PlotListener implements Listener { this.lastRadius = event.getRadius() + 1; } - public boolean checkEntity(Plot plot, String... flags) { + public boolean checkEntity(Plot plot, NumericFlag... flags) { int[] mobs = null; - for (String flag : flags) { + for (NumericFlag flag : flags) { int i; - switch (flag) { + switch (flag.getName()) { case "entity-cap": i = 0; break; @@ -1363,14 +1396,14 @@ public class PlayerEvents extends PlotListener implements Listener { default: i = 0; } - Flag plotFlag = FlagManager.getPlotFlagRaw(plot, flag); - if (plotFlag == null) { + Optional plotFlag = plot.getFlag(flag); + if (!plotFlag.isPresent()) { continue; } if (mobs == null) { mobs = plot.countEntities(); } - if (mobs[i] >= (Integer) plotFlag.getValue()) { + if (mobs[i] >= plotFlag.get()) { return true; } } @@ -1390,6 +1423,7 @@ public class PlayerEvents extends PlotListener implements Listener { case EGG: case THROWN_EXP_BOTTLE: case SPLASH_POTION: + case LINGERING_POTION: case SNOWBALL: case ENDER_PEARL: case ARROW: @@ -1414,11 +1448,11 @@ public class PlayerEvents extends PlotListener implements Listener { case WITHER_SKULL: case UNKNOWN: // non moving / unmovable - return checkEntity(plot, "entity-cap"); + return checkEntity(plot, Flags.ENTITY_CAP); case ITEM_FRAME: case PAINTING: case ARMOR_STAND: - return checkEntity(plot, "entity-cap", "misc-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); // misc case MINECART: case MINECART_CHEST: @@ -1428,7 +1462,7 @@ public class PlayerEvents extends PlotListener implements Listener { case MINECART_MOB_SPAWNER: case MINECART_TNT: case BOAT: - return checkEntity(plot, "entity-cap", "vehicle-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); case RABBIT: case SHEEP: case MUSHROOM_COW: @@ -1444,7 +1478,7 @@ public class PlayerEvents extends PlotListener implements Listener { case BAT: case HORSE: // animal - return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); case BLAZE: case CAVE_SPIDER: case CREEPER: @@ -1465,37 +1499,37 @@ public class PlayerEvents extends PlotListener implements Listener { case ZOMBIE: case SHULKER: // monster - return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); default: if (entity instanceof LivingEntity) { if (entity instanceof Animals) { - return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); } else if (entity instanceof Monster) { - return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); } else { - return checkEntity(plot, "entity-cap", "mob-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP); } } else if (entity instanceof Vehicle) { - return checkEntity(plot, "entity-cap", "vehicle-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); } else if (entity instanceof Hanging) { - return checkEntity(plot, "entity-cap", "misc-cap"); + return checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); } - return checkEntity(plot, "entity-cap"); + return checkEntity(plot, Flags.ENTITY_CAP); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent e) { Block b = e.getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); + Location location = BukkitUtil.getLocation(b.getLocation()); - PlotArea area = loc.getPlotArea(); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Plot plot = loc.getOwnedPlot(); - if (plot == null || !FlagManager.isBooleanFlag(plot, "block-burn", false)) { + Plot plot = location.getOwnedPlot(); + if (plot == null || !plot.getFlag(Flags.BLOCK_BURN).or(false)) { e.setCancelled(true); return; } @@ -1545,11 +1579,11 @@ public class PlayerEvents extends PlotListener implements Listener { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } - } else if (!FlagManager.isPlotFlagTrue(plot, "block-ignition")) { + } else if (!plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { event.setCancelled(true); } } else if (ignitingEntity != null) { - if (plot == null || !FlagManager.isPlotFlagTrue(plot, "block-ignition")) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { event.setCancelled(true); return; } @@ -1573,7 +1607,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else if (event.getIgnitingBlock() != null) { Block ignitingBlock = event.getIgnitingBlock(); if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) { - if (plot == null || !FlagManager.isPlotFlagTrue(plot, "block-ignition")) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { event.setCancelled(true); return; } @@ -1587,7 +1621,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } if (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) { - if (plot == null || !FlagManager.isPlotFlagTrue(plot, "fire-spread")) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { event.setCancelled(true); return; } @@ -1751,38 +1785,38 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBucketEmpty(PlayerBucketEmptyEvent e) { - BlockFace bf = e.getBlockFace(); - Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); - PlotArea area = loc.getPlotArea(); + public void onBucketEmpty(PlayerBucketEmptyEvent event) { + BlockFace bf = event.getBlockFace(); + Block b = event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); + Location location = BukkitUtil.getLocation(b.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); - Plot plot = area.getPlotAbs(loc); + PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer()); + Plot plot = area.getPlotAbs(location); if (plot == null) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); - e.setCancelled(true); + event.setCancelled(true); } else if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); - e.setCancelled(true); + event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { - Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s()); - if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) e.getBucket().getId(), (byte) 0))) { + Optional> use = plot.getFlag(Flags.USE); + if (use.isPresent() && use.get().contains(new PlotBlock((short) event.getBucket().getId(), (byte) 0))) { return; } if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); - e.setCancelled(true); + event.setCancelled(true); } } @@ -1794,11 +1828,11 @@ public class PlayerEvents extends PlotListener implements Listener { } Player player = (Player) clicker; PlotPlayer pp = BukkitUtil.getPlayer(player); - PlotInventory inv = pp.getMeta("inventory"); - if (inv != null && event.getRawSlot() == event.getSlot()) { - if (!inv.onClick(event.getSlot())) { + PlotInventory inventory = pp.getMeta("inventory"); + if (inventory != null && event.getRawSlot() == event.getSlot()) { + if (!inventory.onClick(event.getSlot())) { event.setCancelled(true); - inv.close(); + inventory.close(); } } } @@ -1820,51 +1854,51 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBucketFill(PlayerBucketFillEvent e) { - Block b = e.getBlockClicked(); - Location loc = BukkitUtil.getLocation(b.getLocation()); - PlotArea area = loc.getPlotArea(); + public void onBucketFill(PlayerBucketFillEvent event) { + Block b = event.getBlockClicked(); + Location location = BukkitUtil.getLocation(b.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Player p = e.getPlayer(); - PlotPlayer pp = BukkitUtil.getPlayer(p); - Plot plot = area.getPlotAbs(loc); + Player player = event.getPlayer(); + PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); + Plot plot = area.getPlotAbs(location); if (plot == null) { - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { + if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_ROAD)) { return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); - e.setCancelled(true); + MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); + event.setCancelled(true); } else if (!plot.hasOwner()) { - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { + if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); - e.setCancelled(true); - } else if (!plot.isAdded(pp.getUUID())) { - Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s()); - Block block = e.getBlockClicked(); - if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { + MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); + event.setCancelled(true); + } else if (!plot.isAdded(plotPlayer.getUUID())) { + Optional> use = plot.getFlag(Flags.USE); + Block block = event.getBlockClicked(); + if (use.isPresent() && use.get().contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { return; } - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) { return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); - e.setCancelled(true); + MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleCreate(VehicleCreateEvent event) { Vehicle entity = event.getVehicle(); - Location loc = BukkitUtil.getLocation(entity); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(entity); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Plot plot = area.getOwnedPlotAbs(loc); + Plot plot = area.getOwnedPlotAbs(location); if (plot == null || checkEntity(entity, plot)) { entity.remove(); return; @@ -1875,147 +1909,147 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingPlace(HangingPlaceEvent e) { - Block b = e.getBlock().getRelative(e.getBlockFace()); - Location loc = BukkitUtil.getLocation(b.getLocation()); - PlotArea area = loc.getPlotArea(); + public void onHangingPlace(HangingPlaceEvent event) { + Block b = event.getBlock().getRelative(event.getBlockFace()); + Location location = BukkitUtil.getLocation(b.getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Player p = e.getPlayer(); + Player p = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(p); - Plot plot = area.getPlotAbs(loc); + Plot plot = area.getPlotAbs(location); if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); - e.setCancelled(true); + event.setCancelled(true); } } else { if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); - e.setCancelled(true); + event.setCancelled(true); } return; } else if (!plot.isAdded(pp.getUUID())) { - if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_PLACE.s())) { + if (!plot.getFlag(Flags.HANGING_PLACE).or(false)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); - e.setCancelled(true); + event.setCancelled(true); } return; } } - if (checkEntity(e.getEntity(), plot)) { - e.setCancelled(true); + if (checkEntity(event.getEntity(), plot)) { + event.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingBreakByEntity(HangingBreakByEntityEvent e) { - Entity r = e.getRemover(); - if (r instanceof Player) { - Player p = (Player) r; - Location l = BukkitUtil.getLocation(e.getEntity()); - PlotArea area = l.getPlotArea(); + public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { + Entity remover = event.getRemover(); + if (remover instanceof Player) { + Player p = (Player) remover; + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } PlotPlayer pp = BukkitUtil.getPlayer(p); - Plot plot = area.getPlotAbs(l); + Plot plot = area.getPlotAbs(location); if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD); - e.setCancelled(true); + event.setCancelled(true); } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED); - e.setCancelled(true); + event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) { + if (plot.getFlag(Flags.HANGING_BREAK).or(false)) { return; } if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); - e.setCancelled(true); + event.setCancelled(true); } } - } else if (r instanceof Projectile) { - Projectile p = (Projectile) r; + } else if (remover instanceof Projectile) { + Projectile p = (Projectile) remover; if (p.getShooter() instanceof Player) { Player shooter = (Player) p.getShooter(); - Location loc = BukkitUtil.getLocation(e.getEntity()); - PlotArea area = loc.getPlotArea(); + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } PlotPlayer player = BukkitUtil.getPlayer(shooter); - Plot plot = area.getPlotAbs(BukkitUtil.getLocation(e.getEntity())); + Plot plot = area.getPlotAbs(BukkitUtil.getLocation(event.getEntity())); if (plot != null) { if (!plot.hasOwner()) { if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) { MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED); - e.setCancelled(true); + event.setCancelled(true); } } else if (!plot.isAdded(player.getUUID())) { - if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) { + if (!plot.getFlag(Flags.HANGING_BREAK).or(false)) { if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) { MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); - e.setCancelled(true); + event.setCancelled(true); } } } } } } else { - e.setCancelled(true); + event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { - Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation()); - PlotArea area = l.getPlotArea(); + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + Location location = BukkitUtil.getLocation(event.getRightClicked().getLocation()); + PlotArea area = location.getPlotArea(); if (area == null) { return; } - Player p = e.getPlayer(); + Player p = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(p); - Plot plot = area.getPlotAbs(l); + Plot plot = area.getPlotAbs(location); if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD); - e.setCancelled(true); + event.setCancelled(true); } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED); - e.setCancelled(true); + event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - Entity entity = e.getRightClicked(); - if (entity instanceof Monster && FlagManager.isPlotFlagTrue(plot, C.FLAG_HOSTILE_INTERACT.s())) { + Entity entity = event.getRightClicked(); + if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) { return; } - if (entity instanceof Animals && FlagManager.isPlotFlagTrue(plot, C.FLAG_ANIMAL_INTERACT.s())) { + if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT).or(false)) { return; } - if (entity instanceof Tameable && ((Tameable) entity).isTamed() && FlagManager.isPlotFlagTrue(plot, C.FLAG_TAMED_INTERACT.s())) { + if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot.getFlag(Flags.TAMED_INTERACT).or(false)) { return; } - if (entity instanceof Vehicle && FlagManager.isPlotFlagTrue(plot, C.FLAG_VEHICLE_USE.s())) { + if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE).or(false)) { return; } - if (entity instanceof Player && FlagManager.isPlotFlagTrue(plot, C.FLAG_PLAYER_INTERACT.s())) { + if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT).or(false)) { return; } if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); - e.setCancelled(true); + event.setCancelled(true); } } } @@ -2047,7 +2081,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } if (!plot.isAdded(pp.getUUID())) { - if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) { + if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) { return; } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { @@ -2158,7 +2192,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (player != null) { PlotPlayer pp = BukkitUtil.getPlayer(player); if (victim instanceof Hanging) { // hanging - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hanging-break") || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.HANGING_BREAK).or(false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) { @@ -2166,7 +2200,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim.getEntityId() == 30) { - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "misc-break") || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.MISC_BREAK).or(false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) { @@ -2174,7 +2208,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hostile-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot + if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot .isAdded(pp.getUUID()))) { return true; } @@ -2183,8 +2217,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Tameable) { // victim is tameable - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "tamed-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot - .isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { @@ -2193,12 +2226,14 @@ public class PlayerEvents extends PlotListener implements Listener { } } else if (victim instanceof Player) { if (plot != null) { - Flag pvp = FlagManager.getPlotFlagRaw(plot, C.FLAG_PVP.s()); - if (pvp == null || (Boolean) pvp.getValue()) { + Optional pvp = plot.getFlag(Flags.PVP); + if (pvp.isPresent() && !pvp.get()) { + if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); + return false; + } + } else { return true; - } else if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return false; } } if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) { @@ -2206,7 +2241,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Creature) { // victim is animal - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "animal-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot + if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot .isAdded(pp.getUUID()))) { return true; } @@ -2217,7 +2252,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event return true; } else { // victim is something else - if (plot != null && (FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.PVE).or(false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { @@ -2277,22 +2312,22 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } else if (!plot.isAdded(pp.getUUID())) { - Flag place = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); + Optional> place = plot.getFlag(Flags.PLACE); Block block = event.getBlock(); - if ((place == null || !((HashSet) place.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) - && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + if ((place.isPresent() && !place.get().contains(new PlotBlock((short) block.getTypeId(), block.getData()))) && !Permissions + .hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } - } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) { + } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey(Flags.DONE)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } } - if (FlagManager.isPlotFlagTrue(plot, C.FLAG_DISABLE_PHYSICS.s())) { + if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { Block block = event.getBlockPlaced(); if (block.getType().hasGravity()) { sendBlockChange(block.getLocation(), block.getType(), block.getData()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents183.java index 605f981dc..ae77d6fea 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents183.java @@ -1,7 +1,7 @@ package com.plotsquared.bukkit.listeners; import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -35,7 +35,7 @@ public class PlayerEvents183 implements Listener { return; } Plot plot = area.getOwnedPlot(loc); - if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) { + if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) { event.setCancelled(true); } Iterator iterator = event.blockList().iterator(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java index c2c2ab6b0..6eba7c518 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -1,7 +1,7 @@ package com.plotsquared.bukkit.listeners; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.google.common.base.Optional; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; @@ -88,7 +88,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (plot == null) { return; } - if (FlagManager.isBooleanFlag(plot, "instabreak", false)) { + if (plot.getFlag(Flags.INSTABREAK).or(false)) { event.getBlock().breakNaturally(); } } @@ -103,7 +103,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (plot == null) { return; } - if (FlagManager.isBooleanFlag(plot, "invincible", false)) { + if (plot.getFlag(Flags.INVINCIBLE).or(false)) { event.setCancelled(true); } } @@ -117,7 +117,7 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) { + if (plot.isAdded(uuid) && plot.getFlag(Flags.DROP_PROTECTION).or(false)) { event.setCancelled(true); } } @@ -131,7 +131,7 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) { + if (plot.isAdded(uuid) && plot.getFlag(Flags.ITEM_DROP).or(false)) { event.setCancelled(true); } } @@ -140,14 +140,14 @@ public class PlotPlusListener extends PlotListener implements Listener { public void onPlotEnter(PlayerEnterPlotEvent event) { Player player = event.getPlayer(); Plot plot = event.getPlot(); - Flag feed = FlagManager.getPlotFlagRaw(plot, "feed"); - if (feed != null) { - Integer[] value = (Integer[]) feed.getValue(); + Optional feed = plot.getFlag(Flags.FEED); + if (feed.isPresent()) { + Integer[] value = feed.get(); feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); } - Flag heal = FlagManager.getPlotFlagRaw(plot, "heal"); - if (heal != null) { - Integer[] value = (Integer[]) heal.getValue(); + Optional heal = plot.getFlag(Flags.HEAL); + if (heal.isPresent()) { + Integer[] value = heal.get(); healRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index 5e8c339bc..89e457d2e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -5,7 +5,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class DefaultTitleManager extends TitleManager { @@ -23,18 +22,6 @@ public class DefaultTitleManager extends TitleManager { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } - private static boolean equalsTypeArray(Class[] a, Class[] o) { - if (a.length != o.length) { - return false; - } - for (int i = 0; i < a.length; i++) { - if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) { - return false; - } - } - return true; - } - /** * Load spigot and NMS classes. */ @@ -90,7 +77,8 @@ public class DefaultTitleManager extends TitleManager { * @param player Player * @throws Exception */ - @Override public void clearTitle(Player player) throws Exception { + @Override + public void clearTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -106,7 +94,8 @@ public class DefaultTitleManager extends TitleManager { * @param player Player * @throws Exception */ - @Override public void resetTitle(Player player) throws Exception { + @Override + public void resetTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -116,27 +105,7 @@ public class DefaultTitleManager extends TitleManager { sendPacket.invoke(connection, packet); } - private Object getHandle(Object obj) { - try { - return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } - - private Method getMethod(String name, Class clazz, Class... paramTypes) { - Class[] t = toPrimitiveTypeArray(paramTypes); - for (Method m : clazz.getMethods()) { - Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); - if (m.getName().equals(name) && equalsTypeArray(types, t)) { - return m; - } - } - return null; - } - - private Field getField(Class clazz, String name) { + Field getField(Class clazz, String name) { try { Field field = clazz.getDeclaredField(name); field.setAccessible(true); @@ -157,7 +126,7 @@ public class DefaultTitleManager extends TitleManager { return null; } - private boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean ClassListEqual(Class[] l1, Class[] l2) { if (l1.length != l2.length) { return false; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java index 609d10fd4..cfa480f87 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java @@ -4,10 +4,9 @@ import com.plotsquared.bukkit.chat.Reflection; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import java.lang.reflect.Field; import java.lang.reflect.Method; -public class DefaultTitleManager_183 extends TitleManager { +public class DefaultTitleManager_183 extends DefaultTitleManager { /** * Create a new 1.8 title. @@ -22,18 +21,6 @@ public class DefaultTitleManager_183 extends TitleManager { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } - private static boolean equalsTypeArray(Class[] a, Class[] o) { - if (a.length != o.length) { - return false; - } - for (int i = 0; i < a.length; i++) { - if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) { - return false; - } - } - return true; - } - /** * Load spigot and NMS classes. */ @@ -82,71 +69,6 @@ public class DefaultTitleManager_183 extends TitleManager { } } - /** - * Clear the title. - * - * @param player Player - * @throws Exception - */ - @Override - public void clearTitle(Player player) throws Exception { - // Send timings first - Object handle = getHandle(player); - Object connection = getField(handle.getClass(), "playerConnection").get(handle); - Object[] actions = this.packetActions.getEnumConstants(); - Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null); - sendPacket.invoke(connection, packet); - } - - /** - * Reset the title settings. - * - * @param player Player - * @throws Exception - */ - @Override - public void resetTitle(Player player) throws Exception { - // Send timings first - Object handle = getHandle(player); - Object connection = getField(handle.getClass(), "playerConnection").get(handle); - Object[] actions = this.packetActions.getEnumConstants(); - Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null); - sendPacket.invoke(connection, packet); - } - - private Object getHandle(Object obj) { - try { - return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - private Method getMethod(String name, Class clazz, Class... paramTypes) { - Class[] t = toPrimitiveTypeArray(paramTypes); - for (Method m : clazz.getMethods()) { - Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); - if (m.getName().equals(name) && equalsTypeArray(types, t)) { - return m; - } - } - return null; - } - - private Field getField(Class clazz, String name) { - try { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException | SecurityException e) { - e.printStackTrace(); - return null; - } - } - private Method getMethod(Class clazz, String name, Class... args) { for (Method m : clazz.getMethods()) { if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) { @@ -157,17 +79,4 @@ public class DefaultTitleManager_183 extends TitleManager { return null; } - private boolean ClassListEqual(Class[] l1, Class[] l2) { - if (l1.length != l2.length) { - return false; - } - boolean equal = true; - for (int i = 0; i < l1.length; i++) { - if (l1[i] != l2[i]) { - equal = false; - break; - } - } - return equal; - } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index 933af3229..11dc5fefb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -6,7 +6,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class HackTitleManager extends TitleManager { @@ -24,18 +23,6 @@ public class HackTitleManager extends TitleManager { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } - private static boolean equalsTypeArray(Class[] a, Class[] o) { - if (a.length != o.length) { - return false; - } - for (int i = 0; i < a.length; i++) { - if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) { - return false; - } - } - return true; - } - /** * Load spigot and NMS classes. */ @@ -171,26 +158,6 @@ public class HackTitleManager extends TitleManager { return f.get(obj); } - private Object getHandle(Object obj) { - try { - return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } - - private Method getMethod(String name, Class clazz, Class... paramTypes) { - Class[] t = toPrimitiveTypeArray(paramTypes); - for (Method m : clazz.getMethods()) { - Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); - if (m.getName().equals(name) && equalsTypeArray(types, t)) { - return m; - } - } - return null; - } - private Field getField(Class clazz, String name) { try { Field field = clazz.getDeclaredField(name); @@ -225,4 +192,5 @@ public class HackTitleManager extends TitleManager { } return equal; } + } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java index bd2e0ee84..c457beb2b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java @@ -4,6 +4,8 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -201,4 +203,36 @@ public abstract class TitleManager { return types; } + final Object getHandle(Object obj) { + try { + return getMethod("getHandle", obj.getClass()).invoke(obj); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } + + final Method getMethod(String name, Class clazz, Class... paramTypes) { + Class[] t = toPrimitiveTypeArray(paramTypes); + for (Method m : clazz.getMethods()) { + Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); + if (m.getName().equals(name) && equalsTypeArray(types, t)) { + return m; + } + } + return null; + } + + final boolean equalsTypeArray(Class[] a, Class[] o) { + if (a.length != o.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) { + return false; + } + } + return true; + } + } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java index f9bcb4b17..7673dcf21 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java @@ -20,41 +20,41 @@ public class BukkitChatManager extends ChatManager { } @Override - public void color(PlotMessage m, String color) { - m.$(this).color(ChatColor.getByChar(C.color(color).substring(1))); + public void color(PlotMessage message, String color) { + message.$(this).color(ChatColor.getByChar(C.color(color).substring(1))); } @Override - public void tooltip(PlotMessage m, PlotMessage... tooltips) { + public void tooltip(PlotMessage message, PlotMessage... tooltips) { List lines = new ArrayList<>(); for (PlotMessage tooltip : tooltips) { lines.add(tooltip.$(this)); } - m.$(this).formattedTooltip(lines); + message.$(this).formattedTooltip(lines); } @Override - public void command(PlotMessage m, String command) { - m.$(this).command(command); + public void command(PlotMessage message, String command) { + message.$(this).command(command); } @Override - public void text(PlotMessage m, String text) { - m.$(this).then(ChatColor.stripColor(text)); + public void text(PlotMessage message, String text) { + message.$(this).then(ChatColor.stripColor(text)); } @Override - public void send(PlotMessage m, PlotPlayer player) { + public void send(PlotMessage plotMessage, PlotPlayer player) { if (player instanceof ConsolePlayer) { - player.sendMessage(m.$(this).toOldMessageFormat()); + player.sendMessage(plotMessage.$(this).toOldMessageFormat()); } else { - m.$(this).send(((BukkitPlayer) player).player); + plotMessage.$(this).send(((BukkitPlayer) player).player); } } @Override - public void suggest(PlotMessage m, String command) { - m.$(this).suggest(command); + public void suggest(PlotMessage plotMessage, String command) { + plotMessage.$(this).suggest(command); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java index bfcd5c9af..eaf3c0e17 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java @@ -73,7 +73,7 @@ public class BukkitEventUtil extends EventUtil { } @Override - public boolean callFlagRemove(Flag flag, Plot plot) { + public boolean callFlagRemove(Flag flag, Plot plot, Object value) { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } @@ -113,7 +113,7 @@ public class BukkitEventUtil extends EventUtil { } @Override - public boolean callFlagRemove(Flag flag, PlotCluster cluster) { + public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) { return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java index e01adf8b3..a0cd0d70a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java @@ -16,35 +16,35 @@ public class BukkitPlainChatManager extends ChatManager> { } @Override - public void color(PlotMessage m, String color) { - List parts = m.$(this); + public void color(PlotMessage message, String color) { + List parts = message.$(this); parts.get(parts.size() - 1).insert(0, color); } @Override - public void tooltip(PlotMessage m, PlotMessage... tooltips) { + public void tooltip(PlotMessage message, PlotMessage... tooltips) { } @Override - public void command(PlotMessage m, String command) { + public void command(PlotMessage message, String command) { } @Override - public void text(PlotMessage m, String text) { - m.$(this).add(new StringBuilder(ChatColor.stripColor(text))); + public void text(PlotMessage message, String text) { + message.$(this).add(new StringBuilder(ChatColor.stripColor(text))); } @Override - public void send(PlotMessage m, PlotPlayer player) { + public void send(PlotMessage plotMessage, PlotPlayer player) { StringBuilder built = new StringBuilder(); - for (StringBuilder sb : m.$(this)) { + for (StringBuilder sb : plotMessage.$(this)) { built.append(sb); } player.sendMessage(built.toString()); } @Override - public void suggest(PlotMessage m, String command) { + public void suggest(PlotMessage plotMessage, String command) { } } diff --git a/Core/build.gradle b/Core/build.gradle index fbd344d1b..a559e4c91 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -7,5 +7,5 @@ dependencies { sourceCompatibility = 1.7 targetCompatibility = 1.7 -jar.archiveName="PlotSquared-API-${parent.version}.jar" +jar.archiveName = "PlotSquared-Core-${parent.version}.jar" jar.destinationDir = file '../target' \ No newline at end of file diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index c7c6a5722..e7168c118 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1830,8 +1830,8 @@ public class PS { for (String flag : intFlags) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); } - FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()), true); - FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()), true); + FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue())); + FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue())); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); @@ -1858,6 +1858,10 @@ public class PS { FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue())); FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue())); FlagManager.addFlag(new AbstractFlag("ice-melt", new FlagValue.BooleanValue())); + FlagManager.addFlag(new AbstractFlag("soil-dry", new FlagValue.BooleanValue())); + FlagManager.addFlag(new AbstractFlag("grass-grow", new FlagValue.BooleanValue())); + FlagManager.addFlag(new AbstractFlag("mycel-grow", new FlagValue.BooleanValue())); + FlagManager.addFlag(new AbstractFlag("vine-grow", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("block-ignition", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("block-burn", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fire-spread", new FlagValue.BooleanValue())); @@ -1878,10 +1882,6 @@ public class PS { } } - @Override - public String getValueDesc() { - return "Flag value must a timestamp or a boolean"; - } }); FlagManager.addFlag(new AbstractFlag("gamemode") { @@ -1908,10 +1908,6 @@ public class PS { } } - @Override - public String getValueDesc() { - return "Flag value must be a gamemode: 'creative' , 'survival', 'adventure' or 'spectator'"; - } }); FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue())); FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue())); @@ -1935,12 +1931,8 @@ public class PS { } } - @Override - public String getValueDesc() { - return "Flag value must be weather type: 'clear' or 'rain'"; - } }); - FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue()), true); + FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue())); } /** diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index fb9c9a0f8..8f603528d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -1,9 +1,9 @@ package com.intellectualcrafters.plot.commands; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; + import java.util.Set; @CommandDeclaration( @@ -59,14 +60,14 @@ public class Buy extends SubCommand { if (currentPlots > plr.getAllowedPlots()) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } - Flag flag = FlagManager.getPlotFlagRaw(plot, "price"); - if (flag == null) { + Optional flag = plot.getFlag(Flags.PRICE); + if (!flag.isPresent()) { return sendMessage(plr, C.NOT_FOR_SALE); } if (plot.isOwner(plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); } - double price = (double) flag.getValue(); + double price = flag.get(); if ((EconHandler.manager != null) && (price > 0d)) { if (EconHandler.manager.getMoney(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); @@ -78,7 +79,7 @@ public class Buy extends SubCommand { if (owner != null) { sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + ""); } - FlagManager.removePlotFlag(plot, "price"); + plot.removeFlag(Flags.PRICE); } plot.setOwner(plr.getUUID()); MainUtil.sendMessage(plr, C.CLAIMED); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 712d53fa1..a7ee49994 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -62,7 +63,7 @@ public class Clear extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - if ((FlagManager.getPlotFlagRaw(plot, "done") != null) + if (plot.getFlag(Flags.DONE).isPresent() && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr .getPlotCount())))) { MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); @@ -81,11 +82,11 @@ public class Clear extends SubCommand { public void run() { plot.removeRunning(); // If the state changes, then mark it as no longer done - if (FlagManager.getPlotFlagRaw(plot, "done") != null) { - FlagManager.removePlotFlag(plot, "done"); + if (plot.getFlag(Flags.DONE).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.DONE); } - if (FlagManager.getPlotFlagRaw(plot, "analysis") != null) { - FlagManager.removePlotFlag(plot, "analysis"); + if (plot.getFlag(Flags.ANALYSIS).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.ANALYSIS); } MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start)); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java index 103ec9962..dfb3a1060 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java @@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; @@ -40,7 +40,7 @@ public class Continue extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - FlagManager.removePlotFlag(plot, "done"); + plot.removeFlag(Flags.DONE); MainUtil.sendMessage(plr, C.DONE_REMOVED); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index dbb964df5..036c4e1e2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.ConsolePlayer; @@ -211,8 +212,9 @@ public class DebugExec extends SubCommand { } String flag = args[1]; for (Plot plot : PS.get().getBasePlots()) { - if (FlagManager.getPlotFlagRaw(plot, flag) != null) { - FlagManager.removePlotFlag(plot, flag); + Flag flag1 = FlagManager.getFlag(flag); + if (plot.getFlag(flag1).isPresent()) { + FlagManager.removePlotFlag(plot, flag1); } } return MainUtil.sendMessage(player, "Cleared flag: " + flag); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java index 69b17cebf..3f7289560 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java @@ -4,7 +4,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -39,17 +38,19 @@ public class DebugFixFlags extends SubCommand { } MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---"); for (Plot plot : area.getPlots()) { - HashMap flags = plot.getFlags(); - Iterator> i = flags.entrySet().iterator(); + HashMap, Object> flags = plot.getFlags(); + Iterator, Object>> i = flags.entrySet().iterator(); boolean changed = false; while (i.hasNext()) { +/* if (FlagManager.getFlag(i.next().getKey()) == null) { changed = true; i.remove(); } +*/ } if (changed) { - DBFunc.setFlags(plot, plot.getFlags().values()); + DBFunc.setFlags(plot, plot.getFlags()); } } MainUtil.sendMessage(plr, "&aDone!"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Desc.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Desc.java index e349183cb..d85c7555d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Desc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Desc.java @@ -1,8 +1,8 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; @@ -21,12 +21,11 @@ public class Desc extends SetCommand { @Override public boolean set(PlotPlayer plr, Plot plot, String desc) { if (desc.isEmpty()) { - plot.removeFlag("description"); + plot.removeFlag(Flags.DESCRIPTION); MainUtil.sendMessage(plr, C.DESC_UNSET); return true; } - Flag flag = new Flag(FlagManager.getFlag("description"), desc); - boolean result = FlagManager.addPlotFlag(plot, flag); + boolean result = FlagManager.addPlotFlag(plot, Flags.DESCRIPTION, desc); if (!result) { MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED); return false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java index 231276d33..d6354ee03 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -48,8 +49,9 @@ public class Done extends SubCommand { public void run(PlotAnalysis value) { plot.removeRunning(); if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { - Flag flag = new Flag(FlagManager.getFlag("done"), System.currentTimeMillis() / 1000); - FlagManager.addPlotFlag(plot, flag); + long flagValue = System.currentTimeMillis() / 1000; + Flag flag = Flags.DONE; + FlagManager.addPlotFlag(plot, flag, flagValue); MainUtil.sendMessage(plr, C.DONE_SUCCESS); } else { MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java index 63430a100..064d03799 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -4,7 +4,7 @@ import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; @@ -41,11 +41,8 @@ public class Download extends SubCommand { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } - if ((Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlagRaw(plot, "done") == null)) && !Permissions.hasPermission(plr, "plots.admin.command.download")) { - MainUtil.sendMessage(plr, C.DONE_NOT_DONE); - return false; - } - if ((!plot.isOwner(plr.getUUID()))) { + if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && plot.getFlag(Flags.DONE).isPresent())) && !Permissions + .hasPermission(plr, "plots.admin.command.download")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index de2109dab..3a05497ef 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -1,11 +1,12 @@ package com.intellectualcrafters.plot.commands; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.flag.FlagValue; +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.flag.ListFlag; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -16,6 +17,7 @@ import com.plotsquared.general.commands.CommandDeclaration; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -31,7 +33,7 @@ public class FlagCmd extends SubCommand { @Override public String getUsage() { - return super.getUsage().replaceAll("", StringMan.join(FlagManager.getFlags(), "|")); + return super.getUsage().replaceAll("", StringMan.join(Flags.getFlags(), "|")); } @Override @@ -62,7 +64,7 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other"); return false; } - if (args.length > 1 && FlagManager.isReserved(args[1])) { + if (args.length > 1 && FlagManager.isReserved(FlagManager.getFlag(args[1]))) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } @@ -76,18 +78,18 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info "); return false; } - AbstractFlag flag = FlagManager.getFlag(args[1]); + Flag flag = FlagManager.getFlag(args[1]); if (flag == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info "); return false; } // flag key - MainUtil.sendMessage(player, C.FLAG_KEY, flag.getKey()); + MainUtil.sendMessage(player, C.FLAG_KEY, flag.getName()); // flag type - MainUtil.sendMessage(player, C.FLAG_TYPE, flag.value.getClass().getSimpleName()); + MainUtil.sendMessage(player, C.FLAG_TYPE, flag.getClass().getSimpleName()); // Flag type description - MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDesc()); + MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDescription()); return true; } case "set": { @@ -99,7 +101,7 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set "); return false; } - AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); + Flag af = FlagManager.getFlag(args[1].toLowerCase()); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; @@ -109,13 +111,12 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase()); return false; } - Object parsed = af.parseValueRaw(value); + Object parsed = af.parseValue(value); if (parsed == null) { - MainUtil.sendMessage(player, "&c" + af.getValueDesc()); + MainUtil.sendMessage(player, "&c" + af.getValueDescription()); return false; } - Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); - boolean result = FlagManager.addPlotFlag(plot, flag); + boolean result = plot.setFlag(af, parsed); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); return false; @@ -124,42 +125,42 @@ public class FlagCmd extends SubCommand { return true; } case "remove": { - if (!Permissions.hasPermission(player, "plots.flag.remove")) { - MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove"); + if (!Permissions.hasPermission(player, "plots.flagValue.remove")) { + MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flagValue.remove"); return false; } if (args.length != 2 && args.length != 3) { - MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove [values]"); + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flagValue remove [values]"); return false; } - AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); - if (af == null) { + Flag flag1 = FlagManager.getFlag(args[1].toLowerCase()); + if (flag1 == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } - Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()); - if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { + Optional flagValue = plot.getFlag(flag1); + if (!Permissions.hasPermission(player, "plots.set.flagValue." + args[1].toLowerCase())) { if (args.length != 2) { - MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); + MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flagValue." + args[1].toLowerCase()); return false; } for (String entry : args[2].split(",")) { - if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) { - MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry); + if (!Permissions.hasPermission(player, "plots.set.flagValue." + args[1].toLowerCase() + "." + entry)) { + MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flagValue." + args[1].toLowerCase() + "." + entry); return false; } } } - if (flag == null) { + if (flagValue.isPresent()) { MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT); return false; } - if (args.length == 3 && flag.getAbstractFlag().isList()) { + if (args.length == 3 && flag1 instanceof ListFlag) { String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - ((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value); - DBFunc.setFlags(plot, plot.getFlags().values()); + boolean listFlag = ((Collection) plot.getFlags().get(flag1)).remove(flag1.parseValue(value)); + DBFunc.setFlags(plot, plot.getFlags()); } else { - boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); + boolean result = plot.removeFlag(flag1); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED); return false; @@ -177,7 +178,7 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add "); return false; } - AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); + Flag af = FlagManager.getFlag(args[1].toLowerCase()); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; @@ -189,18 +190,18 @@ public class FlagCmd extends SubCommand { } } String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - Object parsed = af.parseValueRaw(value); + Object parsed = af.parseValue(value); if (parsed == null) { - MainUtil.sendMessage(player, "&c" + af.getValueDesc()); + MainUtil.sendMessage(player, "&c" + af.getValueDescription()); return false; } - Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase()); - if (flag == null || !flag.getAbstractFlag().isList()) { - flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); - } else { - ((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value); + Optional flag = plot.getFlag(af); + if (flag.isPresent()) { + if (af instanceof ListFlag) { + ((Collection) flag.get()).addAll((Collection) parsed); + } } - boolean result = FlagManager.addPlotFlag(plot, flag); + boolean result = FlagManager.addPlotFlag(plot, af, parsed); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); return false; @@ -217,12 +218,12 @@ public class FlagCmd extends SubCommand { return false; } HashMap> flags = new HashMap<>(); - for (AbstractFlag flag1 : FlagManager.getFlags()) { - String type = flag1.value.getClass().getSimpleName().replaceAll("Value", ""); + for (Flag flag1 : Flags.getFlags()) { + String type = flag1.getClass().getSimpleName().replaceAll("Value", ""); if (!flags.containsKey(type)) { flags.put(type, new ArrayList()); } - flags.get(type).add(flag1.getKey()); + //todo flags.get(type).add(flag1.getKey()); } String message = ""; String prefix = ""; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java index 6d2d307e3..e26d7581a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java @@ -1,10 +1,10 @@ package com.intellectualcrafters.plot.commands; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotMessage; @@ -176,8 +176,8 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PS.get().getPlots()) { - Flag flag = plot.getFlags().get("done"); - if (flag == null) { + Optional flag = plot.getFlag(Flags.DONE); + if (!flag.isPresent()) { continue; } plots.add(plot); @@ -185,8 +185,8 @@ public class ListCmd extends SubCommand { Collections.sort(plots, new Comparator() { @Override public int compare(Plot a, Plot b) { - String va = a.getFlags().get("done").getValueString(); - String vb = b.getFlags().get("done").getValueString(); + String va = (String) a.getFlags().get(Flags.DONE); + String vb = (String) b.getFlags().get(Flags.DONE); if (MathMan.isInteger(va)) { if (MathMan.isInteger(vb)) { return Integer.parseInt(vb) - Integer.parseInt(va); @@ -245,10 +245,12 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PS.get().getPlots()) { +/* Flag price = FlagManager.getPlotFlagRaw(plot, "price"); if (price != null) { plots.add(plot); } +*/ } break; case "unowned": diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Music.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Music.java index d269e77f3..76bdea67e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Music.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Music.java @@ -1,8 +1,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; @@ -41,9 +40,9 @@ public class Music extends SubCommand { } int id = item.id == 7 ? 0 : item.id; if (id == 0) { - FlagManager.removePlotFlag(plot, "music"); + plot.removeFlag(Flags.MUSIC); } else { - FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); + plot.setFlag(Flags.MUSIC, id); } return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java index d870f98cf..c89446d39 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -3,7 +3,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.flag.AbstractFlag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; @@ -166,7 +166,7 @@ public class Set extends SubCommand { } catch (Exception e) { af = new AbstractFlag(""); } - if (FlagManager.getFlags().contains(af)) { + if (Flags.getFlags().contains(af)) { StringBuilder a = new StringBuilder(); if (args.length > 1) { for (int x = 1; x < args.length; x++) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 9aaf2e693..bc27bf59e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -9,7 +9,6 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -139,10 +138,10 @@ public interface AbstractDB { /** * Set plot flags. - * @param plot Plot Object + * @param plot Plot Object * @param flags flags to set (flag[]) */ - void setFlags(Plot plot, Collection flags); + void setFlags(Plot plot, HashMap, Object> flags); /** * Set cluster flags. @@ -150,7 +149,7 @@ public interface AbstractDB { * @param cluster PlotCluster Object * @param flags flags to set (flag[]) */ - void setFlags(PlotCluster cluster, Collection flags); + void setFlags(PlotCluster cluster, HashMap, Object> flags); /** * Rename a cluster. diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 7461a9330..473cd6c46 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -12,7 +12,6 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -244,14 +243,14 @@ public class DBFunc { DBFunc.dbManager.setMerged(plot, merged); } - public static void setFlags(Plot plot, Collection flags) { + public static void setFlags(Plot plot, HashMap, Object> flags) { if (plot.temp == -1) { return; } DBFunc.dbManager.setFlags(plot, flags); } - public static void setFlags(PlotCluster cluster, Collection flags) { + public static void setFlags(PlotCluster cluster, HashMap, Object> flags) { DBFunc.dbManager.setFlags(cluster, flags); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index d30162440..bf4b46c05 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -25,7 +25,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -790,31 +789,32 @@ public class SQLManager implements AbstractDB { } @Override - public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { - stmt.setInt(i * 10 + 1, pair.id); // id - stmt.setNull(i * 10 + 2, 4); // biome - stmt.setNull(i * 10 + 3, 4); // rain - stmt.setNull(i * 10 + 4, 4); // custom_time - stmt.setNull(i * 10 + 5, 4); // time - stmt.setNull(i * 10 + 6, 4); // deny_entry + public void setMySQL(PreparedStatement statement, int i, SettingsPair pair) throws SQLException { + statement.setInt(i * 10 + 1, pair.id); // id + statement.setNull(i * 10 + 2, 4); // biome + statement.setNull(i * 10 + 3, 4); // rain + statement.setNull(i * 10 + 4, 4); // custom_time + statement.setNull(i * 10 + 5, 4); // time + statement.setNull(i * 10 + 6, 4); // deny_entry if (pair.settings.getAlias().isEmpty()) { - stmt.setNull(i * 10 + 7, 4); + statement.setNull(i * 10 + 7, 4); } else { - stmt.setString(i * 10 + 7, pair.settings.getAlias()); + statement.setString(i * 10 + 7, pair.settings.getAlias()); } StringBuilder flag_string = new StringBuilder(); int k = 0; - for (Flag flag : pair.settings.flags.values()) { + for (Entry, ?> flag : pair.settings.flags.entrySet()) { if (k != 0) { flag_string.append(","); } - flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") + .replaceAll(",", "´")); k++; } - stmt.setString(i * 10 + 8, flag_string.toString()); + statement.setString(i * 10 + 8, flag_string.toString()); boolean[] merged = pair.settings.getMerged(); int hash = MainUtil.hash(merged); - stmt.setInt(i * 10 + 9, hash); + statement.setInt(i * 10 + 9, hash); BlockLoc loc = pair.settings.getPosition(); String position; if (loc.y == 0) { @@ -822,7 +822,7 @@ public class SQLManager implements AbstractDB { } else { position = loc.x + "," + loc.y + "," + loc.z; } - stmt.setString(i * 10 + 10, position); + statement.setString(i * 10 + 10, position); } @Override @@ -840,11 +840,12 @@ public class SQLManager implements AbstractDB { } StringBuilder flag_string = new StringBuilder(); int k = 0; - for (Flag flag : pair.settings.flags.values()) { + for (Entry, ?> flag : pair.settings.flags.entrySet()) { if (k != 0) { flag_string.append(","); } - flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") + .replaceAll(",", "´")); k++; } stmt.setString(i * 10 + 8, flag_string.toString()); @@ -1784,18 +1785,18 @@ public class SQLManager implements AbstractDB { deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); } - try (ResultSet r = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { + try (ResultSet resultSet = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { ArrayList toDelete = new ArrayList<>(); - while (r.next()) { - id = r.getInt("plot_plot_id"); + while (resultSet.next()) { + id = resultSet.getInt("plot_plot_id"); Plot plot = plots.get(id); if (plot != null) { plots.remove(id); - String alias = r.getString("alias"); + String alias = resultSet.getString("alias"); if (alias != null) { plot.getSettings().setAlias(alias); } - String pos = r.getString("position"); + String pos = resultSet.getString("position"); switch (pos.toLowerCase()) { case "": case "default": @@ -1808,14 +1809,14 @@ public class SQLManager implements AbstractDB { } catch (Exception ignored) { } } - Integer m = r.getInt("merged"); + Integer m = resultSet.getInt("merged"); boolean[] merged = new boolean[4]; for (int i = 0; i < 4; i++) { merged[3 - i] = (m & 1 << i) != 0; } plot.getSettings().setMerged(merged); String[] flags_string; - String myflags = r.getString("flags"); + String myflags = resultSet.getString("flags"); if (myflags == null) { flags_string = new String[] {}; } else { @@ -1825,15 +1826,15 @@ public class SQLManager implements AbstractDB { flags_string = new String[] {}; } } - HashMap flags = new HashMap<>(); + HashMap, Object> flags = new HashMap<>(); boolean exception = false; for (String element : flags_string) { if (element.contains(":")) { String[] split = element.split(":"); try { String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str); - flags.put(flag.getKey(), flag); + Flag flag = FlagManager.getFlag(split[0]); + flags.put(flag, flag_str); } catch (Exception e) { e.printStackTrace(); exception = true; @@ -1841,8 +1842,8 @@ public class SQLManager implements AbstractDB { } else { element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - Flag flag = new Flag(FlagManager.getFlag(element, true), ""); - flags.put(flag.getKey(), flag); + Flag flag = FlagManager.getFlag(element); + flags.put(flag, ""); } else { PS.debug("INVALID FLAG: " + element); } @@ -1851,7 +1852,7 @@ public class SQLManager implements AbstractDB { if (exception) { PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted."); PS.debug("&c" + myflags); - this.setFlags(plot, flags.values()); + this.setFlags(plot, flags); } plot.getSettings().flags = flags; } else if (Settings.AUTO_PURGE) { @@ -1962,8 +1963,8 @@ public class SQLManager implements AbstractDB { } @Override - public void setFlags(final Plot plot, Collection flags) { - final String flag_string = FlagManager.toString(flags); + public void setFlags(final Plot plot, HashMap, Object> flags) { + final String flag_string = FlagManager.toString(flags); //todo MattBDev: Fix this for flags to work. addPlotTask(plot, new UniqueStatement("setFlags") { @Override public void set(PreparedStatement stmt) throws SQLException { @@ -2641,22 +2642,22 @@ public class SQLManager implements AbstractDB { flags_string = new String[] {}; } } - HashMap flags = new HashMap<>(); + HashMap, Object> flags = new HashMap<>(); boolean exception = false; for (String element : flags_string) { if (element.contains(":")) { String[] split = element.split(":"); try { String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); - Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str); - flags.put(flag.getKey(), flag); + Flag flag = FlagManager.getFlag(split[0]); + flags.put(flag, flag_str); } catch (Exception e) { e.printStackTrace(); exception = true; } } else { - Flag flag = new Flag(FlagManager.getFlag(element, true), ""); - flags.put(flag.getKey(), flag); + Flag flag = FlagManager.getFlag(element); + flags.put(flag, ""); } } if (exception) { @@ -2687,14 +2688,15 @@ public class SQLManager implements AbstractDB { } @Override - public void setFlags(final PlotCluster cluster, Collection flags) { + public void setFlags(final PlotCluster cluster, HashMap, Object> flags) { final StringBuilder flag_string = new StringBuilder(); int i = 0; - for (Flag flag : flags) { + for (Entry, Object> flag : flags.entrySet()) { if (i != 0) { flag_string.append(","); } - flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",", + "´")); i++; } addClusterTask(cluster, new UniqueStatement("setFlags") { @@ -3019,12 +3021,12 @@ public class SQLManager implements AbstractDB { PS.debug("&8 - &7Correcting merge for: " + plot); setMerged(dataPlot, plot.getMerged()); } - HashMap pf = plot.getFlags(); - HashMap df = dataPlot.getFlags(); + HashMap, Object> pf = plot.getFlags(); + HashMap, Object> df = dataPlot.getFlags(); if (!pf.isEmpty() && !df.isEmpty()) { if (pf.size() != df.size() || !StringMan.isEqual(StringMan.joinOrdered(pf.values(), ","), StringMan.joinOrdered(df.values(), ","))) { PS.debug("&8 - &7Correcting flags for: " + plot); - setFlags(plot, pf.values()); + setFlags(plot, pf); } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index d220f5fe9..0b99a974d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -1,16 +1,14 @@ package com.intellectualcrafters.plot.flag; -import com.intellectualcrafters.plot.util.StringMan; - /** * Created 2014-09-23 for PlotSquared * */ -public class AbstractFlag { +public class AbstractFlag { public final String key; - public final FlagValue value; + public final T value = null; public AbstractFlag(String key) { this(key, new FlagValue.StringValue()); @@ -22,18 +20,12 @@ public class AbstractFlag { * @param key */ public AbstractFlag(String key, FlagValue value) { - if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) { - throw new IllegalArgumentException("Flag must be alphabetic characters"); - } - if (key.length() > 16) { - throw new IllegalArgumentException("Key must be <= 16 characters"); - } this.key = key.toLowerCase(); - if (value == null) { - this.value = new FlagValue.StringValue(); - } else { - this.value = value; - } + //if (value == null) { + // this.value = new FlagValue.StringValue(); + //} else { + // this.value = value; + //} } public boolean isList() { @@ -51,11 +43,7 @@ public class AbstractFlag { public String toString(Object t) { return this.value.toString(t); } - - public String getValueDesc() { - return this.value.getDescription(); - } - + /** * AbstractFlag key * diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java index a8e36a013..0fb5c7919 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java @@ -5,4 +5,33 @@ public class BooleanFlag extends Flag { public BooleanFlag(String name) { super(name); } + + @Override public String valueToString(Object value) { + if (((boolean) value)) { + return "true"; + } else { + return "false"; + } + } + + @Override public Boolean parseValue(String value) { + switch (value.toLowerCase()) { + case "1": + case "yes": + case "allow": + case "true": + return true; + case "0": + case "no": + case "deny": + case "false": + return false; + default: + return null; + } + } + + @Override public String getValueDescription() { + return "Flag value must be a boolean (true|false)"; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index f01694bdd..659e918db 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -1,14 +1,8 @@ package com.intellectualcrafters.plot.flag; -import com.intellectualcrafters.plot.util.StringMan; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class Flag implements Cloneable { +public class Flag { private AbstractFlag key; - private Object value; private String name; /** @@ -16,35 +10,8 @@ public class Flag implements Cloneable { * key/value pair. For a flag to be usable by a player, you need to * register it with PlotSquared. * - * @param key AbstractFlag - * @param value Value must be alphanumerical (can have spaces) and be <= 48 characters - * - * @throws IllegalArgumentException if you provide inadequate inputs + * @param name Flag name */ - public Flag(AbstractFlag key, String value) { - if (!StringMan.isAsciiPrintable(value)) { - throw new IllegalArgumentException("Flag must be ascii"); - } - if (value.length() > 128) { - throw new IllegalArgumentException("Value must be <= 128 characters"); - } - this.key = key; - this.value = key.parseValueRaw(value); - if (this.value == null) { - throw new IllegalArgumentException(key.getValueDesc() + " (" + value + ")"); - } - } - - /** - * Warning: Unchecked - * @param key - * @param value - */ - public Flag(AbstractFlag key, Object value) { - this.key = key; - this.value = value; - } - public Flag(String name) { this.name = name; } @@ -58,82 +25,25 @@ public class Flag implements Cloneable { return this.key; } - /** - * Get the key for the AbstractFlag. - * - * @return String - */ - public String getKey() { - return this.key.getKey(); - } - - public void setKey(AbstractFlag key) { - this.key = key; - if (this.value instanceof String) { - this.value = key.parseValueRaw((String) this.value); - } - } - - /** - * Get the value. - * - * @return String - */ - public Object getValue() { - return this.value; - } - public String getValueString() { - return this.key.toString(this.value); + return this.key.toString(this.name); + } + + public String valueToString(Object value) { + return null; } @Override public String toString() { - if ("".equals(this.value)) { - return this.key.getKey(); - } - return this.key + ":" + getValueString(); + return "Flag { name='" + getName() + "'}"; } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Flag other = (Flag) obj; - return this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value); + public V parseValue(String value) { + return null; } - @Override - public int hashCode() { - return this.key.getKey().hashCode(); - } - - @Override - protected Object clone() { - try { - if (this.value == null) { - return super.clone(); - } - if (this.value instanceof Cloneable) { - Method method = this.value.getClass().getDeclaredMethod("clone"); - if (!method.isAccessible()) { - method.setAccessible(true); - } - return new Flag(this.key, method.invoke(this.value)); - } - return new Flag(this.key, this.key.parseValueRaw(this.key.toString(this.value))); - } catch (CloneNotSupportedException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | - InvocationTargetException e) { - e.printStackTrace(); - } - return this; + public String getValueDescription() { + return null; } public String getName() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 3be530cc4..1f22fe0a3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -1,19 +1,16 @@ package com.intellectualcrafters.plot.flag; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; +import com.google.common.collect.Sets; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotSettings; -import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.Permissions; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -26,20 +23,16 @@ import java.util.Set; */ public class FlagManager { - //TODO Default Flags - public static final IntegerFlag MUSIC = new IntegerFlag("music"); - - private static final HashSet reserved = new HashSet<>(); - - private static final HashSet flags = new HashSet<>(); + private static final HashSet> + reserved = Sets.newHashSet();//todo MattBDev: Ask Empire what a reserved flag is /** * Reserve a flag so that it cannot be set by players * @param flag */ public static void reserveFlag(String flag) { - reserved.add(flag); + //reserved.add(flag); } /** @@ -47,7 +40,7 @@ public class FlagManager { * @param flag * @return */ - public static boolean isReserved(String flag) { + public static boolean isReserved(Flag flag) { return reserved.contains(flag); } @@ -55,8 +48,8 @@ public class FlagManager { * Get the reserved flags * @return */ - public static HashSet getReservedFlags() { - return (HashSet) reserved.clone(); + public static HashSet> getReservedFlags() { + return (HashSet>) reserved.clone(); } /** @@ -75,87 +68,37 @@ public class FlagManager { * @return boolean success */ public static boolean addFlag(AbstractFlag af) { - return addFlag(af, false); + //todo MattBDev: Remove this + return true; + //return addFlag(af, false); } - public static boolean addFlag(final AbstractFlag af, boolean reserved) { - PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af); - PS.get().foreachPlotArea(new RunnableVal() { - @Override - public void run(PlotArea value) { - Flag flag = value.DEFAULT_FLAGS.get(af.getKey()); - if (flag != null) { - flag.setKey(af); - } - } - }); - PS.get().foreachPlotRaw(new RunnableVal() { - @Override - public void run(Plot value) { - Flag flag = value.getFlags().get(af.getKey()); - if (flag != null) { - flag.setKey(af); - } - } - }); - if (flags.remove(af)) { - PS.debug("(Replaced existing flag)"); - } - flags.add(af); - if (reserved) { - reserveFlag(af.getKey()); - } - return false; - } - - public static String toString(Collection flags) { + public static String toString(HashMap, Object> flags) { + //todo MattBDev: Fix this for flags to work. + //noinspection StringBufferReplaceableByString,MismatchedQueryAndUpdateOfStringBuilder StringBuilder flag_string = new StringBuilder(); - int i = 0; - for (Flag flag : flags) { +/* int i = 0; + Flag flag; + for (Map.Entry, Object> entry : flags.entrySet()) { + flag = entry.getKey(); if (i != 0) { flag_string.append(","); } - flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + flag_string.append(flag.getName() + ":" + flag.valueToString(entry.getValue()).replaceAll(":", "¯").replaceAll(",", "´")); i++; - } + }*/ return flag_string.toString(); } - public static Flag getSettingFlag(PlotArea area, PlotSettings settings, String id) { - Flag flag; - if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) { - if (area == null) { + public static V getSettingFlag(PlotArea area, PlotSettings settings, Flag id) { + Object value; + if (settings.flags.isEmpty() || ((value = settings.flags.get(id)) == null)) { + if (area == null || area.DEFAULT_FLAGS.isEmpty()) { return null; } - if (area.DEFAULT_FLAGS.isEmpty()) { - return null; - } - return area.DEFAULT_FLAGS.get(id); + return (V) area.DEFAULT_FLAGS.get(id); } - return flag; - } - - public static boolean isBooleanFlag(Plot plot, String key, boolean defaultValue) { - Flag flag = FlagManager.getPlotFlagRaw(plot, key); - if (flag == null) { - return defaultValue; - } - Object value = flag.getValue(); - if (value instanceof Boolean) { - return (boolean) value; - } - return defaultValue; - } - - /** - * Get the value of a flag for a plot (respects flag defaults) - * @param plot - * @param flag - * @return Flag - */ - public static Flag getPlotFlag(Plot plot, String flag) { - Flag result = getPlotFlagRaw(plot, flag); - return result == null ? null : (Flag) result.clone(); + return (V) value; } /** @@ -166,80 +109,36 @@ public class FlagManager { * @param flag * @return */ - public static Flag getPlotFlagRaw(Plot plot, String flag) { + public static V getPlotFlagRaw(Plot plot, Flag flag) { if (plot.owner == null) { return null; } return getSettingFlag(plot.getArea(), plot.getSettings(), flag); } - public static boolean isPlotFlagTrue(Plot plot, String strFlag) { - if (plot.owner == null) { - return false; - } - Flag flag = getPlotFlagRaw(plot, strFlag); - return !(flag == null || !((Boolean) flag.getValue())); - } - - public static boolean isPlotFlagFalse(Plot plot, String strFlag) { - if (plot.owner == null) { - return false; - } - Flag flag = getPlotFlagRaw(plot, strFlag); - if (flag == null || (Boolean) flag.getValue()) { - return false; - } - return false; - } - - /** - * Get the value of a flag for a plot (ignores flag defaults) - * @param plot - * @param flag - * @return Flag - */ - public static Flag getPlotFlagAbs(Plot plot, String flag) { - return getSettingFlagAbs(plot.getSettings(), flag); - } - - public static Flag getSettingFlagAbs(PlotSettings settings, String flag) { - if (settings.flags.isEmpty()) { - return null; - } - return settings.flags.get(flag); - } - /** * Add a flag to a plot * @param origin * @param flag + * @param value */ - public static boolean addPlotFlag(Plot origin, Flag flag) { + public static boolean addPlotFlag(Plot origin, Flag flag, V value) { boolean result = EventUtil.manager.callFlagAdd(flag, origin); if (!result) { return false; } for (Plot plot : origin.getConnectedPlots()) { - plot.getFlags().put(flag.getKey(), flag); + plot.getFlags().put(flag, value); plot.reEnter(); - DBFunc.setFlags(plot, plot.getFlags().values()); + DBFunc.setFlags(plot, plot.getFlags()); } return true; } - public static boolean addPlotFlagAbs(Plot plot, Flag flag) { - boolean result = EventUtil.manager.callFlagAdd(flag, plot); - if (!result) { - return false; - } - plot.getFlags().put(flag.getKey(), flag); - return true; - } - - public static boolean addClusterFlag(PlotCluster cluster, Flag flag) { - getSettingFlag(cluster.area, cluster.settings, flag.getKey()); - cluster.settings.flags.put(flag.getKey(), flag); - DBFunc.setFlags(cluster, cluster.settings.flags.values()); + public static boolean addClusterFlag(PlotCluster cluster, Flag flag, V value) { + getSettingFlag(cluster.area, cluster.settings, flag); + cluster.settings.flags.put(flag, value); + DBFunc.setFlags(cluster, cluster.settings.flags); return true; } @@ -248,21 +147,21 @@ public class FlagManager { * @param plot * @return set of flags */ - public static HashMap getPlotFlags(Plot plot) { + public static HashMap, Object> getPlotFlags(Plot plot) { if (!plot.hasOwner()) { return null; } return getSettingFlags(plot.getArea(), plot.getSettings()); } - public static HashMap getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) { - HashMap flags = new HashMap<>(); + public static HashMap, Object> getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) { + HashMap, Object> flags = new HashMap<>(); if (area != null && !area.DEFAULT_FLAGS.isEmpty()) { flags.putAll(area.DEFAULT_FLAGS); } if (ignorePluginflags) { - for (Map.Entry flag : settings.flags.entrySet()) { - if (isReserved(flag.getValue().getAbstractFlag().getKey())) { + for (Map.Entry, Object> flag : settings.flags.entrySet()) { + if (isReserved(flag.getKey())) { continue; } flags.put(flag.getKey(), flag.getValue()); @@ -274,45 +173,45 @@ public class FlagManager { return flags; } - public static HashMap getSettingFlags(PlotArea area, PlotSettings settings) { + public static HashMap, Object> getSettingFlags(PlotArea area, PlotSettings settings) { return getPlotFlags(area, settings, false); } - public static boolean removePlotFlag(Plot plot, String id) { - Flag flag = plot.getFlags().remove(id); - if (flag == null) { + public static boolean removePlotFlag(Plot plot, Flag id) { + Object value = plot.getFlags().remove(id); + if (value == null) { return false; } - boolean result = EventUtil.manager.callFlagRemove(flag, plot); + boolean result = EventUtil.manager.callFlagRemove(id, plot, value); if (!result) { - plot.getFlags().put(id, flag); + plot.getFlags().put(id, value); return false; } plot.reEnter(); - DBFunc.setFlags(plot, plot.getFlags().values()); + DBFunc.setFlags(plot, plot.getFlags()); return true; } - public static boolean removeClusterFlag(PlotCluster cluster, String id) { - Flag flag = cluster.settings.flags.remove(id); - if (flag == null) { + public static boolean removeClusterFlag(PlotCluster cluster, Flag id) { + Object object = cluster.settings.flags.remove(id); + if (object == null) { return false; } - boolean result = EventUtil.manager.callFlagRemove(flag, cluster); + boolean result = EventUtil.manager.callFlagRemove(id, object, cluster); if (!result) { - cluster.settings.flags.put(id, flag); + cluster.settings.flags.put(id, object); return false; } - DBFunc.setFlags(cluster, cluster.settings.flags.values()); + DBFunc.setFlags(cluster, cluster.settings.flags); return true; } - public static void setPlotFlags(Plot origin, Set flags) { + public static void setPlotFlags(Plot origin, HashMap, Object> flags) { for (Plot plot : origin.getConnectedPlots()) { if (flags != null && !flags.isEmpty()) { plot.getFlags().clear(); - for (Flag flag : flags) { - plot.getFlags().put(flag.getKey(), flag); + for (Map.Entry, Object> flag : flags.entrySet()) { + plot.getFlags().put(flag.getKey(), flag.getValue()); } } else if (plot.getFlags().isEmpty()) { return; @@ -320,7 +219,7 @@ public class FlagManager { plot.getFlags().clear(); } plot.reEnter(); - DBFunc.setFlags(plot, plot.getFlags().values()); + DBFunc.setFlags(plot, plot.getFlags()); } } @@ -328,57 +227,27 @@ public class FlagManager { if (flags != null && !flags.isEmpty()) { cluster.settings.flags.clear(); for (Flag flag : flags) { - cluster.settings.flags.put(flag.getKey(), flag); + cluster.settings.flags.put(flag, flag); } } else if (cluster.settings.flags.isEmpty()) { return; } else { cluster.settings.flags.clear(); } - DBFunc.setFlags(cluster, cluster.settings.flags.values()); - } - - public static Flag[] removeFlag(Flag[] flags, String r) { - Flag[] f = new Flag[flags.length - 1]; - int index = 0; - for (Flag flag : flags) { - if (!flag.getKey().equals(r)) { - f[index++] = flag; - } - } - return f; - } - - public static Set removeFlag(Set flags, String r) { - HashSet newflags = new HashSet<>(); - for (Flag flag : flags) { - if (!flag.getKey().equalsIgnoreCase(r)) { - newflags.add(flag); - } - } - return newflags; + DBFunc.setFlags(cluster, cluster.settings.flags); } /** - * Get a list of registered AbstractFlag objects - * - * @return List (AbstractFlag) - */ - public static HashSet getFlags() { - return flags; - } - - /** - * Get a list of registered AbstractFlag objects based on player permissions + * Get a list of registered {@link Flag} objects based on player permissions * * @param player with permissions * * @return List (AbstractFlag) */ - public static List getFlags(PlotPlayer player) { - List returnFlags = new ArrayList<>(); - for (AbstractFlag flag : flags) { - if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase())) { + public static List getFlags(PlotPlayer player) { + List returnFlags = new ArrayList<>(); + for (Flag flag : Flags.flags) { + if (Permissions.hasPermission(player, "plots.set.flag." + flag.getName().toLowerCase())) { returnFlags.add(flag); } } @@ -392,9 +261,9 @@ public class FlagManager { * * @return AbstractFlag */ - public static AbstractFlag getFlag(String string) { - for (AbstractFlag flag : flags) { - if (flag.getKey().equalsIgnoreCase(string)) { + public static Flag getFlag(String string) { + for (Flag flag : Flags.flags) { + if (flag.getName().equalsIgnoreCase(string)) { return flag; } } @@ -409,26 +278,23 @@ public class FlagManager { * * @return AbstractFlag */ - public static AbstractFlag getFlag(String string, boolean create) { + public static Flag getFlag(String string, boolean create) { + for (Flag flag : Flags.getFlags()) { + if (flag.getName().equalsIgnoreCase(string)) { + return flag; + } + } + if (getFlag(string) == null && create) { - return new AbstractFlag(string); + //return new AbstractFlag(string); } return getFlag(string); } - /** - * Remove a registered AbstractFlag - * - * @param flag Flag Key - * - * @return boolean Result of operation - */ - public static boolean removeFlag(AbstractFlag flag) { - return flags.remove(flag); - } - - public static HashMap parseFlags(List flagstrings) { - HashMap map = new HashMap<>(); + public static HashMap, Object> parseFlags(List flagstrings) { + HashMap, Object> map = new HashMap<>(); + //todo MattBDev: Fix this +/* for (String key : flagstrings) { String[] split; if (key.contains(";")) { @@ -438,12 +304,13 @@ public class FlagManager { } Flag flag; if (split.length == 1) { - flag = new Flag(getFlag(split[0], true), ""); + flag = new Flag(getFlag(split[0]), ""); } else { flag = new Flag(getFlag(split[0], true), split[1]); } map.put(flag.getKey(), flag); } +*/ return map; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java index 23193b8ef..8641fd763 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -12,25 +12,10 @@ import java.util.List; public abstract class FlagValue { - private final Class clazz; - - @SuppressWarnings("unchecked") public FlagValue() { - this.clazz = (Class) getClass(); } - public FlagValue(Class clazz) { - if (clazz == null) { - throw new NullPointerException(); - } - this.clazz = clazz; - } - - public boolean validValue(Object value) { - return value != null && value.getClass() == this.clazz; - } - - public String toString(Object t) { + public String toString(T t) { return t.toString(); } @@ -40,7 +25,7 @@ public abstract class FlagValue { public abstract String getDescription(); - public interface ListValue extends Cloneable { + interface ListValue extends Cloneable { void add(Object t, String value); @@ -103,9 +88,8 @@ public abstract class FlagValue { public static class IntervalValue extends FlagValue { @Override - public String toString(Object t) { - Integer[] value = (Integer[]) t; - return value[0] + " " + value[1]; + public String toString(Integer[] t) { + return t[0] + " " + t[1]; } @Override @@ -306,8 +290,8 @@ public abstract class FlagValue { @SuppressWarnings("unchecked") @Override - public String toString(Object t) { - return StringMan.join((HashSet) t, ","); + public String toString(HashSet t) { + return StringMan.join(t, ","); } @SuppressWarnings("unchecked") @@ -318,7 +302,7 @@ public abstract class FlagValue { @Override public HashSet parse(String t) { - HashSet list = new HashSet(); + HashSet list = new HashSet<>(); for (String item : t.split(",")) { PlotBlock block; try { @@ -377,8 +361,8 @@ public abstract class FlagValue { @SuppressWarnings("unchecked") @Override - public String toString(Object t) { - return StringMan.join((List) t, ","); + public String toString(List t) { + return StringMan.join(t, ","); } @SuppressWarnings("unchecked") @@ -390,7 +374,7 @@ public abstract class FlagValue { @Override public List parse(String t) { String[] split = t.split(","); - ArrayList numbers = new ArrayList(); + ArrayList numbers = new ArrayList<>(); for (String element : split) { numbers.add(Integer.parseInt(element)); } @@ -423,12 +407,11 @@ public abstract class FlagValue { } } - @SuppressWarnings("ALL") public static class StringListValue extends FlagValue> implements ListValue { @Override - public String toString(final Object t) { - return StringMan.join((List) t, ","); + public String toString(final List t) { + return StringMan.join(t, ","); } @Override @@ -467,54 +450,6 @@ public abstract class FlagValue { } } - public static class DoubleListValue extends FlagValue> implements ListValue { - - @SuppressWarnings("unchecked") - @Override - public String toString(Object t) { - return StringMan.join((List) t, ","); - } - - @SuppressWarnings("unchecked") - @Override - public List getValue(Object t) { - return (List) t; - } - - @Override - public List parse(String t) { - String[] split = t.split(","); - ArrayList numbers = new ArrayList(); - for (String element : split) { - numbers.add(Double.parseDouble(element)); - } - return numbers; - } - - @Override - public String getDescription() { - return "Flag value must be a integer list"; - } - - @Override - public void add(Object t, String value) { - try { - ((List) t).addAll(parse(value)); - } catch (Exception e) { - } - } - - @Override - public void remove(Object t, String value) { - try { - for (Double item : parse(value)) { - ((List) t).remove(item); - } - } catch (Exception e) { - } - } - } - public static class StringValue extends FlagValue { @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java new file mode 100644 index 000000000..ae564c7c6 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java @@ -0,0 +1,84 @@ +package com.intellectualcrafters.plot.flag; + +import com.google.common.collect.Sets; + +import java.util.HashSet; + +public class Flags { + + public static final NumericFlag MUSIC = new NumericFlag<>("music"); + public static final StringFlag DESCRIPTION = new StringFlag("description"); + public static final IntegerListFlag ANALYSIS = new IntegerListFlag("analysis"); + public static final StringFlag GREETING = new StringFlag("greeting"); + public static final StringFlag FAREWELL = new StringFlag("farewell"); + public static final IntervalFlag FEED = new IntervalFlag("feed"); + public static final IntervalFlag HEAL = new IntervalFlag("heal"); + public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode"); + public static final StringFlag DONE = new StringFlag("done"); + public static final BooleanFlag REDSTONE = new BooleanFlag("redstone"); + public static final BooleanFlag FLY = new BooleanFlag("fly"); + public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave"); + public static final BooleanFlag TITLES = new BooleanFlag("titles"); + public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter"); + public static final NumericFlag TIME = new NumericFlag<>("time"); + public static final PlotWeatherFlag WEATHER = new PlotWeatherFlag("weather"); + public static final Flag KEEP = new Flag<>("keep"); + public static final NumericFlag PRICE = new NumericFlag<>("price"); + public static final BooleanFlag EXPLOSION = new BooleanFlag("explosion"); + public static final BooleanFlag GRASS_GROW = new BooleanFlag("grass-grow"); + public static final BooleanFlag VINE_GROW = new BooleanFlag("vine-grow"); + public static final BooleanFlag MYCEL_GROW = new BooleanFlag("mycel-grow"); + public static final BooleanFlag DISABLE_PHYSICS = new BooleanFlag("disable-physics"); + public static final BooleanFlag SNOW_MELT = new BooleanFlag("snow-melt"); + public static final BooleanFlag ICE_MELT = new BooleanFlag("ice-melt"); + public static final BooleanFlag FIRE_SPREAD = new BooleanFlag("fire-spread"); + public static final BooleanFlag BLOCK_BURN = new BooleanFlag("block-burn"); + public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); + public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry"); + public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); + public static final PlotBlockListFlag USE = new PlotBlockListFlag("use"); + public static final PlotBlockListFlag BREAK = new PlotBlockListFlag("break"); + public static final PlotBlockListFlag PLACE = new PlotBlockListFlag("place"); + public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact"); + public static final BooleanFlag VEHICLE_BREAK = new BooleanFlag("vehicle-break"); + public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place"); + public static final BooleanFlag VEHICLE_USE = new BooleanFlag("vehicle-use"); + public static final BooleanFlag HANGING_BREAK = new BooleanFlag("hanging-break"); + public static final BooleanFlag HANGING_PLACE = new BooleanFlag("hanging-place"); + public static final BooleanFlag HANGING_INTERACT = new BooleanFlag("hanging-interact"); + public static final BooleanFlag MISC_PLACE = new BooleanFlag("misc-place"); + public static final BooleanFlag MISC_BREAK = new BooleanFlag("misc-break"); + public static final BooleanFlag MISC_INTERACT = new BooleanFlag("misc-interact"); + public static final BooleanFlag PLAYER_INTERACT = new BooleanFlag("player-interact"); + public static final BooleanFlag TAMED_ATTACK = new BooleanFlag("tamed-attack"); + public static final BooleanFlag TAMED_INTERACT = new BooleanFlag("tamed-interact"); + public static final BooleanFlag ANIMAL_ATTACK = new BooleanFlag("animal-attack"); + public static final BooleanFlag ANIMAL_INTERACT = new BooleanFlag("animal-interact"); + public static final BooleanFlag HOSTILE_ATTACK = new BooleanFlag("hostile-attack"); + public static final BooleanFlag HOSTILE_INTERACT = new BooleanFlag("hostile-interact"); + public static final BooleanFlag MOB_PLACE = new BooleanFlag("mob-place"); + public static final BooleanFlag FORCEFIELD = new BooleanFlag("forcefield"); + public static final BooleanFlag INVINCIBLE = new BooleanFlag("invincible"); + public static final BooleanFlag ITEM_DROP = new BooleanFlag("item-drop"); + public static final BooleanFlag INSTABREAK = new BooleanFlag("instabreak"); + public static final BooleanFlag DROP_PROTECTION = new BooleanFlag("drop-protection"); + public static final BooleanFlag PVP = new BooleanFlag("pvp"); + public static final BooleanFlag PVE = new BooleanFlag("pve"); + public static final BooleanFlag NO_WORLDEDIT = new BooleanFlag("no-worldedit"); + public static final NumericFlag MISC_CAP = new NumericFlag<>("misc-cap"); + public static final NumericFlag ENTITY_CAP = new NumericFlag<>("entity-cap"); + public static final NumericFlag MOB_CAP = new NumericFlag<>("mob-cap"); + public static final NumericFlag ANIMAL_CAP = new NumericFlag<>("animal-cap"); + public static final NumericFlag HOSTILE_CAP = new NumericFlag<>("hostile-cap"); + public static final NumericFlag VEHICLE_CAP = new NumericFlag<>("vehicle-cap"); + static final HashSet> flags = Sets.newHashSet(MUSIC, ANIMAL_CAP, HOSTILE_CAP, PVP, PVE, NO_WORLDEDIT); + + /** + * Get a list of registered AbstractFlag objects + * + * @return List (AbstractFlag) + */ + public static HashSet> getFlags() { + return flags; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/GameModeFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/GameModeFlag.java new file mode 100644 index 000000000..2b02a9c94 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/GameModeFlag.java @@ -0,0 +1,41 @@ +package com.intellectualcrafters.plot.flag; + +import com.intellectualcrafters.plot.util.PlotGameMode; + +public class GameModeFlag extends Flag { + + public GameModeFlag(String name) { + super(name); + } + + @Override public String valueToString(Object value) { + return ((PlotGameMode) value).getName(); + } + + @Override + public PlotGameMode parseValue(String value) { + switch (value.toLowerCase()) { + case "survival": + case "s": + case "0": + return PlotGameMode.SURVIVAL; + case "creative": + case "c": + case "1": + return PlotGameMode.CREATIVE; + case "adventure": + case "a": + case "2": + return PlotGameMode.ADVENTURE; + case "spectator": + case "3": + return PlotGameMode.SPECTATOR; + default: + return PlotGameMode.NOT_SET; + } + } + + @Override public String getValueDescription() { + return "Flag value must be a gamemode: 'creative' , 'survival', 'adventure' or 'spectator'"; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java deleted file mode 100644 index 85e1f1916..000000000 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.intellectualcrafters.plot.flag; - -public class IntegerFlag extends Flag { - - public IntegerFlag(String name) { - super(name); - } -} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerListFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerListFlag.java new file mode 100644 index 000000000..041487ed5 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerListFlag.java @@ -0,0 +1,23 @@ +package com.intellectualcrafters.plot.flag; + +import java.util.List; + + +public class IntegerListFlag extends ListFlag> { + + public IntegerListFlag(String name) { + super(name); + } + + @Override public String valueToString(Object value) { + return null; + } + + @Override public List parseValue(String value) { + return null; + } + + @Override public String getValueDescription() { + return null; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/IntervalFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntervalFlag.java new file mode 100644 index 000000000..1055e5ddd --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntervalFlag.java @@ -0,0 +1,41 @@ +package com.intellectualcrafters.plot.flag; + +public class IntervalFlag extends Flag { + + public IntervalFlag(String name) { + super(name); + } + + @Override + public String valueToString(Object value) { + return null; + } + + @Override public Integer[] parseValue(String value) { + int seconds; + int amount; + String[] values = value.split(" "); + if (values.length < 2) { + seconds = 1; + try { + amount = Integer.parseInt(values[0]); + } catch (NumberFormatException e) { + return null; + } + } else if (values.length == 2) { + try { + amount = Integer.parseInt(values[0]); + seconds = Integer.parseInt(values[1]); + } catch (NumberFormatException e) { + return null; + } + } else { + return null; + } + return new Integer[]{amount, seconds}; + } + + @Override public String getValueDescription() { + return "Value(s) must be numeric. /plot set flag [amount]"; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java new file mode 100644 index 000000000..b8348a4ff --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java @@ -0,0 +1,18 @@ +package com.intellectualcrafters.plot.flag; + +import java.util.Collection; + +public abstract class ListFlag extends Flag { + + /** + * Flag object used to store basic information for a Plot. Flags are a + * key/value pair. For a flag to be usable by a player, you need to + * register it with PlotSquared. + * + + * @param name Flag name + */ + public ListFlag(String name) { + super(name); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/NumericFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/NumericFlag.java new file mode 100644 index 000000000..1a2bfebd6 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/NumericFlag.java @@ -0,0 +1,16 @@ +package com.intellectualcrafters.plot.flag; + +public class NumericFlag extends Flag { + + public NumericFlag(String name) { + super(name); + } + + @Override public String getValueDescription() { + return super.getValueDescription(); + } + + @Override public String valueToString(Object value) { + return null; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotBlockListFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotBlockListFlag.java new file mode 100644 index 000000000..33073b847 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotBlockListFlag.java @@ -0,0 +1,53 @@ +package com.intellectualcrafters.plot.flag; + +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; + +import java.util.HashSet; + +public class PlotBlockListFlag extends ListFlag> { + + public PlotBlockListFlag(String name) { + super(name); + } + + @Override public String valueToString(Object value) { + return StringMan.join((HashSet) value, ","); + } + + @Override public HashSet parseValue(String value) { + HashSet list = new HashSet<>(); + for (String item : value.split(",")) { + PlotBlock block; + try { + String[] split = item.split(":"); + byte data; + if (split.length == 2) { + if ("*".equals(split[1])) { + data = -1; + } else { + data = Byte.parseByte(split[1]); + } + } else { + data = -1; + } + short id = Short.parseShort(split[0]); + block = new PlotBlock(id, data); + } catch (NumberFormatException e) { + StringComparison.ComparisonResult str = WorldUtil.IMP.getClosestBlock(value); + if (str == null || str.match > 1) { + continue; + } + block = str.best; + } + list.add(block); + } + return list; + } + + @Override public String getValueDescription() { + return null; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotWeatherFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotWeatherFlag.java new file mode 100644 index 000000000..fe611a9c7 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/PlotWeatherFlag.java @@ -0,0 +1,22 @@ +package com.intellectualcrafters.plot.flag; + +import com.intellectualcrafters.plot.util.PlotWeather; + +public class PlotWeatherFlag extends Flag { + + public PlotWeatherFlag(String name) { + super(name); + } + + @Override public String valueToString(Object value) { + return null; + } + + @Override public PlotWeather parseValue(String value) { + return null; + } + + @Override public String getValueDescription() { + return null; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/StringFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/StringFlag.java new file mode 100644 index 000000000..9faec52c8 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/StringFlag.java @@ -0,0 +1,21 @@ +package com.intellectualcrafters.plot.flag; + + +public class StringFlag extends Flag { + + public StringFlag(String name) { + super(name); + } + + @Override public String valueToString(Object value) { + return ((String) value); + } + + @Override public String parseValue(String value) { + return null; + } + + @Override public String getValueDescription() { + return null; + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/StringListFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/StringListFlag.java new file mode 100644 index 000000000..29a6fb263 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/StringListFlag.java @@ -0,0 +1,18 @@ +package com.intellectualcrafters.plot.flag; + +import java.util.List; + +public class StringListFlag extends ListFlag> { + + /** + * Flag object used to store basic information for a Plot. Flags are a + * key/value pair. For a flag to be usable by a player, you need to + * register it with PlotSquared. + * + + * @param name Flag name + */ + public StringListFlag(String name) { + super(name); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index b4ae1246a..0b9173e18 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -3,8 +3,8 @@ package com.intellectualcrafters.plot.generator; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -89,8 +89,7 @@ public abstract class HybridUtils { result.add(whenDone.value.data_sd); result.add(whenDone.value.air_sd); result.add(whenDone.value.variety_sd); - Flag flag = new Flag(FlagManager.getFlag("analysis"), result); - FlagManager.addPlotFlag(origin, flag); + FlagManager.addPlotFlag(origin, Flags.ANALYSIS, result); TaskManager.runTask(whenDone); return; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 79130e18b..40660fe77 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object; +import com.google.common.base.Optional; import com.google.common.collect.BiMap; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; @@ -194,7 +195,7 @@ public class Plot { this.settings.setMerged(merged); if (flags != null) { for (Flag flag : flags) { - this.settings.flags.put(flag.getKey(), flag); + this.settings.flags.put(flag, flag); } } this.timestamp = timestamp; @@ -941,24 +942,38 @@ public class Plot { * @param flag * @param value */ - public void setFlag(String flag, Object value) { - FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value)); + public boolean setFlag(Flag flag, Object value) { + return FlagManager.addPlotFlag(this, flag, (V) value); } /** * Remove a flag from this plot * @param flag */ - public void removeFlag(String flag) { + public boolean removeFlag(Flag flag) { FlagManager.removePlotFlag(this, flag); + return false; } /** * Get the flag for a given key * @param key */ - public Flag getFlag(String key) { - return FlagManager.getPlotFlagRaw(this, key); + public Optional getFlag(Flag key) { + return Optional.fromNullable(FlagManager.getPlotFlagRaw(this, key)); + } + + /** + * Get the flag for a given key + * @param key + */ + public V getFlag(Flag key, V def) { + V value = FlagManager.getPlotFlagRaw(this, key); + if (value == null) { + return def; + } else { + return value; + } } /** @@ -1824,18 +1839,15 @@ public class Plot { * - Does not take default flags into account
* @return */ - public HashMap getFlags() { - if (this.settings == null) { - return new HashMap<>(0); - } - return this.settings.flags; + public HashMap, Object> getFlags() { + return this.getSettings().flags; } /** * Set a flag for this plot. * @param flags */ - public void setFlags(Set flags) { + public void setFlags(HashMap, Object> flags) { FlagManager.setPlotFlags(this, flags); } @@ -2142,8 +2154,8 @@ public class Plot { * @param b */ public void mergeData(Plot b) { - HashMap flags1 = this.getFlags(); - HashMap flags2 = b.getFlags(); + HashMap, Object> flags1 = this.getFlags(); + HashMap, Object> flags2 = b.getFlags(); if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) { boolean greater = flags1.size() > flags2.size(); if (greater) { @@ -2151,7 +2163,7 @@ public class Plot { } else { flags2.putAll(flags1); } - HashSet net = new HashSet<>((greater ? flags1 : flags2).values()); + HashMap, Object> net = (greater ? flags1 : flags2); this.setFlags(net); b.setFlags(net); } @@ -2814,7 +2826,7 @@ public class Plot { other.create(plot.owner, false); if (!plot.getFlags().isEmpty()) { other.getSettings().flags = plot.getFlags(); - DBFunc.setFlags(other, plot.getFlags().values()); + DBFunc.setFlags(other, plot.getFlags()); } if (plot.isMerged()) { other.setMerged(plot.getMerged()); @@ -2863,4 +2875,8 @@ public class Plot { run.run(); return true; } + + public boolean hasFlag(Flag flag) { + return false; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index f4b0c03ad..6a34c0b01 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -1,9 +1,9 @@ package com.intellectualcrafters.plot.object; +import com.google.common.base.Optional; import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.TaskManager; @@ -34,10 +34,10 @@ public class PlotAnalysis { private int complexity; public static PlotAnalysis getAnalysis(Plot plot) { - Flag flag = FlagManager.getPlotFlagRaw(plot, "analysis"); - if (flag != null) { + Optional> flag = plot.getFlag(Flags.ANALYSIS); + if (flag.isPresent()) { PlotAnalysis analysis = new PlotAnalysis(); - List values = (List) flag.getValue(); + List values = flag.get(); analysis.changes = values.get(0); // 2126 analysis.faces = values.get(1); // 90 analysis.data = values.get(2); // 0 diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index d9f21d11c..c41f327f5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -53,7 +53,7 @@ public abstract class PlotArea { public boolean SCHEMATIC_ON_CLAIM = false; public String SCHEMATIC_FILE = "null"; public List SCHEMATICS = null; - public HashMap DEFAULT_FLAGS; + public HashMap, Object> DEFAULT_FLAGS; public boolean USE_ECONOMY = false; public HashMap PRICES = new HashMap<>(); public boolean SPAWN_EGGS = false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index 8bc64d1f8..fb51e41d2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.object; import com.google.common.base.Optional; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.comment.PlotComment; import java.util.ArrayList; @@ -49,7 +49,7 @@ public class PlotSettings { * @deprecated Raw access */ @Deprecated - public HashMap flags; + public HashMap, Object> flags = new HashMap<>(); /** * Home Position. * @deprecated Raw access @@ -57,14 +57,6 @@ public class PlotSettings { @Deprecated private BlockLoc position; - /** - * Constructor - * - */ - public PlotSettings() { - this.flags = new HashMap<>(); - } - /** * Check if the plot is merged in a direction
0 = North
1 = East
2 = South
3 = West
* @@ -131,7 +123,7 @@ public class PlotSettings { } public String getJoinMessage(PlotArea area) { - Flag greeting = FlagManager.getSettingFlag(area, this, "greeting"); + Flag greeting = Flags.GREETING; if (greeting != null) { return greeting.getValueString(); } @@ -145,7 +137,7 @@ public class PlotSettings { * @return Farewell flag */ public String getLeaveMessage(PlotArea plotArea) { - Flag farewell = FlagManager.getSettingFlag(plotArea, this, "farewell"); + Flag farewell = Flags.FAREWELL; if (farewell != null) { return farewell.getValueString(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ConsoleColors.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ConsoleColors.java index 1cd43a8f4..c6c8bf0e8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ConsoleColors.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ConsoleColors.java @@ -63,22 +63,16 @@ public class ConsoleColors { return ConsoleColor.RESET; } } - - static enum ConsoleColor { + + enum ConsoleColor { RESET("\u001B[0m"), BLACK("\u001B[30m"), RED("\u001B[31m"), GREEN("\u001B[32m"), YELLOW("\u001B[33m"), BLUE("\u001B[34m"), PURPLE("\u001B[35m"), CYAN("\u001B[36m"), WHITE("\u001B[37m"), BOLD( "\033[1m"), UNDERLINE("\033[0m"), ITALIC("\033[3m"); - private final String win; private final String lin; ConsoleColor(final String lin) { this.lin = lin; - win = lin; } - - public String getWin() { - return win; - } - + public String getLin() { return lin; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index c245667be..e541f1dba 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -1,10 +1,11 @@ package com.intellectualcrafters.plot.util; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.LazyBlock; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -36,9 +37,9 @@ public abstract class EventUtil { public abstract boolean callFlagAdd(Flag flag, Plot plot); - public abstract boolean callFlagRemove(Flag flag, Plot plot); + public abstract boolean callFlagRemove(Flag flag, Plot plot, Object value); - public abstract boolean callFlagRemove(Flag flag, PlotCluster cluster); + public abstract boolean callFlagRemove(Flag flag, Object value, PlotCluster cluster); public abstract boolean callMerge(Plot plot, ArrayList plots); @@ -119,16 +120,16 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - Flag use = FlagManager.getPlotFlagRaw(plot, "use"); - if (use != null) { - HashSet value = (HashSet) use.getValue(); + Optional> use = plot.getFlag(Flags.USE); + if (use.isPresent()) { + HashSet value = use.get(); if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) { return true; } } - Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); - if (destroy != null) { - HashSet value = (HashSet) destroy.getValue(); + Optional> destroy = plot.getFlag(Flags.BREAK); + if (destroy.isPresent()) { + HashSet value = destroy.get(); if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) { return true; } @@ -141,7 +142,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "hanging-break")) { + if (plot.getFlag(Flags.HANGING_BREAK).or(false)) { return true; } if (plot.hasOwner()) { @@ -153,7 +154,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "misc-break")) { + if (plot.getFlag(Flags.MISC_BREAK).or(false)) { return true; } if (plot.hasOwner()) { @@ -165,7 +166,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) { + if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) { return true; } if (plot.hasOwner()) { @@ -182,14 +183,14 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); + Optional> flagValue = plot.getFlag(Flags.USE); HashSet value; - if (flag == null) { - value = null; + if (flagValue.isPresent()) { + value = flagValue.get(); } else { - value = (HashSet) flag.getValue(); + return true; } - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms) || !(!notifyPerms || MainUtil .sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s())); } @@ -202,14 +203,14 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms); } - Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); + Optional> flagValue = plot.getFlag(Flags.PLACE); HashSet value; - if (flag == null) { - value = null; + if (flagValue.isPresent()) { + value = flagValue.get(); } else { - value = (HashSet) flag.getValue(); + return true; } - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER.s(), notifyPerms)) { return true; } @@ -224,18 +225,19 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false); } - if (FlagManager.isPlotFlagTrue(plot, "device-interact")) { + if (plot.getFlag(Flags.DEVICE_INTERACT).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); + Optional> flagValue = plot.getFlag(Flags.USE); HashSet value; - if (flag == null) { - value = null; + if (flagValue.isPresent()) { + value = flagValue.get(); } else { - value = (HashSet) flag.getValue(); + return true; } - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { - return false; //!(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s())); + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + // TODO: fix the commented dead code + return true; //!(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s())); } return true; } @@ -246,12 +248,17 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) { + if (plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.USE); + HashSet value; + if (flagValue.isPresent()) { + value = flagValue.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -266,12 +273,18 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) { + if (plot.getFlag(Flags.MISC_INTERACT).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + + Optional> flag = plot.getFlag(Flags.USE); + HashSet value; + if (flag.isPresent()) { + value = flag.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -286,12 +299,17 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) { + if (plot.getFlag(Flags.VEHICLE_USE).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.USE); + HashSet value; + if (flag.isPresent()) { + value = flag.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -307,12 +325,17 @@ public abstract class EventUtil { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "mob-place")) { + if (plot.getFlag(Flags.MOB_PLACE).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + HashSet value; + if (flagValue.isPresent()) { + value = flagValue.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -330,17 +353,24 @@ public abstract class EventUtil { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "misc-place")) { + if (plot.getFlag(Flags.MISC_PLACE).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.PLACE); + + HashSet value; + if (flag.isPresent()) { + value = flag.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_MISC_PLACE.s() + "/" + C.FLAG_PLACE.s())); } + return true; } case PLACE_VEHICLE: @@ -351,12 +381,17 @@ public abstract class EventUtil { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (FlagManager.isPlotFlagTrue(plot, "vehicle-place")) { + if (plot.getFlag(Flags.VEHICLE_PLACE).or(false)) { return true; } - Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); - HashSet value = flag == null ? null : (HashSet) flag.getValue(); - if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.PLACE); + HashSet value; + if (flag.isPresent()) { + value = flag.get(); + } else { + return true; + } + if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 36a2b4bc9..66d4fb3ac 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -1,11 +1,12 @@ package com.intellectualcrafters.plot.util; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; @@ -155,7 +156,7 @@ public class ExpireManager { if ((changed.changes != 0) && (changed.getComplexity() > Settings.CLEAR_THRESHOLD)) { PS.debug("$2[&5Expire&dManager$2] &bIgnoring modified plot: " + plot + " : " + changed.getComplexity() + " - " + changed.changes); - FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("analysis"), changed.asList())); + FlagManager.addPlotFlag(plot, Flags.ANALYSIS, changed.asList()); TaskManager.runTaskLaterAsync(task, Settings.CLEAR_INTERVAL * 20); } else { expiredTask.run(plot, new Runnable() { @@ -263,9 +264,9 @@ public class ExpireManager { if (!plot.hasOwner() || Objects.equals(DBFunc.everyone, plot.owner) || UUIDHandler.getPlayer(plot.owner) != null || plot.getRunning() > 0) { return false; } - Flag keep = plot.getFlag("keep"); - if (keep != null) { - Object value = keep.getValue(); + Optional keep = plot.getFlag(Flags.KEEP); + if (keep.isPresent()) { + Object value = keep.get(); if (value instanceof Boolean) { if (Boolean.TRUE.equals(value)) { return false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index f3774963f..7a1c38341 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -1,11 +1,12 @@ package com.intellectualcrafters.plot.util; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; @@ -708,9 +709,9 @@ public class MainUtil { String expires = C.UNKNOWN.s(); if (Settings.AUTO_CLEAR) { if (plot.hasOwner()) { - Flag keep = plot.getFlag("keep"); - if (keep != null) { - Object value = keep.getValue(); + Optional keep = plot.getFlag(Flags.KEEP); + if (keep.isPresent()) { + Object value = keep.get(); if (value instanceof Boolean) { if (Boolean.TRUE.equals(value)) { expires = C.NONE.s(); @@ -731,8 +732,8 @@ public class MainUtil { } else { expires = C.NEVER.s(); } - Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description"); - String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString(); + Optional descriptionFlag = plot.getFlag(Flags.DESCRIPTION); + String description = !descriptionFlag.isPresent() ? C.NONE.s() : Flags.DESCRIPTION.valueToString(descriptionFlag.get()); String flags; if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 8ea5775b4..4137b330b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -155,7 +155,7 @@ public abstract class SchematicHandler { Map flags = schematic.getFlags(); if (!flags.isEmpty()) { for (Map.Entry entry : flags.entrySet()) { - plot.setFlag(entry.getKey(), StringTag.class.cast(entry.getValue()).getValue()); + //plot.setFlag(entry.getKey(), StringTag.class.cast(entry.getValue()).getValue()); } } @@ -619,9 +619,9 @@ public abstract class SchematicHandler { public void run(CompoundTag value) { if (!plot.getFlags().isEmpty()) { HashMap flagMap = new HashMap<>(); - for (Map.Entry entry : plot.getFlags().entrySet()) { - String key = entry.getKey(); - flagMap.put(key, new StringTag(key, entry.getValue().getValueString())); + for (Map.Entry, Object> entry : plot.getFlags().entrySet()) { + String key = entry.getKey().getName(); + flagMap.put(key, new StringTag(key, entry.getKey().valueToString(entry.getValue()))); } CompoundTag tag = new CompoundTag("Flags", flagMap); HashMap map = new HashMap<>(value.getValue()); diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index 7c02f1f89..b8204ec5a 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -1,9 +1,11 @@ package com.plotsquared.listener; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -41,19 +43,19 @@ public class PlotListener { pp.setMeta("lastplot", plot); EventUtil.manager.callEntry(pp, plot); if (plot.hasOwner()) { - HashMap flags = FlagManager.getPlotFlags(plot); + HashMap, Object> flags = FlagManager.getPlotFlags(plot); int size = flags.size(); boolean titles = Settings.TITLES; final String greeting; if (size != 0) { - Flag titleFlag = flags.get("titles"); - if (titleFlag != null) { - titles = (Boolean) titleFlag.getValue(); + Optional titleFlag = plot.getFlag(Flags.TITLES); + if (titleFlag.isPresent()) { + titles = titleFlag.get(); } - Flag greetingFlag = flags.get("greeting"); - if (greetingFlag != null) { - greeting = (String) greetingFlag.getValue(); + Optional greetingFlag = plot.getFlag(Flags.GREETING); + if (greetingFlag.isPresent()) { + greeting = greetingFlag.get(); MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal() { @Override public void run(String value) { @@ -63,8 +65,8 @@ public class PlotListener { } else { greeting = ""; } - Flag enter = flags.get("notify-enter"); - if (enter != null && (Boolean) enter.getValue()) { + Optional enter = plot.getFlag(Flags.NOTIFY_ENTER); + if (enter.isPresent() && enter.get()) { if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { PlotPlayer owner = UUIDHandler.getPlayer(uuid); @@ -75,38 +77,38 @@ public class PlotListener { } } } - Flag gamemodeFlag = flags.get("gamemode"); - if (gamemodeFlag != null) { - if (pp.getGameMode() != gamemodeFlag.getValue()) { + Optional gamemodeFlag = plot.getFlag(Flags.GAMEMODE); + if (gamemodeFlag.isPresent()) { + if (pp.getGameMode() != gamemodeFlag.get()) { if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { - pp.setGameMode((PlotGameMode) gamemodeFlag.getValue()); + pp.setGameMode(gamemodeFlag.get()); } else { MainUtil.sendMessage(pp, - StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.getValue())); + StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.get())); } } } - Flag flyFlag = flags.get("fly"); - if (flyFlag != null) { - pp.setFlight((boolean) flyFlag.getValue()); + Optional flyFlag = plot.getFlag(Flags.FLY); + if (flyFlag.isPresent()) { + pp.setFlight(flyFlag.get()); } - Flag timeFlag = flags.get("time"); - if (timeFlag != null) { + Optional timeFlag = plot.getFlag(Flags.TIME); + if (timeFlag.isPresent()) { try { - long time = (long) timeFlag.getValue(); + long time = timeFlag.get(); pp.setTime(time); } catch (Exception e) { - FlagManager.removePlotFlag(plot, "time"); + FlagManager.removePlotFlag(plot, Flags.TIME); } } - Flag weatherFlag = flags.get("weather"); - if (weatherFlag != null) { - pp.setWeather((PlotWeather) weatherFlag.getValue()); + Optional weatherFlag = plot.getFlag(Flags.WEATHER); + if (weatherFlag.isPresent()) { + pp.setWeather(weatherFlag.get()); } - Flag musicFlag = flags.get("music"); - if (musicFlag != null) { - Integer id = (Integer) musicFlag.getValue(); + Optional musicFlag = plot.getFlag(Flags.MUSIC); + if (musicFlag.isPresent()) { + Integer id = musicFlag.get(); if ((id >= 2256 && id <= 2267) || (id == 0)) { Location loc = pp.getLocation(); Location lastLoc = pp.getMeta("music"); @@ -172,7 +174,7 @@ public class PlotListener { if (pw == null) { return true; } - if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) { + if (plot.getFlag(Flags.GAMEMODE).isPresent()) { if (pp.getGameMode() != pw.GAMEMODE) { if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { pp.setGameMode(pw.GAMEMODE); @@ -182,17 +184,17 @@ public class PlotListener { } } } - Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell"); - if (farewell != null) { - MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.getValueString(), plot, pp, false, new RunnableVal() { + Optional farewell = plot.getFlag(Flags.FAREWELL); + if (farewell.isPresent()) { + MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, pp, false, new RunnableVal() { @Override public void run(String value) { MainUtil.sendMessage(pp, value); } }); } - Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave"); - if ((leave != null) && (Boolean) leave.getValue()) { + Optional leave = plot.getFlag(Flags.NOTIFY_LEAVE); + if (leave.isPresent() && leave.get()) { if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { PlotPlayer owner = UUIDHandler.getPlayer(uuid); @@ -202,16 +204,16 @@ public class PlotListener { } } } - if (FlagManager.getPlotFlagRaw(plot, "fly") != null) { + if (plot.getFlag(Flags.FLY).isPresent()) { PlotGameMode gamemode = pp.getGameMode(); if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) { pp.setFlight(false); } } - if (FlagManager.getPlotFlagRaw(plot, "time") != null) { + if (plot.getFlag(Flags.TIME).isPresent()) { pp.setTime(Long.MAX_VALUE); } - if (FlagManager.getPlotFlagRaw(plot, "weather") != null) { + if (plot.getFlag(Flags.WEATHER).isPresent()) { pp.setWeather(PlotWeather.RESET); } Location lastLoc = pp.getMeta("music"); diff --git a/Core/src/main/java/com/plotsquared/listener/WEManager.java b/Core/src/main/java/com/plotsquared/listener/WEManager.java index 749bd309f..52969275e 100644 --- a/Core/src/main/java/com/plotsquared/listener/WEManager.java +++ b/Core/src/main/java/com/plotsquared/listener/WEManager.java @@ -2,7 +2,7 @@ package com.plotsquared.listener; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -46,7 +46,7 @@ public class WEManager { return regions; } for (Plot plot : area.getPlots()) { - if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (FlagManager.getPlotFlagRaw(plot, "done") != null))) { + if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (plot.getFlag(Flags.DONE).isPresent()))) { continue; } if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted() diff --git a/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java b/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java new file mode 100644 index 000000000..6506458be --- /dev/null +++ b/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java @@ -0,0 +1,55 @@ +package com.intellectualcrafters.plot; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import com.google.common.base.Optional; +import com.intellectualcrafters.plot.database.AbstractDBTEst; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.EventUtilTest; +import org.hamcrest.core.IsCollectionContaining; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.UUID; + +public class FlagTest { + + private PlotBlock testBlock; + + @Before + public void setUp() throws Exception { + EventUtil.manager = new EventUtilTest(); + DBFunc.dbManager = new AbstractDBTEst(); + } + + @Test + public void flagTest() throws Exception { + Plot plot = new Plot(null, new PlotId(0, 0)); + plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b"); + Flags.USE.parseValue("33,33:1,6:4"); + plot.setFlag(Flags.USE, Flags.USE.parseValue("33,33:1,6:4")); + Optional> flag = plot.getFlag(Flags.USE); + if (flag.isPresent()) { + System.out.println(Flags.USE.valueToString(flag.get())); + } + testBlock = new PlotBlock((short) 1, (byte) 0); + flag.get().add(testBlock); + if (flag.isPresent()) { + System.out.println(Flags.USE.valueToString(flag.get())); + } + Optional> flag2 = plot.getFlag(Flags.USE); + if (flag2.isPresent()) { + assertThat(flag2.get(), IsCollectionContaining.hasItem(testBlock)); + } + if (flag.isPresent() && flag2.isPresent()) { + assertEquals(flag.get(), flag2.get()); + } + } +} diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java new file mode 100644 index 000000000..d94661796 --- /dev/null +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java @@ -0,0 +1,243 @@ +package com.intellectualcrafters.plot.database; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.PlotComment; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class AbstractDBTEst implements AbstractDB { + + @Override public void setOwner(Plot plot, UUID uuid) { + + } + + @Override public void createPlotsAndData(ArrayList plots, Runnable whenDone) { + + } + + @Override public void createPlot(Plot plot) { + + } + + @Override public void createTables() throws Exception { + + } + + @Override public void delete(Plot plot) { + + } + + @Override public void deleteSettings(Plot plot) { + + } + + @Override public void deleteHelpers(Plot plot) { + + } + + @Override public void deleteTrusted(Plot plot) { + + } + + @Override public void deleteDenied(Plot plot) { + + } + + @Override public void deleteComments(Plot plot) { + + } + + @Override public void deleteRatings(Plot plot) { + + } + + @Override public void delete(PlotCluster cluster) { + + } + + @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) { + + } + + @Override public void removePersistentMeta(UUID uuid, String key) { + + } + + @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) { + + } + + @Override public void createPlotSettings(int id, Plot plot) { + + } + + @Override public int getId(Plot plot) { + return 0; + } + + @Override public int getClusterId(PlotCluster cluster) { + return 0; + } + + @Override public HashMap> getPlots() { + return null; + } + + @Override public void validateAllPlots(Set toValidate) { + + } + + @Override public HashMap> getClusters() { + return null; + } + + @Override public void setMerged(Plot plot, boolean[] merged) { + + } + + @Override public void swapPlots(Plot plot1, Plot plot2) { + + } + + @Override public void setFlags(Plot plot, HashMap, Object> flags) { + + } + + @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) { + + } + + @Override public void setClusterName(PlotCluster cluster, String name) { + + } + + @Override public void setAlias(Plot plot, String alias) { + + } + + @Override public void purgeIds(Set uniqueIds) { + + } + + @Override public void purge(PlotArea area, Set plotIds) { + + } + + @Override public void setPosition(Plot plot, String position) { + + } + + @Override public void setPosition(PlotCluster cluster, String position) { + + } + + @Override public void removeTrusted(Plot plot, UUID uuid) { + + } + + @Override public void removeHelper(PlotCluster cluster, UUID uuid) { + + } + + @Override public void removeMember(Plot plot, UUID uuid) { + + } + + @Override public void removeInvited(PlotCluster cluster, UUID uuid) { + + } + + @Override public void setTrusted(Plot plot, UUID uuid) { + + } + + @Override public void setHelper(PlotCluster cluster, UUID uuid) { + + } + + @Override public void setMember(Plot plot, UUID uuid) { + + } + + @Override public void setInvited(PlotCluster cluster, UUID uuid) { + + } + + @Override public void removeDenied(Plot plot, UUID uuid) { + + } + + @Override public void setDenied(Plot plot, UUID uuid) { + + } + + @Override public HashMap getRatings(Plot plot) { + return null; + } + + @Override public void setRating(Plot plot, UUID rater, int value) { + + } + + @Override public void removeComment(Plot plot, PlotComment comment) { + + } + + @Override public void clearInbox(Plot plot, String inbox) { + + } + + @Override public void setComment(Plot plot, PlotComment comment) { + + } + + @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) { + + } + + @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) { + + } + + @Override public void createCluster(PlotCluster cluster) { + + } + + @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) { + + } + + @Override public void movePlot(Plot originalPlot, Plot newPlot) { + + } + + @Override public void replaceUUID(UUID old, UUID now) { + + } + + @Override public boolean deleteTables() { + return false; + } + + @Override public void close() { + + } + + @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) { + + } + + @Override public void updateTables(int[] oldVersion) { + + } +} diff --git a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java new file mode 100644 index 000000000..2d2c37fe4 --- /dev/null +++ b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java @@ -0,0 +1,76 @@ +package com.intellectualcrafters.plot.util; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; + +import java.util.ArrayList; +import java.util.UUID; + +public class EventUtilTest extends EventUtil { + + @Override public Rating callRating(PlotPlayer player, Plot plot, Rating rating) { + return null; + } + + @Override public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) { + return false; + } + + @Override public boolean callTeleport(PlotPlayer player, Location from, Plot plot) { + return false; + } + + @Override public boolean callClear(Plot plot) { + return false; + } + + @Override public void callDelete(Plot plot) { + + } + + @Override public boolean callFlagAdd(Flag flag, Plot plot) { + return true; + } + + @Override public boolean callFlagRemove(Flag flag, Plot plot, Object value) { + return true; + } + + @Override public boolean callFlagRemove(Flag flag, Object value, PlotCluster cluster) { + return true; + } + + @Override public boolean callMerge(Plot plot, ArrayList plots) { + return false; + } + + @Override public boolean callUnlink(PlotArea area, ArrayList plots) { + return false; + } + + @Override public void callEntry(PlotPlayer player, Plot plot) { + + } + + @Override public void callLeave(PlotPlayer player, Plot plot) { + + } + + @Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + + } + + @Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + + } + + @Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + + } +} \ No newline at end of file diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 6f964f15e..04dda11f0 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -4,8 +4,7 @@ import com.flowpowered.math.vector.Vector3d; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -27,7 +26,6 @@ import com.plotsquared.sponge.util.SpongeUtil; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.data.Transaction; -import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.explosive.Explosive; import org.spongepowered.api.entity.living.Ambient; @@ -61,6 +59,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; +@SuppressWarnings("Guava") public class MainListener { /* @@ -203,16 +202,16 @@ public class MainListener { // } if (entity.getType() == EntityTypes.ITEM) { - return !FlagManager.isPlotFlagFalse(plot, "item-drop"); + return plot.getFlag(Flags.ITEM_DROP).or(true); } int[] mobs = null; if (entity instanceof Living) { if (!loc.getPlotArea().MOB_SPAWNING) { return false; } - Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap"); - if (mobCap != null) { - Integer cap = (Integer) mobCap.getValue(); + com.google.common.base.Optional mobCap = plot.getFlag(Flags.MOB_CAP); + if (mobCap.isPresent()) { + Integer cap = mobCap.get(); if (cap == 0) { return false; } @@ -222,9 +221,9 @@ public class MainListener { } } if (entity instanceof Ambient || entity instanceof Animal) { - Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap"); - if (animalFlag != null) { - int cap = (Integer) animalFlag.getValue(); + com.google.common.base.Optional animalFlag = plot.getFlag(Flags.ANIMAL_CAP); + if (animalFlag.isPresent()) { + int cap = animalFlag.get(); if (cap == 0) { return false; } @@ -236,9 +235,9 @@ public class MainListener { } } } else if (entity instanceof Monster) { - Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap"); - if (monsterFlag != null) { - int cap = (Integer) monsterFlag.getValue(); + com.google.common.base.Optional monsterFlag = plot.getFlag(Flags.HOSTILE_CAP); + if (monsterFlag.isPresent()) { + int cap = monsterFlag.get(); if (cap == 0) { return false; } @@ -252,9 +251,9 @@ public class MainListener { } return true; } else if (entity instanceof Minecart || entity instanceof Boat) { - Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap"); - if (vehicleFlag != null) { - int cap = (Integer) vehicleFlag.getValue(); + com.google.common.base.Optional vehicleFlag = plot.getFlag(Flags.VEHICLE_CAP); + if (vehicleFlag.isPresent()) { + int cap = vehicleFlag.get(); if (cap == 0) { return false; } @@ -264,9 +263,9 @@ public class MainListener { } } } - Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap"); - if (entityCap != null) { - Integer cap = (Integer) entityCap.getValue(); + com.google.common.base.Optional entityCap = plot.getFlag(Flags.ENTITY_CAP); + if (entityCap.isPresent()) { + Integer cap = entityCap.get(); if (cap == 0) { return false; } @@ -356,8 +355,8 @@ public class MainListener { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { return; } else { - Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); - if (flag != null && ((HashSet) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) { + com.google.common.base.Optional> flag = plot.getFlag(Flags.USE); + if (flag.isPresent() && flag.get().contains(SpongeUtil.getPlotBlock(l.getBlock()))) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); @@ -396,22 +395,12 @@ public class MainListener { return; } } - if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { + if (!currentPlot.getFlag(Flags.EXPLOSION).or(false)) { event.filterAll(); return; } - event.filter(new Predicate>() { - @Override - public boolean test(org.spongepowered.api.world.Location loc) { - return currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()); - } - }); - event.filterEntities(new Predicate() { - @Override - public boolean test(Entity entity) { - return currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()); - } - }); + event.filter(loc -> currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot())); + event.filterEntities(entity -> currentPlot.equals(SpongeUtil.getLocation(entity).getPlot())); } } @@ -432,12 +421,7 @@ public class MainListener { event.setCancelled(true); return; } - event.filter(new Predicate>() { - @Override - public boolean test(org.spongepowered.api.world.Location loc) { - return !SpongeUtil.getLocation(worldName, loc).isPlotRoad(); - } - }); + event.filter(loc1 -> !SpongeUtil.getLocation(worldName, loc1).isPlotRoad()); } @Listener @@ -494,9 +478,9 @@ public class MainListener { return; } else { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); - Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); + com.google.common.base.Optional> destroy = plot.getFlag(Flags.BREAK); BlockState state = pos.getState(); - if (destroy == null || !((HashSet) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) { + if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) { event.setCancelled(true); return; } @@ -524,9 +508,9 @@ public class MainListener { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { return true; } else { - Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); + com.google.common.base.Optional> destroy = plot.getFlag(Flags.BREAK); BlockState state = l.getBlock(); - if (destroy != null && ((HashSet) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) { + if (destroy.isPresent() && destroy.get().contains(SpongeUtil.getPlotBlock(state))) { return true; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); @@ -563,7 +547,19 @@ public class MainListener { return; } } else if (transactions.size() == 1) { - if (!plot.hasOwner()) { + if (plot.hasOwner()) { + if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + return; + } else { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); + com.google.common.base.Optional> BUILD = plot.getFlag(Flags.PLACE); + BlockState state = pos.getState(); + if (!BUILD.isPresent() || !BUILD.get().contains(SpongeUtil.getPlotBlock(state))) { + event.setCancelled(true); + return; + } + } + } else { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } @@ -571,17 +567,6 @@ public class MainListener { event.setCancelled(true); return; } - if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { - return; - } else { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); - Flag BUILD = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); - BlockState state = pos.getState(); - if (BUILD == null || !((HashSet) BUILD.getValue()).contains(SpongeUtil.getPlotBlock(state))) { - event.setCancelled(true); - return; - } - } } event.filter(new Predicate>() { @@ -605,9 +590,9 @@ public class MainListener { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { return true; } else { - Flag build = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); + com.google.common.base.Optional> build = plot.getFlag(Flags.PLACE); BlockState state = l.getBlock(); - if (build != null && ((HashSet) build.getValue()).contains(SpongeUtil.getPlotBlock(state))) { + if (build.isPresent() && build.get().contains(SpongeUtil.getPlotBlock(state))) { return true; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java index 1a7abdf89..6481d7a56 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java @@ -22,7 +22,7 @@ public class SpongeChatManager extends ChatManager { } @Override - public void color(PlotMessage m, String color) { + public void color(PlotMessage message, String color) { TextColor tc = null; TextStyle ts = null; switch (color.charAt(1)) { @@ -94,10 +94,10 @@ public class SpongeChatManager extends ChatManager { break; } if (tc != null) { - apply(m, getChild(m).color(tc)); + apply(message, getChild(message).color(tc)); } if (ts != null) { - apply(m, getChild(m).style(ts)); + apply(message, getChild(message).style(ts)); } } @@ -114,7 +114,7 @@ public class SpongeChatManager extends ChatManager { } @Override - public void tooltip(PlotMessage m, PlotMessage... tooltips) { + public void tooltip(PlotMessage message, PlotMessage... tooltips) { Text.Builder builder = Text.builder(); boolean lb = false; for (PlotMessage tooltip : tooltips) { @@ -124,30 +124,30 @@ public class SpongeChatManager extends ChatManager { builder.append(tooltip.$(this).build()); lb = true; } - apply(m, getChild(m).onHover(TextActions.showText(builder.toText()))); + apply(message, getChild(message).onHover(TextActions.showText(builder.toText()))); } @Override - public void command(PlotMessage m, String command) { - apply(m, getChild(m).onClick(TextActions.runCommand(command))); + public void command(PlotMessage message, String command) { + apply(message, getChild(message).onClick(TextActions.runCommand(command))); } @Override - public void text(PlotMessage m, String text) { - m.$(this).append(SpongeUtil.getText(text)); + public void text(PlotMessage message, String text) { + message.$(this).append(SpongeUtil.getText(text)); } @Override - public void send(PlotMessage m, PlotPlayer player) { + public void send(PlotMessage plotMessage, PlotPlayer player) { if (player instanceof ConsolePlayer) { - player.sendMessage(m.$(this).build().toPlain()); + player.sendMessage(plotMessage.$(this).build().toPlain()); } else { - ((SpongePlayer) player).player.sendMessage(m.$(this).build()); + ((SpongePlayer) player).player.sendMessage(plotMessage.$(this).build()); } } @Override - public void suggest(PlotMessage m, String command) { - apply(m, getChild(m).onClick(TextActions.suggestCommand(command))); + public void suggest(PlotMessage plotMessage, String command) { + apply(plotMessage, getChild(plotMessage).onClick(TextActions.suggestCommand(command))); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java index 345125c6c..a9d7ff585 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java @@ -69,7 +69,7 @@ public class SpongeEventUtil extends EventUtil { } @Override - public boolean callFlagRemove(Flag flag, Plot plot) { + public boolean callFlagRemove(Flag flag, Plot plot, Object value) { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } @@ -109,7 +109,7 @@ public class SpongeEventUtil extends EventUtil { } @Override - public boolean callFlagRemove(Flag flag, PlotCluster cluster) { + public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) { return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); }