From 5601315c41f4514e09ef6cc4e8b3eee8a592ff6f Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 23 Sep 2014 15:58:30 +1000 Subject: [PATCH] forgot to save to DB. --- .../com/intellectualcrafters/plot/Flag.java | 2 +- .../intellectualcrafters/plot/PlotMain.java | 4 +++ .../plot/PlotSettings.java | 13 +++---- .../plot/commands/Info.java | 2 +- .../plot/commands/Set.java | 8 +++-- .../plot/database/DBFunc.java | 34 +++++++++---------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java index 9558984a9..c967d18e3 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -35,7 +35,7 @@ public class Flag { if (getClass() != obj.getClass()) return false; Flag other = (Flag) obj; - return (this.key==other.key); + return (this.key==other.key && this.value == other.value); } @Override public int hashCode() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 5899739c4..54f10875c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -144,6 +144,10 @@ public class PlotMain extends JavaPlugin { return registeredFlags.add(flag); } + public static boolean unRegisterFlag(Flag flag) { + return registeredFlags.remove(flag); + } + /** * Get all plots * diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index f44c27c8f..b6ab2d9ff 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -133,6 +133,9 @@ public class PlotSettings { * @param flag */ public void addFlag(Flag flag) { + Flag hasFlag = getFlag(flag.getKey()); + if (hasFlag!=null) + flags.remove(hasFlag); this.flags.add(flag); } /** @@ -156,19 +159,11 @@ public class PlotSettings { */ public Flag getFlag(String flag) { for (Flag myflag:flags) { - if (myflag.getKey()==flag) + if (myflag.getKey().equals(flag)) return myflag; } return null; } - /** - * - * @param flag - * @return - */ - public boolean hasFlag(Flag flag) { - return this.flags.contains(flag); - } public PlotHomePosition getPosition() { return this.position; } public void setPosition(PlotHomePosition position) { this.position = position; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index f57539b7c..acffffa5a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -78,7 +78,7 @@ public class Info extends SubCommand{ info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default"); info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); info = info.replaceAll("%denied%", getPlayerList(plot.denied)); - info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(),"").length() > 0 ? StringUtils.join(plot.settings.getFlags(),"") : "none"); + info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(),"").length() > 0 ? StringUtils.join(plot.settings.getFlags(),",") : "none"); PlayerFunctions.sendMessage(player, info); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 05d27d76a..fe59e3c0c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -96,7 +96,7 @@ public class Set extends SubCommand{ return false; } if (args.length==2) { - if (!plot.settings.hasFlag(new Flag(args[1], ""))) { + if (plot.settings.getFlag(args[1].toLowerCase())==null) { PlayerFunctions.sendMessage(plr, C.FLAG_NOT_IN_PLOT); return false; } @@ -109,8 +109,11 @@ public class Set extends SubCommand{ return false; } java.util.Set newflags = plot.settings.getFlags(); - newflags.remove(flag); + Flag oldFlag = plot.settings.getFlag(args[1].toLowerCase()); + if (oldFlag!=null) + newflags.remove(oldFlag); plot.settings.setFlags(newflags.toArray(new Flag[0])); + DBFunc.setFlags(plr.getWorld().getName(), plot, newflags.toArray(new Flag[0])); PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED); return true; } @@ -125,6 +128,7 @@ public class Set extends SubCommand{ return false; } plot.settings.addFlag(flag); + DBFunc.setFlags(plr.getWorld().getName(), plot, plot.settings.getFlags().toArray(new Flag[0])); PlayerFunctions.sendMessage(plr, C.FLAG_ADDED); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 76e47a1fc..988402bdd 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -150,23 +150,23 @@ public class DBFunc { /** * `plot` */ - int target_len = 6; - ArrayList ids = new ArrayList(); - stmt = connection.createStatement(); - String table = "plot"; - ResultSet rs = stmt.executeQuery("SELECT * FROM `"+table+"`"); - ResultSetMetaData md = rs.getMetaData(); - int len = md.getColumnCount(); - if (len cols = new HashSet(); - for (int i = 1; i <= len; i++) { - cols.add(md.getColumnName(i)); - } - while (rs.next()) { - ids.add(rs.getString("plot_id")); - } - } - stmt.close(); +// int target_len = 6; +// ArrayList ids = new ArrayList(); +// stmt = connection.createStatement(); +// String table = "plot"; +// ResultSet rs = stmt.executeQuery("SELECT * FROM `"+table+"`"); +// ResultSetMetaData md = rs.getMetaData(); +// int len = md.getColumnCount(); +// if (len cols = new HashSet(); +// for (int i = 1; i <= len; i++) { +// cols.add(md.getColumnName(i)); +// } +// while (rs.next()) { +// ids.add(rs.getString("plot_id")); +// } +// } +// stmt.close(); } /**