diff --git a/pom.xml b/pom.xml
index 484169215..6065b38f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
UTF-8
PlotSquared
- 3.1.6
+ 3.1.7
PlotSquared
jar
diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java
index f400b5077..bcff67c15 100644
--- a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java
+++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java
@@ -22,9 +22,13 @@ package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
@@ -40,6 +44,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
+import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
@@ -69,8 +74,8 @@ public class DebugUUID extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
PlotPlayer player = null;
- UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
- UUIDWrapper newWrapper = null;
+ final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
+ final UUIDWrapper newWrapper;
switch (args[0].toLowerCase()) {
case "lower": {
@@ -121,8 +126,8 @@ public class DebugUUID extends SubCommand {
MainUtil.sendConsoleMessage("&7 - Initializing map");
- HashMap uCMap = new HashMap();
- HashMap uCReverse = new HashMap();
+ final HashMap uCMap = new HashMap();
+ final HashMap uCReverse = new HashMap();
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
@@ -172,7 +177,7 @@ public class DebugUUID extends SubCommand {
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
- if (!uuid.equals(uuid2)) {
+ if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
@@ -192,8 +197,8 @@ public class DebugUUID extends SubCommand {
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) {
- String name = op.getName();
- StringWrapper wrap = new StringWrapper(name);
+// String name = op.getName();
+// StringWrapper wrap = new StringWrapper(name);
UUID uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
if (!uuid.equals(uuid2)) {
@@ -212,92 +217,135 @@ public class DebugUUID extends SubCommand {
}
MainUtil.sendConsoleMessage("&7 - Replacing cache");
- for (Entry entry : uCMap.entrySet()) {
- String name = UUIDHandler.getName(entry.getKey());
- UUIDHandler.add(new StringWrapper(name), entry.getValue());
- }
-
- MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
- UUIDHandler.setUUIDWrapper(newWrapper);
-
- MainUtil.sendConsoleMessage("&7 - Updating plot objects");
-
- for (Plot plot : PS.get().getPlotsRaw()) {
- UUID value = uCMap.get(plot.owner);
- if (value != null) {
- plot.owner = value;
- }
- plot.getTrusted().clear();
- plot.getMembers().clear();
- plot.getDenied().clear();
- }
-
- MainUtil.sendConsoleMessage("&7 - Deleting database");
- final AbstractDB database = DBFunc.dbManager;
- boolean result = database.deleteTables();
-
- MainUtil.sendConsoleMessage("&7 - Creating tables");
-
- try {
- database.createTables();
- if (!result) {
- MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
- for (Plot plot : PS.get().getPlots()) {
- UUID value = uCReverse.get(plot.owner);
- if (value != null) {
- plot.owner = value;
- }
- }
- database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
- @Override
- public void run() {
- MainUtil.sendMessage(null, "&6Recovery was successful!");
- }
- });
- return false;
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
- if (newWrapper instanceof OfflineUUIDWrapper) {
- PS.get().config.set("UUID.force-lowercase", false);
- PS.get().config.set("UUID.offline", true);
- }
- else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
- PS.get().config.set("UUID.force-lowercase", true);
- PS.get().config.set("UUID.offline", true);
- }
- else if (newWrapper instanceof DefaultUUIDWrapper) {
- PS.get().config.set("UUID.force-lowercase", false);
- PS.get().config.set("UUID.offline", false);
- }
- try {
- PS.get().config.save(PS.get().configFile);
- }
- catch (Exception e) {
- MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
- }
-
- MainUtil.sendConsoleMessage("&7 - Populating tables");
-
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
- ArrayList plots = new ArrayList<>(PS.get().getPlots());
- database.createPlotsAndData(plots, new Runnable() {
+ for (Entry entry : uCMap.entrySet()) {
+ String name = UUIDHandler.getName(entry.getKey());
+ if (name != null) {
+ UUIDHandler.add(new StringWrapper(name), entry.getValue());
+ }
+ }
+
+ MainUtil.sendConsoleMessage("&7 - Scanning for applicable files (uuids.txt)");
+
+ File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
+ if (file.exists()) {
+ try {
+ List lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
+ for (String line : lines) {
+ try {
+ line = line.trim();
+ if (line.length() == 0) {
+ continue;
+ }
+ line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
+ String[] split = line.split("\\|");
+ String name = split[0];
+ if (name.length() == 0 || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
+ continue;
+ }
+ UUID old = currentUUIDWrapper.getUUID(name);
+ if (old == null) {
+ continue;
+ }
+ UUID now = newWrapper.getUUID(name);
+ UUIDHandler.add(new StringWrapper(name), now);
+ uCMap.put(old, now);
+ uCReverse.put(now, old);
+ }
+ catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
+ UUIDHandler.setUUIDWrapper(newWrapper);
+
+ MainUtil.sendConsoleMessage("&7 - Updating plot objects");
+
+ for (Plot plot : PS.get().getPlotsRaw()) {
+ UUID value = uCMap.get(plot.owner);
+ if (value != null) {
+ plot.owner = value;
+ }
+ plot.getTrusted().clear();
+ plot.getMembers().clear();
+ plot.getDenied().clear();
+ }
+
+ MainUtil.sendConsoleMessage("&7 - Deleting database");
+ final AbstractDB database = DBFunc.dbManager;
+ boolean result = database.deleteTables();
+
+ MainUtil.sendConsoleMessage("&7 - Creating tables");
+
+ try {
+ database.createTables();
+ if (!result) {
+ MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
+ for (Plot plot : PS.get().getPlots()) {
+ UUID value = uCReverse.get(plot.owner);
+ if (value != null) {
+ plot.owner = value;
+ }
+ }
+ database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
+ @Override
+ public void run() {
+ MainUtil.sendMessage(null, "&6Recovery was successful!");
+ }
+ });
+ return;
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+
+ if (newWrapper instanceof OfflineUUIDWrapper) {
+ PS.get().config.set("UUID.force-lowercase", false);
+ PS.get().config.set("UUID.offline", true);
+ }
+ else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
+ PS.get().config.set("UUID.force-lowercase", true);
+ PS.get().config.set("UUID.offline", true);
+ }
+ else if (newWrapper instanceof DefaultUUIDWrapper) {
+ PS.get().config.set("UUID.force-lowercase", false);
+ PS.get().config.set("UUID.offline", false);
+ }
+ try {
+ PS.get().config.save(PS.get().configFile);
+ }
+ catch (Exception e) {
+ MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
+ }
+
+ MainUtil.sendConsoleMessage("&7 - Populating tables");
+
+ TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
- MainUtil.sendConsoleMessage("&aConversion complete!");
+ ArrayList plots = new ArrayList<>(PS.get().getPlots());
+ database.createPlotsAndData(plots, new Runnable() {
+ @Override
+ public void run() {
+ MainUtil.sendConsoleMessage("&aConversion complete!");
+ }
+ });
}
});
+
+ MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
+ MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete");
}
});
-
- MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
- MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete");
return true;
}
}
diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
index 9b21c78de..2305b9076 100644
--- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
+++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
@@ -439,7 +439,7 @@ public class SQLManager implements AbstractDB {
}
}
}
- }
+ }
}
createSettings(settings, new Runnable() {
@Override
@@ -977,10 +977,13 @@ public class SQLManager implements AbstractDB {
final DatabaseMetaData meta = connection.getMetaData();
int create = 0;
for (final String s : tables) {
- ResultSet set = meta.getTables(null, null, prefix + s, null);
+ ResultSet set = meta.getTables(null, null, prefix + s, new String[] {"TABLE"});
+// ResultSet set = meta.getTables(null, null, prefix + s, null);
if (!set.next()) {
create++;
}
+ else {
+ }
set.close();
}
if (create == 0) {
@@ -2390,34 +2393,30 @@ public class SQLManager implements AbstractDB {
@Override
public boolean deleteTables() {
- addGlobalTask(new Runnable() {
- @Override
- public void run() {
- try {
- close();
- SQLManager.this.connection = database.forceConnection();
- final Statement stmt = connection.createStatement();
- stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
- stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");
- stmt.addBatch("DROP TABLE `" + prefix + "cluster`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_rating`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_settings`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_comments`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_trusted`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_helpers`");
- stmt.addBatch("DROP TABLE `" + prefix + "plot_denied`");
- stmt.executeBatch();
- stmt.clearBatch();
- stmt.close();
-
- PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
+ try {
+ close();
+ CLOSED = false;
+ SQLManager.this.connection = database.forceConnection();
+ final Statement stmt = connection.createStatement();
+ stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
+ stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");
+ stmt.addBatch("DROP TABLE `" + prefix + "cluster`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_rating`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_settings`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_comments`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_trusted`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_helpers`");
+ stmt.addBatch("DROP TABLE `" + prefix + "plot_denied`");
+ stmt.executeBatch();
+ stmt.clearBatch();
+ stmt.close();
+
+ PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`");
+ statement.executeUpdate();
+ statement.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
return true;
}
diff --git a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java
index 6e9b15b6f..3cbce1adb 100644
--- a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java
+++ b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java
@@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.util;
import java.util.ArrayDeque;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS;
@@ -89,7 +90,11 @@ public class SetBlockQueue {
if (locked) {
return;
}
- Entry n = blocks.entrySet().iterator().next();
+ Iterator> iter = blocks.entrySet().iterator();
+ if (!iter.hasNext()) {
+ return;
+ }
+ Entry n = iter.next();
ChunkWrapper chunk = n.getKey();
PlotBlock[][] blocks = n.getValue();
int X = chunk.x << 4;
diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java
index 5e2d9116b..0bf0127f2 100644
--- a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java
+++ b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java
@@ -113,6 +113,16 @@ public class StringMan {
return true;
}
+ public static boolean isAlphanumericUnd(String str) {
+ for (int i=0; i= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a || c == '_') {
+ return false;
+ }
+ }
+ return true;
+ }
+
public static boolean isAlpha(String str) {
for (int i=0; i inverse = uuidMap.inverse();
- if (inverse.containsKey(uuid)) {
- if (uuidMap.containsKey(name)) {
+ try {
+ uuidMap.put(name, uuid);
+ }
+ catch (Exception e) {
+ BiMap inverse = uuidMap.inverse();
+ if (inverse.containsKey(uuid)) {
+ if (uuidMap.containsKey(name)) {
+ return false;
+ }
+ rename(uuid, name);
return false;
}
- rename(uuid, name);
- return false;
+ uuidMap.put(name, uuid);
}
- uuidMap.put(name, uuid);
return true;
}
diff --git a/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java b/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java
index 920c60d8f..dcc6ad52d 100644
--- a/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java
+++ b/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java
@@ -3,6 +3,9 @@ package com.plotsquared.bukkit.uuid;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -12,7 +15,6 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import com.google.common.collect.HashBiMap;
-import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
@@ -23,6 +25,7 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.NbtFactory;
+import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
@@ -56,6 +59,36 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
@Override
public void run() {
PS.debug(C.PREFIX.s() + "&6Starting player data caching for: " + world);
+ File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
+ if (uuidfile.exists()) {
+ try {
+ List lines = Files.readAllLines(uuidfile.toPath(), StandardCharsets.UTF_8);
+ for (String line : lines) {
+ try {
+ line = line.trim();
+ if (line.length() == 0) {
+ continue;
+ }
+ line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
+ String[] split = line.split("\\|");
+ String name = split[0];
+ if (name.length() == 0 || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
+ continue;
+ }
+ UUID uuid = uuidWrapper.getUUID(name);
+ if (uuid == null) {
+ continue;
+ }
+ UUIDHandler.add(new StringWrapper(name), uuid);
+ }
+ catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
if (Settings.TWIN_MODE_UUID) {
final HashBiMap toAdd = HashBiMap.create(new HashMap());
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
@@ -76,7 +109,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
UUID uuid = UUID.fromString(s);
if (check || all.remove(uuid)) {
File file = new File(playerdataFolder + File.separator + current);
- InputSupplier is = Files.newInputStreamSupplier(file);
+ InputSupplier is = com.google.common.io.Files.newInputStreamSupplier(file);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
@@ -146,7 +179,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
for (UUID uuid : uuids) {
try {
File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
- InputSupplier is = Files.newInputStreamSupplier(file);
+ InputSupplier is = com.google.common.io.Files.newInputStreamSupplier(file);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar
index 3275a4135..efefce606 100644
Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ
diff --git a/target/PlotSquared-Sponge.jar b/target/PlotSquared-Sponge.jar
index bedcddfe7..b0c31bc4f 100644
Binary files a/target/PlotSquared-Sponge.jar and b/target/PlotSquared-Sponge.jar differ