From 37367adfcff25c646c6d66a2f382ea52997045f5 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 16 Dec 2014 15:58:54 +1100 Subject: [PATCH] Just moving a few things. --- PlotSquared/pom.xml | 2 +- .../intellectualcrafters/plot/PlotMain.java | 1 + .../plot/util/UUIDHandler.java | 4 ++ .../plot/uuid/DefaultUUIDWrapper.java | 31 +++++++++++ .../plot/uuid/OfflineUUIDWrapper.java | 55 +++++++++++++++++++ .../plot/uuid/UUIDWrapper.java | 16 ++++++ 6 files changed, 108 insertions(+), 1 deletion(-) 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/UUIDWrapper.java diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index ec123e849..0151f0af6 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -6,7 +6,7 @@ com.intellectualcrafters PlotSquared - 2.3.8 + 2.4.0 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 2757bf3ae..9e9da3ab9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -38,6 +38,7 @@ 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.UUIDSaver; import com.sk89q.worldedit.bukkit.WorldEditPlugin; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 9b328ab08..8a7a0eedb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -27,9 +27,13 @@ import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.NameFetcher; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDFetcher; import com.intellectualcrafters.plot.uuid.UUIDSaver; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; 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..d4c4a3eb0 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -0,0 +1,55 @@ +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; +import com.intellectualcrafters.plot.util.UUIDHandler; + +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/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); +}