From 760041607e20b0d43c5ecd39d5c56770382cf721 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sun, 14 Dec 2014 00:30:29 +1100 Subject: [PATCH] Seems to work for 1.7.2 (which doesn't have UUIDs) --- .../intellectualcrafters/plot/PlotMain.java | 8 +++-- .../plot/api/PlotAPI.java | 2 +- .../plot/commands/Database.java | 8 +++-- .../plot/commands/Denied.java | 19 +++++++---- .../plot/commands/Helpers.java | 10 ++++-- .../plot/commands/Info.java | 4 +-- .../plot/commands/Trusted.java | 10 ++++-- .../plot/commands/plugin.java | 2 +- .../intellectualcrafters/plot/config/C.java | 2 +- .../plot/listeners/PlotPlusListener.java | 5 +-- .../plot/listeners/WorldEditListener.java | 3 +- .../plot/listeners/WorldGuardListener.java | 4 +-- .../plot/object/Plot.java | 2 +- .../plot/util/DefaultUUIDWrapper.java | 11 +++++++ .../plot/util/OfflineUUIDWrapper.java | 32 +++++++++++++++++++ .../plot/util/PlayerFunctions.java | 2 +- .../plot/util/PlotHelper.java | 2 +- .../plot/util/SchematicHandler.java | 4 +-- .../plot/util/UUIDHandler.java | 8 +++-- .../plot/util/UUIDWrapper.java | 4 +++ .../plot/uuid/PlotUUIDSaver.java | 2 +- 21 files changed, 109 insertions(+), 35 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 3859a2c9a..8f2a9c67a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -52,6 +52,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -74,7 +75,7 @@ import java.util.concurrent.TimeUnit; */ @SuppressWarnings("unused") public class PlotMain extends JavaPlugin { - + private static PlotMain main = null; /** * Permission that allows for "everything" */ @@ -681,7 +682,7 @@ public class PlotMain extends JavaPlugin { * @return (this class) */ public static PlotMain getMain() { - return JavaPlugin.getPlugin(PlotMain.class); + return PlotMain.main; } /** @@ -718,7 +719,7 @@ public class PlotMain extends JavaPlugin { return 0; } OfflinePlayer player; - if (((player = Bukkit.getOfflinePlayer(uuid)) == null) || !player.hasPlayedBefore()) { + if (((player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid)) == null) || !player.hasPlayedBefore()) { return 0; } return player.getLastPlayed(); @@ -1388,6 +1389,7 @@ public class PlotMain extends JavaPlugin { @Override @SuppressWarnings("deprecation") final public void onEnable() { + PlotMain.main = this; // Setup the logger mechanics setupLogger(); // Setup translations 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 f6942c455..b0063db7b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -124,7 +124,7 @@ public class PlotAPI { * @see com.intellectualcrafters.plot.PlotMain */ public PlotAPI(@NotNull final JavaPlugin plugin) { - this.plotMain = JavaPlugin.getPlugin(PlotMain.class); + this.plotMain = PlotMain.getMain(); if (plotMain == null) { throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled"); } 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 8bd33bdbd..55595967c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -6,6 +6,8 @@ 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 org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -36,7 +38,7 @@ public class Database extends SubCommand { if (uuid == null) { PlotMain.sendConsoleSenderMessage(msg); } else { - Player p = Bukkit.getPlayer(uuid); + Player p = UUIDHandler.uuidWrapper.getPlayer(uuid); if (p != null && p.isOnline()) return PlayerFunctions.sendMessage(p, msg); else @@ -46,7 +48,7 @@ public class Database extends SubCommand { } public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) { - Plugin p = PlotMain.getPlugin(PlotMain.class); + Plugin p = PlotMain.getMain(); final java.util.Set plots = PlotMain.getPlots(); p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() { @Override @@ -100,7 +102,7 @@ public class Database extends SubCommand { Connection n; try { n = new MySQL( - PlotMain.getPlugin(PlotMain.class), + PlotMain.getMain(), host, port, database, 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 af4ad84fd..5acbebf19 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java @@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.UUID; @@ -70,13 +71,18 @@ public class Denied extends SubCommand { PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); return false; } + OfflinePlayer player = null; if (plot.trusted.contains(uuid)) { plot.trusted.remove(uuid); - DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + DBFunc.removeTrusted(plr.getWorld().getName(), plot, player); } if (plot.helpers.contains(uuid)) { plot.helpers.remove(uuid); - DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + if (player == null) { + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + } + DBFunc.removeHelper(plr.getWorld().getName(), plot, player); } plot.addDenied(uuid); DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); @@ -86,11 +92,12 @@ public class Denied extends SubCommand { PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); return false; } - if (!uuid.equals(DBFunc.everyone) && (Bukkit.getPlayer(uuid) != null) && Bukkit.getPlayer(uuid).isOnline()) { - final Plot pl = PlayerFunctions.getCurrentPlot(Bukkit.getPlayer((uuid))); + Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); + if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) { + final Plot pl = PlayerFunctions.getCurrentPlot(player); if ((pl != null) && pl.id.equals(plot.id)) { - PlayerFunctions.sendMessage(Bukkit.getPlayer(uuid), C.YOU_BE_DENIED); - Bukkit.getPlayer(uuid).teleport(Bukkit.getPlayer(uuid).getWorld().getSpawnLocation()); + PlayerFunctions.sendMessage(player, C.YOU_BE_DENIED); + player.teleport(player.getWorld().getSpawnLocation()); } } PlayerFunctions.sendMessage(plr, C.DENIED_ADDED); 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 4576f413d..fa9a02f0c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.UUID; @@ -68,13 +69,18 @@ public class Helpers extends SubCommand { PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); return false; } + OfflinePlayer player = null; if (plot.trusted.contains(uuid)) { plot.trusted.remove(uuid); - DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + DBFunc.removeTrusted(plr.getWorld().getName(), plot, player); } if (plot.denied.contains(uuid)) { plot.denied.remove(uuid); - DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + if (player == null) { + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + } + DBFunc.removeDenied(plr.getWorld().getName(), plot, player); } plot.addHelper(uuid); DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); 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 9559f69c9..1d1673f40 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -115,7 +115,7 @@ public class Info extends SubCommand { String owner = "none"; if (plot.owner != null) { - owner = Bukkit.getOfflinePlayer(plot.owner).getName(); + owner = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner).getName(); } if (owner == null) { owner = plot.owner.toString(); @@ -179,7 +179,7 @@ public class Info extends SubCommand { String owner = "none"; if (plot.owner != null) { - owner = Bukkit.getOfflinePlayer(plot.owner).getName(); + owner = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner).getName(); } if (owner == null) { owner = plot.owner.toString(); 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 95dcc2b7e..5f171c901 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.UUID; @@ -69,13 +70,18 @@ public class Trusted extends SubCommand { PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); return false; } + OfflinePlayer player = null; if (plot.helpers.contains(uuid)) { plot.helpers.remove(uuid); - DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + DBFunc.removeHelper(plr.getWorld().getName(), plot, player); } if (plot.denied.contains(uuid)) { plot.denied.remove(uuid); - DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + if (player == null) { + player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + } + DBFunc.removeDenied(plr.getWorld().getName(), plot, player); } plot.addTrusted(uuid); DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 56220a09a..61c2a412a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -91,7 +91,7 @@ public class plugin extends SubCommand { @Override public boolean execute(final Player plr, final String... args) { - Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() { @Override public void run() { final ArrayList strings = new ArrayList() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index e7542f67a..343cb10db 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -439,7 +439,7 @@ public enum C { manager = new TranslationManager(); } if (defaultFile == null) { - defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), lang, "PlotSquared", manager) + defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager) .read(); } // register everything in this class 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 daee64dfe..970c19e35 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -177,7 +177,8 @@ public class PlotPlusListener extends PlotListener implements Listener { } if (booleanFlag(plot, "notify-enter")) { if (plot.hasOwner()) { - final Player player = Bukkit.getPlayer(plot.getOwner()); + + final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner()); if (player == null) { return; } @@ -216,7 +217,7 @@ public class PlotPlusListener extends PlotListener implements Listener { } if (booleanFlag(plot, "notify-leave")) { if (plot.hasOwner()) { - final Player player = Bukkit.getPlayer(plot.getOwner()); + final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner()); if (player == null) { return; } 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 a02e2e94c..7d4fe3945 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -31,6 +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.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.bukkit.selections.Selection; @@ -77,7 +78,7 @@ public class WorldEditListener implements Listener { if ((plot == null) || (plot.owner == null)) { return; } - final Player player = Bukkit.getPlayer(plot.owner); + final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.owner); if (player == null) { return; } 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 96eb01200..0c8d61e7e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -76,10 +76,10 @@ public class WorldGuardListener implements Listener { // requester.setOp(true); // 10 ticks should be enough - final PermissionAttachment add = requester.addAttachment(JavaPlugin.getPlugin(PlotMain.class), 10); + final PermissionAttachment add = requester.addAttachment(PlotMain.getMain(), 10); add.setPermission("worldguard.region.addowner.own.*", true); - final PermissionAttachment remove = requester.addAttachment(JavaPlugin.getPlugin(PlotMain.class), 10); + final PermissionAttachment remove = requester.addAttachment(PlotMain.getMain(), 10); remove.setPermission("worldguard.region.removeowner.own.*", true); try { 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 dbea4c478..794438915 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -214,7 +214,7 @@ public class Plot implements Cloneable { * @return true if the player is added as a helper or is the owner */ public boolean hasRights(final Player player) { - return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(UUIDHandler.getUUID(player))) || ((this.owner != null) && this.owner.equals(UUIDHandler.getUUID(player))) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(UUIDHandler.getUUID(player)) || this.trusted.contains(DBFunc.everyone))); + return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(UUIDHandler.getUUID(player))) || ((this.owner != null) && this.owner.equals(UUIDHandler.getUUID(player))) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.uuidWrapper.getPlayer(this.owner) != null) && (this.trusted.contains(UUIDHandler.getUUID(player)) || this.trusted.contains(DBFunc.everyone))); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java index 30c200de6..ff538103f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.util; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -16,5 +17,15 @@ public class DefaultUUIDWrapper extends UUIDWrapper { 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/util/OfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java index 2a4861247..fbf1e39e3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java @@ -2,10 +2,13 @@ package com.intellectualcrafters.plot.util; 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 { @@ -18,5 +21,34 @@ public class OfflineUUIDWrapper extends UUIDWrapper { 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/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index 8f23f1143..f989abf0f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -55,7 +55,7 @@ public class PlayerFunctions { * @return */ public static boolean hasExpired(final Plot plot) { - final OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner); + final OfflinePlayer player = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner); final long lp = player.getLastPlayed(); final long cu = System.currentTimeMillis(); return (lp - cu) > 30l; 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 4ec95bcc3..7b080e9d4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -273,7 +273,7 @@ public class PlotHelper { if (uuid == null) { return "unknown"; } - final OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid); + final OfflinePlayer plr = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); if (plr == null) { return "unknown"; } 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 aea945977..2234a65fb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -122,14 +122,14 @@ public class SchematicHandler { */ public static Schematic getSchematic(final String name) { { - final File parent = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics"); + final File parent = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics"); if (!parent.exists()) { if (!parent.mkdir()) { throw new RuntimeException("Could not create schematic parent directory"); } } } - final File file = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic"); + final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic"); if (!file.exists()) { PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist"); return null; 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 72544c39e..0f09d89be 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -194,7 +194,7 @@ public class UUIDHandler { if ((name = getNameOfflinePlayer(uuid)) != null) { return name; } - if (online) { + if (online && !Settings.OFFLINE_MODE) { if (!Settings.CUSTOM_API) { try { final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); @@ -251,7 +251,7 @@ public class UUIDHandler { * @return String - name */ private static String getNameOnlinePlayer(final UUID uuid) { - final Player player = Bukkit.getPlayer(uuid); + final Player player = uuidWrapper.getPlayer(uuid); if ((player == null) || !player.isOnline()) { return null; } @@ -259,13 +259,15 @@ public class UUIDHandler { 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 = Bukkit.getOfflinePlayer(uuid); + final OfflinePlayer player = uuidWrapper.getOfflinePlayer(uuid); if ((player == null) || !player.hasPlayedBefore()) { return null; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java index 3c09469e7..e1fc1b3a7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java @@ -9,4 +9,8 @@ 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); } 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 235199658..5b9bcc034 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -46,7 +46,7 @@ public class PlotUUIDSaver implements UUIDSaver { @Override public void globalPopulate() { - JavaPlugin.getPlugin(PlotMain.class).getServer().getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() { + Bukkit.getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() { @Override public void run() { final OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();