Experimental PlotMe UUID cache

This commit is contained in:
boy0001 2015-03-31 23:14:38 +11:00
parent 86a7974f84
commit 7b96bdd907
5 changed files with 61 additions and 6 deletions

View File

@ -514,7 +514,7 @@ public class PlotSquared {
// Set chunk // Set chunk
ChunkManager.manager = IMP.initChunkManager(); ChunkManager.manager = IMP.initChunkManager();
// PlotMe // PlotMe
if (Settings.CONVERT_PLOTME) { if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) {
TaskManager.runTaskLater(new Runnable() { TaskManager.runTaskLater(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -773,6 +773,7 @@ public class PlotSquared {
options.put("clear.fastmode", Settings.ENABLE_CLUSTERS); options.put("clear.fastmode", Settings.ENABLE_CLUSTERS);
options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); options.put("plotme-alias", Settings.USE_PLOTME_ALIAS);
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME); 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("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
options.put("UUID.offline", Settings.OFFLINE_MODE); options.put("UUID.offline", Settings.OFFLINE_MODE);
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); 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.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login");
Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias"); Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias");
Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled"); 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.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf" + "inding"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf" + "inding");
Settings.METRICS = config.getBoolean("metrics"); Settings.METRICS = config.getBoolean("metrics");

View File

@ -39,6 +39,7 @@ public class Settings {
* *
*/ */
public static boolean CONVERT_PLOTME = true; public static boolean CONVERT_PLOTME = true;
public static boolean CACHE_PLOTME = false;
public static boolean USE_PLOTME_ALIAS = false; public static boolean USE_PLOTME_ALIAS = false;
/** /**
* *

View File

@ -20,6 +20,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -53,7 +56,28 @@ public class DBFunc {
public static void movePlot(final Plot originalPlot, final Plot newPlot) { public static void movePlot(final Plot originalPlot, final Plot newPlot) {
dbManager.movePlot(originalPlot, 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 * Set the owner of a plot
* *

View File

@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.database;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.Blob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -39,9 +40,11 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -96,6 +99,9 @@ public class PlotMeConverter {
stmt = connection.createStatement(); stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
// TODO check if r contains UUID collumn -> assign var // TODO check if r contains UUID collumn -> assign var
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
while (r.next()) { while (r.next()) {
count++; count++;
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
@ -110,15 +116,36 @@ public class PlotMeConverter {
if (owner == null) { if (owner == null) {
if (name.equals("*")) { if (name.equals("*")) {
owner = DBFunc.everyone; owner = DBFunc.everyone;
} else { }
// TODO check PlotMe table for UUID else {
sendMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); if (checkUUID){
continue; 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<UUID>(), new ArrayList<UUID>(), world); final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot); plots.get(world).put(id, plot);
} }
if (!Settings.CONVERT_PLOTME) {
return;
}
sendMessage(" - plotmeAllowed"); sendMessage(" - plotmeAllowed");
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) { while (r.next()) {

View File

@ -214,6 +214,7 @@ public abstract class SchematicHandler {
} }
try { try {
final File tmp = new File(path); final File tmp = new File(path);
System.out.print("ABS: " + tmp.getAbsolutePath());
tmp.getParentFile().mkdirs(); tmp.getParentFile().mkdirs();
final OutputStream stream = new FileOutputStream(path); final OutputStream stream = new FileOutputStream(path);
final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream)); final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));