mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Offline uuid from flat file.
This commit is contained in:
parent
1872e147cb
commit
3229705012
2
pom.xml
2
pom.xml
@ -8,7 +8,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>PlotSquared</artifactId>
|
<artifactId>PlotSquared</artifactId>
|
||||||
<version>3.1.6</version>
|
<version>3.1.7</version>
|
||||||
<name>PlotSquared</name>
|
<name>PlotSquared</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
|
@ -22,9 +22,13 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
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.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
@ -69,8 +74,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
PlotPlayer player = null;
|
PlotPlayer player = null;
|
||||||
|
|
||||||
UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||||
UUIDWrapper newWrapper = null;
|
final UUIDWrapper newWrapper;
|
||||||
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "lower": {
|
case "lower": {
|
||||||
@ -121,8 +126,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Initializing map");
|
MainUtil.sendConsoleMessage("&7 - Initializing map");
|
||||||
|
|
||||||
HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
|
final HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
|
||||||
HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
|
final HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
|
||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
|
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
|
||||||
|
|
||||||
@ -172,7 +177,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||||
uuid = currentUUIDWrapper.getUUID(op);
|
uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2)) {
|
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
@ -192,8 +197,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
|
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
|
||||||
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||||
if (op.getLastPlayed() != 0) {
|
if (op.getLastPlayed() != 0) {
|
||||||
String name = op.getName();
|
// String name = op.getName();
|
||||||
StringWrapper wrap = new StringWrapper(name);
|
// StringWrapper wrap = new StringWrapper(name);
|
||||||
UUID uuid = currentUUIDWrapper.getUUID(op);
|
UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2)) {
|
if (!uuid.equals(uuid2)) {
|
||||||
@ -212,10 +217,51 @@ public class DebugUUID extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||||
String name = UUIDHandler.getName(entry.getKey());
|
String name = UUIDHandler.getName(entry.getKey());
|
||||||
|
if (name != null) {
|
||||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
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<String> 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");
|
MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
|
||||||
UUIDHandler.setUUIDWrapper(newWrapper);
|
UUIDHandler.setUUIDWrapper(newWrapper);
|
||||||
@ -254,12 +300,12 @@ public class DebugUUID extends SubCommand {
|
|||||||
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||||
@ -298,6 +344,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
|
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("&cConversion is still in progress, you will be notified when it is complete");
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,10 +977,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
final DatabaseMetaData meta = connection.getMetaData();
|
final DatabaseMetaData meta = connection.getMetaData();
|
||||||
int create = 0;
|
int create = 0;
|
||||||
for (final String s : tables) {
|
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()) {
|
if (!set.next()) {
|
||||||
create++;
|
create++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
set.close();
|
set.close();
|
||||||
}
|
}
|
||||||
if (create == 0) {
|
if (create == 0) {
|
||||||
@ -2390,11 +2393,9 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteTables() {
|
public boolean deleteTables() {
|
||||||
addGlobalTask(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
close();
|
close();
|
||||||
|
CLOSED = false;
|
||||||
SQLManager.this.connection = database.forceConnection();
|
SQLManager.this.connection = database.forceConnection();
|
||||||
final Statement stmt = connection.createStatement();
|
final Statement stmt = connection.createStatement();
|
||||||
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
|
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
|
||||||
@ -2416,8 +2417,6 @@ public class SQLManager implements AbstractDB {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.util;
|
|||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
@ -89,7 +90,11 @@ public class SetBlockQueue {
|
|||||||
if (locked) {
|
if (locked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entry<ChunkWrapper, PlotBlock[][]> n = blocks.entrySet().iterator().next();
|
Iterator<Entry<ChunkWrapper, PlotBlock[][]>> iter = blocks.entrySet().iterator();
|
||||||
|
if (!iter.hasNext()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entry<ChunkWrapper, PlotBlock[][]> n = iter.next();
|
||||||
ChunkWrapper chunk = n.getKey();
|
ChunkWrapper chunk = n.getKey();
|
||||||
PlotBlock[][] blocks = n.getValue();
|
PlotBlock[][] blocks = n.getValue();
|
||||||
int X = chunk.x << 4;
|
int X = chunk.x << 4;
|
||||||
|
@ -113,6 +113,16 @@ public class StringMan {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAlphanumericUnd(String str) {
|
||||||
|
for (int i=0; i<str.length(); i++) {
|
||||||
|
char c = str.charAt(i);
|
||||||
|
if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a || c == '_') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAlpha(String str) {
|
public static boolean isAlpha(String str) {
|
||||||
for (int i=0; i<str.length(); i++) {
|
for (int i=0; i<str.length(); i++) {
|
||||||
char c = str.charAt(i);
|
char c = str.charAt(i);
|
||||||
|
@ -90,6 +90,10 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
if ((uuid == null) || (name == null)) {
|
if ((uuid == null) || (name == null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
uuidMap.put(name, uuid);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
|
BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
|
||||||
if (inverse.containsKey(uuid)) {
|
if (inverse.containsKey(uuid)) {
|
||||||
if (uuidMap.containsKey(name)) {
|
if (uuidMap.containsKey(name)) {
|
||||||
@ -99,6 +103,7 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uuidMap.put(name, uuid);
|
uuidMap.put(name, uuid);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@ package com.plotsquared.bukkit.uuid;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FilenameFilter;
|
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.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,7 +15,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.common.io.Files;
|
|
||||||
import com.google.common.io.InputSupplier;
|
import com.google.common.io.InputSupplier;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
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.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||||
import com.intellectualcrafters.plot.util.NbtFactory;
|
import com.intellectualcrafters.plot.util.NbtFactory;
|
||||||
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||||
@ -56,6 +59,36 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PS.debug(C.PREFIX.s() + "&6Starting player data caching for: " + world);
|
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<String> 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) {
|
if (Settings.TWIN_MODE_UUID) {
|
||||||
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
||||||
@ -76,7 +109,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if (check || all.remove(uuid)) {
|
if (check || all.remove(uuid)) {
|
||||||
File file = new File(playerdataFolder + File.separator + current);
|
File file = new File(playerdataFolder + File.separator + current);
|
||||||
InputSupplier<FileInputStream> is = Files.newInputStreamSupplier(file);
|
InputSupplier<FileInputStream> is = com.google.common.io.Files.newInputStreamSupplier(file);
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
@ -146,7 +179,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
try {
|
try {
|
||||||
File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
|
File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
|
||||||
InputSupplier<FileInputStream> is = Files.newInputStreamSupplier(file);
|
InputSupplier<FileInputStream> is = com.google.common.io.Files.newInputStreamSupplier(file);
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user