From 4475290443fe5ace3d4e68b78a59a7a052e88772 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 30 Jan 2015 10:49:00 +1100 Subject: [PATCH] Fixed flag system --- .../plot/commands/FlagCmd.java | 21 +++++++++++++------ .../plot/commands/MainCommand.java | 2 +- .../plot/database/PlotMeConverter.java | 4 ++-- .../plot/database/SQLManager.java | 2 +- .../plot/object/PlotBlock.java | 5 +++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index b76ede213..038797a82 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -30,6 +30,7 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.PlotMain; 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; @@ -110,7 +111,7 @@ public class FlagCmd extends SubCommand { PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove"); return false; } - if (args.length != 3) { + if (args.length != 2 && args.length != 3) { PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove [values]"); return false; } @@ -128,10 +129,17 @@ public class FlagCmd extends SubCommand { PlayerFunctions.sendMessage(player, C.FLAG_NOT_IN_PLOT); return false; } - boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); - if (!result) { - PlayerFunctions.sendMessage(player, C.FLAG_NOT_REMOVED); - return false; + if (args.length == 3 && flag.getAbstractFlag().isList()) { + String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); + ((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value); + DBFunc.setFlags(plot.world, plot, plot.settings.flags); + } + else { + boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); + if (!result) { + PlayerFunctions.sendMessage(player, C.FLAG_NOT_REMOVED); + return false; + } } PlayerFunctions.sendMessage(player, C.FLAG_REMOVED); PlotListener.plotEntry(player, plot); @@ -166,13 +174,14 @@ public class FlagCmd extends SubCommand { flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); } else { - ((FlagValue.ListValue) flag.getValue()).add(flag.getValue(), value); + ((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value); } boolean result = FlagManager.addPlotFlag(plot, flag); if (!result) { PlayerFunctions.sendMessage(player, C.FLAG_NOT_ADDED); return false; } + DBFunc.setFlags(plot.world, plot, plot.settings.flags); PlayerFunctions.sendMessage(player, C.FLAG_ADDED); PlotListener.plotEntry(player, plot); return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 13db88bc8..61fb62acd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -49,7 +49,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { */ public static final String MAIN_PERMISSION = "plots.use"; - private final static SubCommand[] _subCommands = new SubCommand[]{new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec()}; + private final static SubCommand[] _subCommands = new SubCommand[]{new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd()}; public final static ArrayList subCommands = new ArrayList() { { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index e62f5695d..467cf893d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -78,14 +78,14 @@ public class PlotMeConverter { @Override public void run() { try { - sendMessage("Conversion has started"); - sendMessage("Connecting to PlotMe DB"); final ArrayList createdPlots = new ArrayList<>(); final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; final File plotMeFile = new File(dataFolder + "config.yml"); if (!plotMeFile.exists()) { return; } + sendMessage("Conversion has started"); + sendMessage("Connecting to PlotMe DB"); final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); int count = 0; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 6f9060443..da85580c7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -704,7 +704,7 @@ public class SQLManager implements AbstractDB { if (element.contains(":")) { final String[] split = element.split(":"); try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); + String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str); flags.add(flag); } catch (final Exception e) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java index 3ff42ffb4..1e390dc30 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java @@ -52,4 +52,9 @@ public class PlotBlock { public int hashCode() { return (id + data) * (id + data + 1) + data; } + + @Override + public String toString() { + return this.id + ":" + this.data; + } }