From cee970e3d95e6133a3c9365eb3d0ae8efdd67e8d Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 2 Jun 2016 13:42:32 -0400 Subject: [PATCH] Tweaked some things --- .../bukkit/commands/DebugUUID.java | 21 ++--- .../plotsquared/bukkit/util/NbtFactory.java | 6 +- .../bukkit/uuid/DatFileFilter.java | 12 +++ .../bukkit/uuid/FileUUIDHandler.java | 81 ++++++++----------- .../plot/commands/Merge.java | 4 +- .../intellectualcrafters/plot/config/C.java | 2 +- .../plot/flag/FlagManager.java | 2 +- 7 files changed, 59 insertions(+), 69 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/uuid/DatFileFilter.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java index 15bfafbb6..6439c4e6f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java @@ -1,5 +1,6 @@ package com.plotsquared.bukkit.commands; +import com.google.common.collect.Sets; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.CommandCategory; 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.WorldUtil; import com.intellectualcrafters.plot.uuid.UUIDWrapper; +import com.plotsquared.bukkit.uuid.DatFileFilter; import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; @@ -24,7 +26,6 @@ import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -102,19 +103,12 @@ public class DebugUUID extends SubCommand { MainUtil.sendMessage(player, "&7 - Collecting playerdata"); - HashSet worlds = new HashSet<>(); - worlds.add(WorldUtil.IMP.getMainWorld()); - worlds.add("world"); + HashSet worlds = Sets.newHashSet(WorldUtil.IMP.getMainWorld(), "world"); HashSet uuids = new HashSet<>(); HashSet names = new HashSet<>(); for (String worldName : worlds) { File playerDataFolder = new File(worldName + File.separator + "playerdata"); - String[] dat = playerDataFolder.list(new FilenameFilter() { - @Override - public boolean accept(File f, String s) { - return s.endsWith(".dat"); - } - }); + String[] dat = playerDataFolder.list(new DatFileFilter()); if (dat != null) { for (String current : dat) { String s = current.replaceAll(".dat$", ""); @@ -127,12 +121,7 @@ public class DebugUUID extends SubCommand { } } File playersFolder = new File(worldName + File.separator + "players"); - dat = playersFolder.list(new FilenameFilter() { - @Override - public boolean accept(File f, String s) { - return s.endsWith(".dat"); - } - }); + dat = playersFolder.list(new DatFileFilter()); if (dat != null) { for (String current : dat) { names.add(current.replaceAll(".dat$", "")); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java index 66c5368ec..ea4838bac 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java @@ -6,9 +6,9 @@ import com.google.common.collect.HashBiMap; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; import com.google.common.io.ByteSink; +import com.google.common.io.ByteSource; import com.google.common.io.Closeables; import com.google.common.io.Files; -import com.google.common.io.InputSupplier; import com.google.common.primitives.Primitives; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -167,13 +167,13 @@ public class NbtFactory { * @return The decoded NBT compound. * @throws IOException If anything went wrong. */ - public static NbtCompound fromStream(InputSupplier stream, StreamOptions option) throws IOException { + public static NbtCompound fromStream(ByteSource stream, StreamOptions option) throws IOException { InputStream input = null; DataInputStream data = null; boolean suppress = true; try { - input = stream.getInput(); + input = stream.openStream(); if (option == StreamOptions.GZIP_COMPRESSION) { data = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input))); } else { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/DatFileFilter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/DatFileFilter.java new file mode 100644 index 000000000..2cd509051 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/DatFileFilter.java @@ -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"); + } +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java index bc6413f16..84e2c0058 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java @@ -1,8 +1,8 @@ package com.plotsquared.bukkit.uuid; import com.google.common.collect.HashBiMap; +import com.google.common.collect.Sets; import com.google.common.io.ByteSource; -import com.google.common.io.InputSupplier; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -21,8 +21,6 @@ import org.bukkit.Bukkit; import org.bukkit.World; 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; @@ -90,12 +88,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { HashSet all = UUIDHandler.getAllUUIDS(); PS.debug("&aFast mode UUID caching enabled!"); File playerDataFolder = new File(container, world + File.separator + "playerdata"); - String[] dat = playerDataFolder.list(new FilenameFilter() { - @Override - public boolean accept(File f, String s) { - return s.endsWith(".dat"); - } - }); + String[] dat = playerDataFolder.list(new DatFileFilter()); boolean check = all.isEmpty(); if (dat != null) { for (String current : dat) { @@ -103,16 +96,20 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { try { UUID uuid = UUID.fromString(s); if (check || all.remove(uuid)) { - File file = new File(playerDataFolder + File.separator + current); - InputSupplier is = com.google.common.io.Files.newInputStreamSupplier(file); + File file = new File(playerDataFolder, current); + ByteSource is = com.google.common.io.Files.asByteSource(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"); - long last = (long) bukkit.get("lastPlayed"); - if (ExpireManager.IMP != null) { - ExpireManager.IMP.storeDate(uuid, last); + if (!compound.containsKey("bukkit")) { + PS.debug("ERROR: Player data does not contain the the key \"bukkit\""); + } else { + NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit"); + 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) { e.printStackTrace(); @@ -132,21 +129,14 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } HashBiMap toAdd = HashBiMap.create(new HashMap()); toAdd.put(new StringWrapper("*"), DBFunc.everyone); - HashSet worlds = new HashSet<>(); - worlds.add(world); - worlds.add("world"); + HashSet worlds = Sets.newHashSet(world, "world"); HashSet uuids = new HashSet<>(); HashSet names = new HashSet<>(); File playerDataFolder = null; for (String worldName : worlds) { // Getting UUIDs playerDataFolder = new File(container, worldName + File.separator + "playerdata"); - String[] dat = playerDataFolder.list(new FilenameFilter() { - @Override - public boolean accept(File f, String s) { - return s.endsWith(".dat"); - } - }); + String[] dat = playerDataFolder.list(new DatFileFilter()); if ((dat != null) && (dat.length != 0)) { for (String current : dat) { String s = current.replaceAll(".dat$", ""); @@ -161,12 +151,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } // Getting names File playersFolder = new File(worldName + File.separator + "players"); - dat = playersFolder.list(new FilenameFilter() { - @Override - public boolean accept(File f, String s) { - return s.endsWith(".dat"); - } - }); + dat = playersFolder.list(new DatFileFilter()); if ((dat != null) && (dat.length != 0)) { for (String current : dat) { names.add(current.replaceAll(".dat$", "")); @@ -182,22 +167,26 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } ByteSource is = com.google.common.io.Files.asByteSource(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"); - long last = (long) bukkit.get("lastPlayed"); - if (Settings.OFFLINE_MODE) { - if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) { - uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name); - } else { - long most = (long) compound.get("UUIDMost"); - long least = (long) compound.get("UUIDLeast"); - uuid = new UUID(most, least); + if (!compound.containsKey("bukkit")) { + PS.debug("ERROR: Player data does not contain the the key \"bukkit\""); + } else { + NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit"); + String name = (String) bukkit.get("lastKnownName"); + long last = (long) bukkit.get("lastPlayed"); + if (Settings.OFFLINE_MODE) { + if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) { + uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name); + } 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) { PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat"); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 29848f6ce..d7266ee0c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -165,8 +165,8 @@ public class Merge extends SubCommand { public void run() { MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); plot.autoMerge(dir, maxSize - size, owner, terrain); - PlotPlayer pp = UUIDHandler.getPlayer(player.getUUID()); - if (pp == null) { + PlotPlayer plotPlayer = UUIDHandler.getPlayer(player.getUUID()); + if (plotPlayer == null) { sendMessage(accepter, C.MERGE_NOT_VALID); return; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index cf295df8a..293c937e0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -339,7 +339,7 @@ public enum C { MERGE_ACCEPTED("$2The merge request has been accepted", "Merge"), SUCCESS_MERGE("$2Plots have been merged!", "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_AVAILABLE_AUTOMERGE("$2You do not own any adjacent plots in the specified direction or are not allowed to merge to the required size.", "Merge"), diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 8c4a1e65d..b75222d46 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -100,7 +100,7 @@ public class FlagManager { StringBuilder flag_string = new StringBuilder(); int i = 0; for (Map.Entry, Object> entry : flags.entrySet()) { - Flag flag = entry.getKey(); + Flag flag = entry.getKey(); if (i != 0) { flag_string.append(','); }