From 4651731f65d612aae5dcc6512d99098548c37df2 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 16 Dec 2014 15:53:06 +1100 Subject: [PATCH] Moved UUID classes to UUID package --- .../intellectualcrafters/plot/PlotMain.java | 2 + .../plot/api/PlotAPI.java | 2 +- .../plot/commands/Clear.java | 2 +- .../plot/commands/Database.java | 2 +- .../plot/commands/DebugClaimTest.java | 3 +- .../plot/commands/Denied.java | 2 +- .../plot/commands/Helpers.java | 2 +- .../plot/commands/Info.java | 3 +- .../plot/commands/Schematic.java | 2 + .../plot/commands/SetOwner.java | 2 +- .../plot/commands/Trusted.java | 2 +- .../plot/commands/Unlink.java | 2 +- .../plot/commands/Visit.java | 3 +- .../plot/commands/list.java | 3 +- .../plot/database/SQLManager.java | 2 +- .../plot/listeners/PlotListener.java | 3 +- .../plot/listeners/PlotPlusListener.java | 2 +- .../plot/listeners/WorldEditListener.java | 2 +- .../plot/listeners/WorldGuardListener.java | 3 +- .../plot/object/InfoInventory.java | 3 +- .../plot/object/Plot.java | 2 +- .../plot/util/PlayerFunctions.java | 2 + .../plot/util/PlotHelper.java | 1 + .../plot/uuid/DefaultUUIDWrapper.java | 31 ++ .../plot/uuid/OfflineUUIDWrapper.java | 54 +++ .../plot/uuid/PlotUUIDSaver.java | 2 +- .../plot/uuid/UUIDHandler.java | 343 ++++++++++++++++++ .../plot/uuid/UUIDWrapper.java | 16 + 28 files changed, 478 insertions(+), 20 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDHandler.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 2757bf3ae..f74ac9c71 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -38,7 +38,9 @@ import com.intellectualcrafters.plot.listeners.*; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.Logger.LogLevel; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import com.intellectualcrafters.plot.uuid.UUIDSaver; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index b0063db7b..60a49c4f6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotSquaredException; import com.intellectualcrafters.plot.util.SchematicHandler; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import com.sun.istack.internal.NotNull; import org.bukkit.Bukkit; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 1cc25527a..97e224687 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 55595967c..722f8715c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -6,7 +6,7 @@ import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.StringComparison; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 465b6aa6f..feee860a6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -30,7 +30,8 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java index 5acbebf19..2b4882f60 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java index fa9a02f0c..d40347d65 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 1d1673f40..cef39085b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -30,7 +30,8 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java index de5795a73..5b2c17562 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java @@ -30,6 +30,8 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index a4169ab5e..fe924c549 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -28,7 +28,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.World; import org.bukkit.entity.Player; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java index 5f171c901..b9ec0b46b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index c7a48e808..24d840813 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SetBlockFast; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.World; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 462c4de26..0b655eec9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -24,7 +24,8 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.entity.Player; import java.util.ArrayList; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 33fb952ea..e0c0a1ac1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -27,7 +27,8 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.StringComparison; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index a08d43b79..125cdb0ee 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -30,7 +30,7 @@ import com.intellectualcrafters.plot.object.PlotHomePosition; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.Logger; import com.intellectualcrafters.plot.util.Logger.LogLevel; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 2553e3740..25cf89c7a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -29,7 +29,8 @@ import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 970c19e35..674d8540e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -26,7 +26,7 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.*; import org.bukkit.entity.EntityType; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java index 7d4fe3945..0291e6992 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -31,7 +31,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PWE; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.bukkit.selections.Selection; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index 0c8d61e7e..e153a44ad 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.events.PlotUnlinkEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.protection.flags.DefaultFlag; @@ -37,6 +37,7 @@ import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java index 2874493ca..df8d953b7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 3afc1fd54..50582579f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -25,7 +25,7 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.World; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index f989abf0f..f3a68c22f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -28,6 +28,8 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.uuid.UUIDHandler; + import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.util.ChatPaginator; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index a7b66e220..fe51fc51a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -26,6 +26,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.listeners.PlotListener; import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.uuid.UUIDHandler; import net.milkbowl.vault.economy.Economy; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java new file mode 100644 index 000000000..f5be0b554 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java @@ -0,0 +1,31 @@ +package com.intellectualcrafters.plot.uuid; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public class DefaultUUIDWrapper extends UUIDWrapper { + + @Override + public UUID getUUID(Player player) { + return player.getUniqueId(); + } + + @Override + public UUID getUUID(OfflinePlayer player) { + return player.getUniqueId(); + } + + @Override + public OfflinePlayer getOfflinePlayer(UUID uuid) { + return Bukkit.getOfflinePlayer(uuid); + } + + @Override + public Player getPlayer(UUID uuid) { + return Bukkit.getPlayer(uuid); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java new file mode 100644 index 000000000..475e62e62 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -0,0 +1,54 @@ +package com.intellectualcrafters.plot.uuid; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.google.common.base.Charsets; +import com.google.common.collect.BiMap; +import com.intellectualcrafters.plot.object.StringWrapper; + +public class OfflineUUIDWrapper extends UUIDWrapper { + + @Override + public UUID getUUID(Player player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + } + + @Override + public UUID getUUID(OfflinePlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + } + + @Override + public OfflinePlayer getOfflinePlayer(UUID uuid) { + BiMap map = UUIDHandler.getUuidMap().inverse(); + String name = map.get(uuid).value; + if (name != null) { + return Bukkit.getOfflinePlayer(name); + } + else { + for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { + if (getUUID(player).equals(uuid)) { + return player; + } + } + } + return Bukkit.getOfflinePlayer(uuid.toString()); + } + + @Override + public Player getPlayer(UUID uuid) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (getUUID(player).equals(uuid)) { + return player; + } + } + return null; + } + + + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java index 5b9bcc034..4ecc63a24 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.json.JSONTokener; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.plugin.java.JavaPlugin; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDHandler.java new file mode 100644 index 000000000..a3c82e5d0 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDHandler.java @@ -0,0 +1,343 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// + +package com.intellectualcrafters.plot.uuid; + +import com.google.common.base.Charsets; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.StringWrapper; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.UUID; + +/** + * This class can be used to efficiently translate UUIDs and names back and + * forth. + * It uses three primary methods of achieving this: + * - Read From Cache + * - Read from OfflinePlayer objects + * - Read from (if onlinemode: mojang api) (else: playername hashing) + * All UUIDs/Usernames will be stored in a map (cache) until the server is + * restarted. + *

+ * You can use getUuidMap() to save the uuids/names to a file (SQLite db for + * example). + * Primary methods: getUUID(String name) & getName(UUID uuid) <-- You should + * ONLY use these. + * Call startFetch(JavaPlugin plugin) in your onEnable(). + *

+ * Originally created by: + * + * @author Citymonstret + * @author Empire92 + * for PlotSquared. + */ +@SuppressWarnings("unused") +public class UUIDHandler { + + public static UUIDWrapper uuidWrapper = null; + + /** + * Online mode + * + * @see org.bukkit.Server#getOnlineMode() + */ + private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE; + + /** + * Map containing names and UUIDs + * + * @see com.google.common.collect.BiMap + */ + private final static BiMap uuidMap = HashBiMap.create(new HashMap()); + + /** + * Get the map containing all names/uuids + * + * @return map with names + uuids + * @see com.google.common.collect.BiMap + */ + public static BiMap getUuidMap() { + return uuidMap; + } + + /** + * Check if a uuid is cached + * + * @param uuid to check + * @return true of the uuid is cached + * @see com.google.common.collect.BiMap#containsValue(Object) + */ + public static boolean uuidExists(final UUID uuid) { + return uuidMap.containsValue(uuid); + } + + /** + * Check if a name is cached + * + * @param name to check + * @return true of the name is cached + * @see com.google.common.collect.BiMap#containsKey(Object) + */ + public static boolean nameExists(final StringWrapper name) { + return uuidMap.containsKey(name); + } + + /** + * Add a set to the cache + * + * @param name to cache + * @param uuid to cache + */ + public static void add(final StringWrapper name, final UUID uuid) { + if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) { + uuidMap.put(name, uuid); + } + } + + /** + * @param name to use as key + * @return uuid + */ + public static UUID getUUID(final String name) { + final StringWrapper nameWrap = new StringWrapper(name); + if (uuidMap.containsKey(nameWrap)) { + return uuidMap.get(nameWrap); + } + @SuppressWarnings("deprecation") + final Player player = Bukkit.getPlayer(name); + if (player != null) { + final UUID uuid = getUUID(player); + add(nameWrap, uuid); + return uuid; + } + UUID uuid; + if (online) { + if (Settings.CUSTOM_API) { + if ((uuid = getUuidOnlinePlayer(nameWrap)) != null) { + return uuid; + } + try { + return PlotMain.getUUIDSaver().mojangUUID(name); + } catch (final Exception e) { + try { + final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); + uuid = fetcher.call().get(name); + add(nameWrap, uuid); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + } else { + try { + final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); + uuid = fetcher.call().get(name); + add(nameWrap, uuid); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + } else { + return getUuidOfflineMode(nameWrap); + } + return null; + } + + /** + * @param uuid to use as key + * @return name (cache) + */ + private static StringWrapper loopSearch(final UUID uuid) { + return uuidMap.inverse().get(uuid); + } + + /** + * @param uuid to use as key + * @return Name + */ + public static String getName(final UUID uuid) { + if (uuidExists(uuid)) { + return loopSearch(uuid).value; + } + String name; + if ((name = getNameOnlinePlayer(uuid)) != null) { + return name; + } + if ((name = getNameOfflinePlayer(uuid)) != null) { + return name; + } + if (online && !Settings.OFFLINE_MODE) { + if (!Settings.CUSTOM_API) { + try { + final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); + name = fetcher.call().get(uuid); + add(new StringWrapper(name), uuid); + return name; + } catch (final Exception ex) { + ex.printStackTrace(); + } + } else { + try { + return PlotMain.getUUIDSaver().mojangName(uuid); + } catch (final Exception e) { + try { + final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); + name = fetcher.call().get(uuid); + add(new StringWrapper(name), uuid); + return name; + } catch (final Exception ex) { + e.printStackTrace(); + } + } + } + try { + return PlotMain.getUUIDSaver().mojangName(uuid); + } catch (final Exception e) { + try { + final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); + name = fetcher.call().get(uuid); + add(new StringWrapper(name), uuid); + return name; + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + } else { + return "unknown"; + } + return ""; + } + + /** + * @param name to use as key + * @return UUID (name hash) + */ + private static UUID getUuidOfflineMode(final StringWrapper name) { + final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); + add(name, uuid); + return uuid; + } + + /** + * @param uuid to use as key + * @return String - name + */ + private static String getNameOnlinePlayer(final UUID uuid) { + final Player player = uuidWrapper.getPlayer(uuid); + if ((player == null) || !player.isOnline()) { + return null; + } + final String name = player.getName(); + add(new StringWrapper(name), uuid); + return name; + } + + + + /** + * @param uuid to use as key + * @return String - name + */ + private static String getNameOfflinePlayer(final UUID uuid) { + final OfflinePlayer player = uuidWrapper.getOfflinePlayer(uuid); + if ((player == null) || !player.hasPlayedBefore()) { + return null; + } + final String name = player.getName(); + add(new StringWrapper(name), uuid); + return name; + } + + /** + * @param name to use as key + * @return UUID + */ + private static UUID getUuidOnlinePlayer(final StringWrapper name) { + @SuppressWarnings("deprecation") + final Player player = Bukkit.getPlayer(name.value); + if (player == null) { + return null; + } + final UUID uuid = getUUID(player); + add(name, uuid); + return uuid; + } + + /** + * Handle saving of uuids + * + * @see com.intellectualcrafters.plot.uuid.UUIDSaver#globalSave(com.google.common.collect.BiMap) + */ + @SuppressWarnings("unused") + public static void handleSaving() { + final UUIDSaver saver = PlotMain.getUUIDSaver(); + saver.globalSave(getUuidMap()); + } + + public static UUID getUUID(Player player) { + if (uuidWrapper == null) { + try { + getUUID(player); + uuidWrapper = new DefaultUUIDWrapper(); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + } + } + return uuidWrapper.getUUID(player); + } + + /** + * Safely provide the correct UUID provider. Ignores user preference if not possible rather than break the plugin. + */ + public static UUID getUUID(OfflinePlayer player) { + if (uuidWrapper == null) { + + if (Settings.OFFLINE_MODE) { + uuidWrapper = new OfflineUUIDWrapper(); + } + else { + try { + getUUID(player); + uuidWrapper = new DefaultUUIDWrapper(); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + } + } + } + try { + return uuidWrapper.getUUID(player); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + return uuidWrapper.getUUID(player); + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java new file mode 100644 index 000000000..454e9343f --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java @@ -0,0 +1,16 @@ +package com.intellectualcrafters.plot.uuid; + +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public abstract class UUIDWrapper { + public abstract UUID getUUID(Player player); + + public abstract UUID getUUID(OfflinePlayer player); + + public abstract OfflinePlayer getOfflinePlayer(UUID uuid); + + public abstract Player getPlayer(UUID uuid); +}