From 7b96bdd9077cf5f68c53776c61d9374a6aabb50a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 31 Mar 2015 23:14:38 +1100 Subject: [PATCH] Experimental PlotMe UUID cache --- .../plot/PlotSquared.java | 4 ++- .../plot/config/Settings.java | 1 + .../plot/database/DBFunc.java | 26 +++++++++++++- .../plot/database/PlotMeConverter.java | 35 ++++++++++++++++--- .../plot/util/SchematicHandler.java | 1 + 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 4138a6ef0..7be29b885 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -514,7 +514,7 @@ public class PlotSquared { // Set chunk ChunkManager.manager = IMP.initChunkManager(); // PlotMe - if (Settings.CONVERT_PLOTME) { + if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { TaskManager.runTaskLater(new Runnable() { @Override public void run() { @@ -773,6 +773,7 @@ public class PlotSquared { options.put("clear.fastmode", Settings.ENABLE_CLUSTERS); options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME); + options.put("plotme-convert.cache-uuids", Settings.CACHE_PLOTME); options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); options.put("UUID.offline", Settings.OFFLINE_MODE); options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); @@ -815,6 +816,7 @@ public class PlotSquared { Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login"); Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias"); Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled"); + Settings.CACHE_PLOTME = config.getBoolean("plotme-convert.cache-uuids"); Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf" + "inding"); Settings.METRICS = config.getBoolean("metrics"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 6b62fdb4e..f1bbd125f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -39,6 +39,7 @@ public class Settings { * */ public static boolean CONVERT_PLOTME = true; + public static boolean CACHE_PLOTME = false; public static boolean USE_PLOTME_ALIAS = false; /** * diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index c43509403..3261d51f7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -20,6 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.database; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -53,7 +56,28 @@ public class DBFunc { public static void movePlot(final Plot originalPlot, final Plot newPlot) { dbManager.movePlot(originalPlot, newPlot); } - + /** + * Check if a resultset contains a column + * @param rs + * @param columnName + * @return + * @throws SQLException + */ + public static boolean hasColumn(ResultSet r, String name) { + try { + ResultSetMetaData meta = r.getMetaData(); + int count = meta.getColumnCount(); + for (int x = 1; x <= count; x++) { + if (name.equals(meta.getColumnName(x))) { + return true; + } + } + return false; + } + catch (SQLException e) { + return false; + } + } /** * Set the owner of a plot * 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 6cde2cfe9..7832f3100 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.database; import java.io.File; import java.io.IOException; +import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -39,9 +40,11 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -96,6 +99,9 @@ public class PlotMeConverter { stmt = connection.createStatement(); r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); // TODO check if r contains UUID collumn -> assign var + + boolean checkUUID = DBFunc.hasColumn(r, "ownerid"); + while (r.next()) { count++; final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); @@ -110,15 +116,36 @@ public class PlotMeConverter { if (owner == null) { if (name.equals("*")) { owner = DBFunc.everyone; - } else { - // TODO check PlotMe table for UUID - sendMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); - continue; + } + else { + if (checkUUID){ + try { + byte[] bytes = r.getBytes("ownerid"); + if (bytes != null) { + owner = UUID.nameUUIDFromBytes(bytes); + if (owner != null) { + UUIDHandler.add(new StringWrapper(name), owner); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + if (owner == null) { + sendMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); + continue; + } } } final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), world); plots.get(world).put(id, plot); } + + if (!Settings.CONVERT_PLOTME) { + return; + } + sendMessage(" - plotmeAllowed"); r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); while (r.next()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index ce35aab44..ff82d9fe3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -214,6 +214,7 @@ public abstract class SchematicHandler { } try { final File tmp = new File(path); + System.out.print("ABS: " + tmp.getAbsolutePath()); tmp.getParentFile().mkdirs(); final OutputStream stream = new FileOutputStream(path); final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));