From 8e8489d4a70294f733ad7648327f5d35bc68e3f9 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 26 Feb 2015 22:13:17 +1100 Subject: [PATCH] Fixed UUID caching and name changes --- .../intellectualcrafters/plot/BukkitMain.java | 1 - .../intellectualcrafters/plot/IPlotMain.java | 4 ++-- .../plot/commands/DebugExec.java | 4 ++-- .../plot/commands/SchematicCmd.java | 2 +- .../plot/generator/HybridGen.java | 2 +- .../plot/generator/HybridPlotManager.java | 2 -- .../plot/generator/HybridPlotWorld.java | 2 +- .../plot/object/schematic/StateWrapper.java | 2 -- .../plot/util/BlockManager.java | 2 -- .../plot/util/ExpireManager.java | 4 ++-- .../plot/util/SchematicHandler.java | 3 --- .../plot/util/bukkit/UUIDHandler.java | 22 +++++++++++++++++++ .../plot/uuid/DefaultUUIDWrapper.java | 16 ++++++++++++-- .../plot/uuid/OfflineUUIDWrapper.java | 15 +++++++++++-- .../plot/uuid/UUIDWrapper.java | 8 ++++--- 15 files changed, 63 insertions(+), 26 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 770fb0f5f..af0964ecb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -36,7 +36,6 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8; import com.intellectualcrafters.plot.listeners.PlotPlusListener; import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldEvents; -import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.util.BlockManager; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index d2d10b564..f2387d0b1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -2,10 +2,10 @@ package com.intellectualcrafters.plot; import java.io.File; -import org.bukkit.generator.ChunkGenerator; - import net.milkbowl.vault.economy.Economy; +import org.bukkit.generator.ChunkGenerator; + import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 57ba394ab..83f52878f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -35,8 +35,8 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; @@ -111,7 +111,7 @@ public class DebugExec extends SubCommand { if (uuid == null) { return MainUtil.sendMessage(null, "player not found: " + args[1]); } - final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); if ((op == null) || (op.getLastPlayed() == 0)) { return MainUtil.sendMessage(null, "player hasn't connected before: " + args[1]); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index dc5b00017..0524b48e0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; -import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index efd4f3303..96a0a4036 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -31,8 +31,8 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java index 837f344d0..7a9b19c9d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java @@ -27,14 +27,12 @@ import java.util.HashSet; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.commands.Template; -import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.FileBytes; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; -import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index f1f73e616..09d10a706 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -29,8 +29,8 @@ import org.bukkit.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; -import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java index 1961ad496..f4ac35d62 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java @@ -18,8 +18,6 @@ import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.ListTag; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.Tag; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; public class StateWrapper { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index b50a5bcce..ee8252014 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -1,7 +1,5 @@ package com.intellectualcrafters.plot.util; -import org.bukkit.inventory.ItemStack; - import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PseudoRandom; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 2a021a67e..eeb650719 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -18,7 +18,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlotDeleteEvent; -import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -171,7 +171,7 @@ public class ExpireManager { keep.add(uuid); continue; } - final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); if ((op == null) || (op.getLastPlayed() == 0)) { continue; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 539cad27b..46e172a5f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -12,8 +12,6 @@ import java.util.Map; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; -import org.bukkit.block.BlockState; - import com.intellectualcrafters.jnbt.ByteArrayTag; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.IntTag; @@ -23,7 +21,6 @@ import com.intellectualcrafters.jnbt.NBTOutputStream; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.commands.Set; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java index b5fdc9cb2..63e151f8e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; @@ -35,6 +36,13 @@ public class UUIDHandler { if ((uuid == null) || (name == null)) { return; } + BiMap inverse = uuidMap.inverse(); + if (inverse.containsKey(uuid)) { + if (uuidMap.containsKey(name)) { + return; + } + inverse.remove(uuid); + } uuidMap.put(name, uuid); } @@ -81,6 +89,18 @@ public class UUIDHandler { } PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching"); UUIDHandler.CACHED = true; + + for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { + if (op.getLastPlayed() != 0) { + String name = op.getName(); + StringWrapper wrap = new StringWrapper(name); + UUID uuid = uuidWrapper.getUUID(op); + add(wrap, uuid); + } + } + + // OLD UUID CACHING SYSTEM + /* final HashSet worlds = new HashSet<>(); worlds.add(world); worlds.add("world"); @@ -136,6 +156,8 @@ public class UUIDHandler { final StringWrapper nameWrap = new StringWrapper(name); add(nameWrap, uuid); } + */ + // add the Everyone '*' UUID add(new StringWrapper("*"), DBFunc.everyone); PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java index 890a61989..a04870794 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java @@ -3,9 +3,11 @@ package com.intellectualcrafters.plot.uuid; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.BukkitPlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; public class DefaultUUIDWrapper extends UUIDWrapper { @@ -15,12 +17,12 @@ public class DefaultUUIDWrapper extends UUIDWrapper { } @Override - public UUID getUUID(final BukkitOfflinePlayer player) { + public UUID getUUID(final OfflinePlotPlayer player) { return player.getUUID(); } @Override - public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) { + public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid)); } @@ -28,4 +30,14 @@ public class DefaultUUIDWrapper extends UUIDWrapper { public UUID getUUID(final String name) { return Bukkit.getOfflinePlayer(name).getUniqueId(); } + + @Override + public OfflinePlotPlayer[] getOfflinePlayers() { + OfflinePlayer[] ops = Bukkit.getOfflinePlayers(); + BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ; + for (int i = 0; i < ops.length; i++) { + toReturn[i] = new BukkitOfflinePlayer(ops[i]); + } + return toReturn; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java index 7faa7ad41..fd46bd6bd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -13,6 +13,7 @@ import com.google.common.base.Charsets; import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -37,7 +38,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } @Override - public UUID getUUID(final BukkitOfflinePlayer player) { + public UUID getUUID(final OfflinePlotPlayer player) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @@ -46,7 +47,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } @Override - public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) { + public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { final BiMap map = UUIDHandler.getUuidMap().inverse(); String name; try { @@ -92,4 +93,14 @@ public class OfflineUUIDWrapper extends UUIDWrapper { public UUID getUUID(final String name) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); } + + @Override + public OfflinePlotPlayer[] getOfflinePlayers() { + OfflinePlayer[] ops = Bukkit.getOfflinePlayers(); + BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ; + for (int i = 0; i < ops.length; i++) { + toReturn[i] = new BukkitOfflinePlayer(ops[i]); + } + return toReturn; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java index b325f9df0..1c6381c1c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java @@ -2,15 +2,17 @@ package com.intellectualcrafters.plot.uuid; import java.util.UUID; -import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; public abstract class UUIDWrapper { public abstract UUID getUUID(PlotPlayer player); - public abstract UUID getUUID(BukkitOfflinePlayer player); + public abstract UUID getUUID(OfflinePlotPlayer player); public abstract UUID getUUID(String name); - public abstract BukkitOfflinePlayer getOfflinePlayer(UUID uuid); + public abstract OfflinePlotPlayer getOfflinePlayer(UUID uuid); + + public abstract OfflinePlotPlayer[] getOfflinePlayers(); }