Tweaked some things

This commit is contained in:
MattBDev 2016-06-02 13:42:32 -04:00
parent da58c7b411
commit cee970e3d9
7 changed files with 59 additions and 69 deletions

View File

@ -1,5 +1,6 @@
package com.plotsquared.bukkit.commands; package com.plotsquared.bukkit.commands;
import com.google.common.collect.Sets;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.CommandCategory; import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
@ -17,6 +18,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.uuid.DatFileFilter;
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
@ -24,7 +26,6 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -102,19 +103,12 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7 - Collecting playerdata"); MainUtil.sendMessage(player, "&7 - Collecting playerdata");
HashSet<String> worlds = new HashSet<>(); HashSet<String> worlds = Sets.newHashSet(WorldUtil.IMP.getMainWorld(), "world");
worlds.add(WorldUtil.IMP.getMainWorld());
worlds.add("world");
HashSet<UUID> uuids = new HashSet<>(); HashSet<UUID> uuids = new HashSet<>();
HashSet<String> names = new HashSet<>(); HashSet<String> names = new HashSet<>();
for (String worldName : worlds) { for (String worldName : worlds) {
File playerDataFolder = new File(worldName + File.separator + "playerdata"); File playerDataFolder = new File(worldName + File.separator + "playerdata");
String[] dat = playerDataFolder.list(new FilenameFilter() { String[] dat = playerDataFolder.list(new DatFileFilter());
@Override
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
if (dat != null) { if (dat != null) {
for (String current : dat) { for (String current : dat) {
String s = current.replaceAll(".dat$", ""); String s = current.replaceAll(".dat$", "");
@ -127,12 +121,7 @@ public class DebugUUID extends SubCommand {
} }
} }
File playersFolder = new File(worldName + File.separator + "players"); File playersFolder = new File(worldName + File.separator + "players");
dat = playersFolder.list(new FilenameFilter() { dat = playersFolder.list(new DatFileFilter());
@Override
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
if (dat != null) { if (dat != null) {
for (String current : dat) { for (String current : dat) {
names.add(current.replaceAll(".dat$", "")); names.add(current.replaceAll(".dat$", ""));

View File

@ -6,9 +6,9 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.io.ByteSink; import com.google.common.io.ByteSink;
import com.google.common.io.ByteSource;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.primitives.Primitives; import com.google.common.primitives.Primitives;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -167,13 +167,13 @@ public class NbtFactory {
* @return The decoded NBT compound. * @return The decoded NBT compound.
* @throws IOException If anything went wrong. * @throws IOException If anything went wrong.
*/ */
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException { public static NbtCompound fromStream(ByteSource stream, StreamOptions option) throws IOException {
InputStream input = null; InputStream input = null;
DataInputStream data = null; DataInputStream data = null;
boolean suppress = true; boolean suppress = true;
try { try {
input = stream.getInput(); input = stream.openStream();
if (option == StreamOptions.GZIP_COMPRESSION) { if (option == StreamOptions.GZIP_COMPRESSION) {
data = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input))); data = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)));
} else { } else {

View File

@ -0,0 +1,12 @@
package com.plotsquared.bukkit.uuid;
import java.io.File;
import java.io.FilenameFilter;
public class DatFileFilter implements FilenameFilter {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".dat");
}
}

View File

@ -1,8 +1,8 @@
package com.plotsquared.bukkit.uuid; package com.plotsquared.bukkit.uuid;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
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;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -21,8 +21,6 @@ import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -90,12 +88,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
HashSet<UUID> all = UUIDHandler.getAllUUIDS(); HashSet<UUID> all = UUIDHandler.getAllUUIDS();
PS.debug("&aFast mode UUID caching enabled!"); PS.debug("&aFast mode UUID caching enabled!");
File playerDataFolder = new File(container, world + File.separator + "playerdata"); File playerDataFolder = new File(container, world + File.separator + "playerdata");
String[] dat = playerDataFolder.list(new FilenameFilter() { String[] dat = playerDataFolder.list(new DatFileFilter());
@Override
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
boolean check = all.isEmpty(); boolean check = all.isEmpty();
if (dat != null) { if (dat != null) {
for (String current : dat) { for (String current : dat) {
@ -103,16 +96,20 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
try { try {
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, current);
InputSupplier<FileInputStream> is = com.google.common.io.Files.newInputStreamSupplier(file); ByteSource is = com.google.common.io.Files.asByteSource(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"); if (!compound.containsKey("bukkit")) {
String name = (String) bukkit.get("lastKnownName"); PS.debug("ERROR: Player data does not contain the the key \"bukkit\"");
long last = (long) bukkit.get("lastPlayed"); } else {
if (ExpireManager.IMP != null) { NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
ExpireManager.IMP.storeDate(uuid, last); String name = (String) bukkit.get("lastKnownName");
long last = (long) bukkit.get("lastPlayed");
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(uuid, last);
}
toAdd.put(new StringWrapper(name), uuid);
} }
toAdd.put(new StringWrapper(name), uuid);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -132,21 +129,14 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
} }
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>()); HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
toAdd.put(new StringWrapper("*"), DBFunc.everyone); toAdd.put(new StringWrapper("*"), DBFunc.everyone);
HashSet<String> worlds = new HashSet<>(); HashSet<String> worlds = Sets.newHashSet(world, "world");
worlds.add(world);
worlds.add("world");
HashSet<UUID> uuids = new HashSet<>(); HashSet<UUID> uuids = new HashSet<>();
HashSet<String> names = new HashSet<>(); HashSet<String> names = new HashSet<>();
File playerDataFolder = null; File playerDataFolder = null;
for (String worldName : worlds) { for (String worldName : worlds) {
// Getting UUIDs // Getting UUIDs
playerDataFolder = new File(container, worldName + File.separator + "playerdata"); playerDataFolder = new File(container, worldName + File.separator + "playerdata");
String[] dat = playerDataFolder.list(new FilenameFilter() { String[] dat = playerDataFolder.list(new DatFileFilter());
@Override
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
if ((dat != null) && (dat.length != 0)) { if ((dat != null) && (dat.length != 0)) {
for (String current : dat) { for (String current : dat) {
String s = current.replaceAll(".dat$", ""); String s = current.replaceAll(".dat$", "");
@ -161,12 +151,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
} }
// Getting names // Getting names
File playersFolder = new File(worldName + File.separator + "players"); File playersFolder = new File(worldName + File.separator + "players");
dat = playersFolder.list(new FilenameFilter() { dat = playersFolder.list(new DatFileFilter());
@Override
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
if ((dat != null) && (dat.length != 0)) { if ((dat != null) && (dat.length != 0)) {
for (String current : dat) { for (String current : dat) {
names.add(current.replaceAll(".dat$", "")); names.add(current.replaceAll(".dat$", ""));
@ -182,22 +167,26 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
} }
ByteSource is = com.google.common.io.Files.asByteSource(file); ByteSource is = com.google.common.io.Files.asByteSource(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"); if (!compound.containsKey("bukkit")) {
String name = (String) bukkit.get("lastKnownName"); PS.debug("ERROR: Player data does not contain the the key \"bukkit\"");
long last = (long) bukkit.get("lastPlayed"); } else {
if (Settings.OFFLINE_MODE) { NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) { String name = (String) bukkit.get("lastKnownName");
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name); long last = (long) bukkit.get("lastPlayed");
} else { if (Settings.OFFLINE_MODE) {
long most = (long) compound.get("UUIDMost"); if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) {
long least = (long) compound.get("UUIDLeast"); uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
uuid = new UUID(most, least); } else {
long most = (long) compound.get("UUIDMost");
long least = (long) compound.get("UUIDLeast");
uuid = new UUID(most, least);
}
} }
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(uuid, last);
}
toAdd.put(new StringWrapper(name), uuid);
} }
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(uuid, last);
}
toAdd.put(new StringWrapper(name), uuid);
} catch (Exception ignored) { } catch (Exception ignored) {
PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat"); PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
} }

View File

@ -165,8 +165,8 @@ public class Merge extends SubCommand {
public void run() { public void run() {
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
plot.autoMerge(dir, maxSize - size, owner, terrain); plot.autoMerge(dir, maxSize - size, owner, terrain);
PlotPlayer pp = UUIDHandler.getPlayer(player.getUUID()); PlotPlayer plotPlayer = UUIDHandler.getPlayer(player.getUUID());
if (pp == null) { if (plotPlayer == null) {
sendMessage(accepter, C.MERGE_NOT_VALID); sendMessage(accepter, C.MERGE_NOT_VALID);
return; return;
} }

View File

@ -339,7 +339,7 @@ public enum C {
MERGE_ACCEPTED("$2The merge request has been accepted", "Merge"), MERGE_ACCEPTED("$2The merge request has been accepted", "Merge"),
SUCCESS_MERGE("$2Plots have been merged!", "Merge"), SUCCESS_MERGE("$2Plots have been merged!", "Merge"),
MERGE_REQUESTED("$2Successfully sent a merge request", "Merge"), MERGE_REQUESTED("$2Successfully sent a merge request", "Merge"),
MERGE_REQUEST_CONFIRM("merge request from %s", "Permission"), MERGE_REQUEST_CONFIRM("Merge request from %s", "Permission"),
NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%", "Merge"), NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%", "Merge"),
NO_AVAILABLE_AUTOMERGE("$2You do not own any adjacent plots in the specified direction or are not allowed to merge to the required size.", NO_AVAILABLE_AUTOMERGE("$2You do not own any adjacent plots in the specified direction or are not allowed to merge to the required size.",
"Merge"), "Merge"),

View File

@ -100,7 +100,7 @@ public class FlagManager {
StringBuilder flag_string = new StringBuilder(); StringBuilder flag_string = new StringBuilder();
int i = 0; int i = 0;
for (Map.Entry<Flag<?>, Object> entry : flags.entrySet()) { for (Map.Entry<Flag<?>, Object> entry : flags.entrySet()) {
Flag<?> flag = entry.getKey(); Flag flag = entry.getKey();
if (i != 0) { if (i != 0) {
flag_string.append(','); flag_string.append(',');
} }