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
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");

View File

@ -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;
/**
*

View File

@ -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
*

View File

@ -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<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot);
}
if (!Settings.CONVERT_PLOTME) {
return;
}
sendMessage(" - plotmeAllowed");
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) {

View File

@ -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));