From 3be0f7449818c09d5c58ea00cbca70e4a77d1b77 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Tue, 10 May 2016 13:41:59 -0400 Subject: [PATCH] Fix #1098 --- .../plot/database/SQLManager.java | 58 ++++++++++--------- .../plot/flag/FlagManager.java | 15 +++++ .../plot/generator/HybridPlotWorld.java | 2 +- .../plot/object/BlockLoc.java | 2 +- 4 files changed, 47 insertions(+), 30 deletions(-) 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 e0199104d..400820b36 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -733,17 +733,13 @@ public class SQLManager implements AbstractDB { e.printStackTrace(); PS.debug("&cERROR 2: | " + objList.get(0).getClass().getCanonicalName()); PS.debug("&6[WARN] Could not bulk save!"); - try { - String nonBulk = mod.getCreateSQL(); - try (PreparedStatement preparedStmt = this.connection.prepareStatement(nonBulk)) { - for (T obj : objList) { - mod.setSQL(preparedStmt, obj); - preparedStmt.addBatch(); - } - PS.debug("&aBatch 3"); - preparedStmt.executeBatch(); - preparedStmt.close(); + try (PreparedStatement preparedStmt = this.connection.prepareStatement(mod.getCreateSQL())) { + for (T obj : objList) { + mod.setSQL(preparedStmt, obj); + preparedStmt.addBatch(); } + PS.debug("&aBatch 3"); + preparedStmt.executeBatch(); } catch (SQLException e3) { e3.printStackTrace(); PS.debug("&c[ERROR] Failed to save all!"); @@ -1819,9 +1815,13 @@ public class SQLManager implements AbstractDB { if (element.contains(":")) { String[] split = element.split(":"); try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - Flag flag = FlagManager.getFlag(split[0]); - flags.put(flag, flag.parseValue(flag_str)); + String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); + Flag flag = FlagManager.getFlag(split[0],false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", split[0])); + } else { + flags.put(flag, flag.parseValue(flag_str)); + } } catch (Exception e) { e.printStackTrace(); exception = true; @@ -1829,8 +1829,12 @@ public class SQLManager implements AbstractDB { } else { element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, flag.parseValue("")); + Flag flag = FlagManager.getFlag(element,false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", element)); + } else { + flags.put(flag, flag.parseValue("")); + } } else { PS.debug("INVALID FLAG: " + element); } @@ -2624,27 +2628,25 @@ public class SQLManager implements AbstractDB { flags_string = myflags.split(","); } 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 = FlagManager.getFlag(split[0]); + String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); + Flag flag = FlagManager.getFlag(split[0],false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", split[0])); + } else { flags.put(flag, flag.parseValue(flag_str)); - } catch (Exception e) { - e.printStackTrace(); - exception = true; } } else { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, flag.parseValue("")); + Flag flag = FlagManager.getFlag(element,false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", element)); + } else { + flags.put(flag, flag.parseValue("")); + } } } - if (exception) { - PS.debug("&cCluster " + id + " had an invalid flag. A fix has been attempted."); - PS.debug("&c" + myflags); - } cluster.settings.flags = flags; } else { PS.debug("&cCluster " + id + " in cluster_settings does not exist. Please create the cluster or remove this entry."); 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 c099af9b0..27ce607b9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -257,6 +257,21 @@ public class FlagManager { return null; } + public static Flag getFlag(String string, boolean ignoreReserved) { + for (Flag flag : Flags.getFlags()) { + if (flag.getName().equalsIgnoreCase(string)) { + if (!ignoreReserved) { + if (isReserved(flag)) { + return null; + } + } + return flag; + } + } + return null; + } + + public static Map, Object> parseFlags(List flagstrings) { HashMap, Object> map = new HashMap<>(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index 2f4294475..267e36750 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -158,7 +158,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } try { setupSchematics(); - } catch (Exception e) { + } catch (Exception ignored) { PS.debug("&c - road schematics are disabled for this world."); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java index e3e310609..32f029d8d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java @@ -74,7 +74,7 @@ public class BlockLoc { if (this.x == 0 && this.y == 0 && this.z == 0) { return ""; } - return this.x + "," + this.y + "," + this.z + "," + this.yaw + "," + this.pitch; + return this.x + "," + this.y + ',' + this.z + ',' + this.yaw + ',' + this.pitch; } }