diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 804d0376e2..f43d13c8ca 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -343,7 +343,7 @@ public void onEnable() { try { plotSquared.setConfigurationVersion("v5"); } catch (final Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to update configuration version", e); } } } diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index bd017184fc..f58a26984a 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -1728,6 +1728,18 @@ public void setSQL(PreparedStatement stmt, Integer obj) throws SQLException { @Override public boolean convertFlags() { final Map> flagMap = new HashMap<>(); + try { + // only migrate flags, if plot_settings table has flags column + DatabaseMetaData metaData = this.connection.getMetaData(); + try (ResultSet rs = metaData.getColumns(null, null, this.prefix + "plot_settings", "flags")) { + if (!rs.next()) { + return true; + } + } + } catch (SQLException e) { + LOGGER.error("Failed to query table metadata", e); + return false; + } try (Statement statement = this.connection.createStatement()) { try (ResultSet resultSet = statement .executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { @@ -1742,11 +1754,10 @@ public boolean convertFlags() { if (element.contains(":")) { String[] split = element.split(":"); // splits flag:value try { - String flag_str = - split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); + String flag_str = split[1].replace("¯", ":").replace("´", ","); flagMap.get(id).put(split[0], flag_str); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to migrate flag value", e); } } } @@ -1759,8 +1770,7 @@ public boolean convertFlags() { LOGGER.info("Loaded {} plot flag collections...", flagMap.size()); LOGGER.info("Attempting to store these flags in the new table..."); try (final PreparedStatement preparedStatement = this.connection.prepareStatement( - "INSERT INTO `" + SQLManager.this.prefix - + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) { + "INSERT INTO `" + this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) { long timeStarted = System.currentTimeMillis(); int flagsProcessed = 0; @@ -1785,23 +1795,18 @@ public boolean convertFlags() { try { preparedStatement.executeBatch(); } catch (final Exception e) { - LOGGER.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey()); - e.printStackTrace(); + LOGGER.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey(), e); continue; } - if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap - .size()) { + if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap.size()) { timeStarted = System.currentTimeMillis(); LOGGER.info( "... Flag conversion in progress. {}% done", String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100) ); } - LOGGER.info( - "- Finished converting flags for plot with entry ID: {}", - plotFlagEntry.getKey() - ); + LOGGER.info("- Finished converting flags for plot with entry ID: {}", plotFlagEntry.getKey()); } } catch (final Exception e) { LOGGER.error("Failed to store flag values", e);