From dc025839f5cc62a707e2587cf5e21db5ffa7e354 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 21 Feb 2015 23:52:50 +1100 Subject: [PATCH] UUID --- .../intellectualcrafters/plot/BukkitMain.java | 2 +- .../plot/commands/Auto.java | 3 +- .../plot/commands/Buy.java | 13 +++--- .../plot/commands/Clear.java | 2 +- .../plot/commands/DebugClaimTest.java | 2 +- .../plot/commands/DebugClear.java | 2 +- .../plot/commands/Delete.java | 2 +- .../plot/commands/Info.java | 4 +- .../plot/commands/Merge.java | 6 +-- .../plot/commands/Paste.java | 2 +- .../plot/commands/SetOwner.java | 4 +- .../plot/commands/Unclaim.java | 2 +- .../plot/commands/Unlink.java | 6 +-- .../plot/listeners/WorldEditListener.java | 6 +-- .../plot/object/BukkitOfflinePlayer.java | 38 +++++++++++++++++ .../plot/object/BukkitPlayer.java | 2 +- .../plot/object/InfoInventory.java | 3 +- .../plot/object/OfflinePlotPlayer.java | 18 ++++++++ .../plot/object/Plot.java | 2 +- .../plot/util/ClusterManager.java | 5 ++- .../plot/util/EconHandler.java | 6 ++- .../plot/util/ExpireManager.java | 16 +++---- .../util/bukkit/BukkitPlayerFunctions.java | 9 ++-- .../plot/util/bukkit/BukkitUtil.java | 5 +-- .../plot/util/bukkit/PWE.java | 18 ++------ .../plot/util/bukkit/UUIDHandler.java | 42 ++++++++++++------- .../plot/uuid/DefaultUUIDWrapper.java | 22 ++++------ .../plot/uuid/OfflineUUIDWrapper.java | 24 +++++------ .../plot/uuid/UUIDWrapper.java | 12 +++--- 29 files changed, 167 insertions(+), 111 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitOfflinePlayer.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index fee316dac..9ca66e3e7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -57,7 +57,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @EventHandler public static void worldLoad(final WorldLoadEvent event) { - UUIDHandler.cacheAll(); + UUIDHandler.cacheAll(event.getWorld().getName()); } public static boolean checkVersion(final int major, final int minor, final int minor2) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 0f30da926..e16129fcf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -32,6 +32,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.ClusterManager; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -138,7 +139,7 @@ public class Auto extends SubCommand { sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); return true; } - EconHandler.withdrawPlayer(plr.getName(), cost); + EconHandler.withdrawPlayer(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index 5d0841bb2..0191f73c9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -70,13 +70,14 @@ public class Buy extends SubCommand { if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - if (BukkitPlayerFunctions.getPlayerPlotCount(world, plr) >= BukkitPlayerFunctions.getAllowedPlots(plr)) { + int currentPlots = MainUtil.getPlayerPlotCount(world, plr); + if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); } - if (plot.owner.equals(UUIDHandler.getUUID(plr))) { + if (plot.owner.equals(plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); } final Flag flag = FlagManager.getPlotFlag(plot, "price"); @@ -86,8 +87,8 @@ public class Buy extends SubCommand { double initPrice = (double) flag.getValue(); double price = initPrice; final PlotId id = plot.id; - final PlotId id2 = BukkitPlayerFunctions.getTopPlot(world, plot).id; - final int size = BukkitPlayerFunctions.getPlotSelectionIds(id, id2).size(); + final PlotId id2 = MainUtil.getTopPlot(world, plot).id; + final int size = MainUtil.getPlotSelectionIds(id, id2).size(); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); if (plotworld.USE_ECONOMY) { price += plotworld.PLOT_PRICE * size; @@ -100,14 +101,14 @@ public class Buy extends SubCommand { } EconHandler.withdrawPlayer(plr, price); sendMessage(plr, C.REMOVED_BALANCE, price + ""); - economy.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice); + EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice); final Player owner = UUIDHandler.uuidWrapper.getPlayer(plot.owner); if (owner != null) { sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + ""); } FlagManager.removePlotFlag(plot, "price"); } - plot.owner = UUIDHandler.getUUID(plr); + plot.owner = plr.getUUID(); DBFunc.setOwner(plot, plot.owner); MainUtil.sendMessage(plr, C.CLAIMED); return true; 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 d245d642a..447b3e464 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -67,7 +67,7 @@ public class Clear extends SubCommand { return sendMessage(plr, C.NOT_IN_PLOT); } final Plot plot = MainUtil.getPlot(loc); - if (!BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); } if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { 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 3afb20e24..699a1ad8d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -97,7 +97,7 @@ public class DebugClaimTest extends SubCommand { final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final ArrayList plots = new ArrayList<>(); - for (final PlotId id : BukkitPlayerFunctions.getPlotSelectionIds(min, max)) { + for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { final Plot plot = MainUtil.getPlot(world, id); final boolean contains = PlotSquared.getPlots(world).containsKey(plot.id); if (contains) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java index b1d7b316d..3f817236a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java @@ -85,7 +85,7 @@ public class DebugClear extends SubCommand { return sendMessage(plr, C.NOT_IN_PLOT); } final Plot plot = MainUtil.getPlot(loc); - if (!BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); } if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index d16999d8a..c6f06ae7c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -43,7 +43,7 @@ public class Delete extends SubCommand { return !sendMessage(plr, C.NOT_IN_PLOT); } final Plot plot = MainUtil.getPlot(loc); - if (!BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { 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 baa4e0559..f1bb0b464 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -163,8 +163,8 @@ public class Info extends SubCommand { private String format(String info, final World world, final Plot plot, final Player player) { final PlotId id = plot.id; - final PlotId id2 = BukkitPlayerFunctions.getTopPlot(world, plot).id; - final int num = BukkitPlayerFunctions.getPlotSelectionIds(id, id2).size(); + final PlotId id2 = MainUtil.getTopPlot(world, plot).id; + final int num = MainUtil.getPlotSelectionIds(id, id2).size(); final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"; final String biome = getBiomeAt(plot).toString(); final String helpers = getPlayerList(plot.helpers); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 4f8941dfb..37f872431 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -107,7 +107,7 @@ public class Merge extends SubCommand { } final World world = plr.getWorld(); PlotId bot = BukkitPlayerFunctions.getBottomPlot(world, plot).id; - PlotId top = BukkitPlayerFunctions.getTopPlot(world, plot).id; + PlotId top = MainUtil.getTopPlot(world, plot).id; ArrayList plots; switch (direction) { case 0: // north = -y @@ -129,8 +129,8 @@ public class Merge extends SubCommand { final PlotId topId = plots.get(plots.size() - 1); final PlotId bot1 = BukkitPlayerFunctions.getBottomPlot(world, MainUtil.getPlot(world, botId)).id; final PlotId bot2 = BukkitPlayerFunctions.getBottomPlot(world, MainUtil.getPlot(world, topId)).id; - final PlotId top1 = BukkitPlayerFunctions.getTopPlot(world, MainUtil.getPlot(world, topId)).id; - final PlotId top2 = BukkitPlayerFunctions.getTopPlot(world, MainUtil.getPlot(world, botId)).id; + final PlotId top1 = MainUtil.getTopPlot(world, MainUtil.getPlot(world, topId)).id; + final PlotId top2 = MainUtil.getTopPlot(world, MainUtil.getPlot(world, botId)).id; bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y)); top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y)); plots = BukkitPlayerFunctions.getMaxPlotSelectionIds(world, bot, top); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java index 70fcd2188..d347b2d56 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java @@ -43,7 +43,7 @@ public class Paste extends SubCommand { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if (!BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { MainUtil.sendMessage(plr, C.UNLINK_REQUIRED); return false; } 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 8c25d99b6..6712f851a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -66,8 +66,8 @@ public class SetOwner extends SubCommand { } final World world = plr.getWorld(); final PlotId bot = BukkitPlayerFunctions.getBottomPlot(world, plot).id; - final PlotId top = BukkitPlayerFunctions.getTopPlot(world, plot).id; - final ArrayList plots = BukkitPlayerFunctions.getPlotSelectionIds(bot, top); + final PlotId top = MainUtil.getTopPlot(world, plot).id; + final ArrayList plots = MainUtil.getPlotSelectionIds(bot, top); for (final PlotId id : plots) { final Plot current = PlotSquared.getPlots(world).get(id); final UUID uuid = getUUID(args[0]); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index 7c4a9413b..839fb5f08 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -45,7 +45,7 @@ public class Unclaim extends SubCommand { return !sendMessage(plr, C.NOT_IN_PLOT); } final Plot plot = MainUtil.getPlot(loc); - if (!BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { 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 fb0d40673..2b5cb847f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -58,7 +58,7 @@ public class Unlink extends SubCommand { if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { return sendMessage(plr, C.NO_PLOT_PERMS); } - if (BukkitPlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return sendMessage(plr, C.UNLINK_IMPOSSIBLE); } final World world = plr.getWorld(); @@ -82,8 +82,8 @@ public class Unlink extends SubCommand { public static boolean unlinkPlot(final World world, final Plot plot) { final PlotId pos1 = BukkitPlayerFunctions.getBottomPlot(world, plot).id; - final PlotId pos2 = BukkitPlayerFunctions.getTopPlot(world, plot).id; - final ArrayList ids = BukkitPlayerFunctions.getPlotSelectionIds(pos1, pos2); + final PlotId pos2 = MainUtil.getTopPlot(world, plot).id; + final ArrayList ids = MainUtil.getPlotSelectionIds(pos1, pos2); final PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { 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 3cbe411b4..4aa9d4f4b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -78,14 +78,14 @@ public class WorldEditListener implements Listener { if ((plot == null) || (plot.owner == null)) { return; } - final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.owner); + final PlotPlayer player = UUIDHandler.getPlayer(plot.owner); if (player == null) { return; } - if (!world.equals(player.getWorld().getName())) { + if (!world.equals(player.getLocation().getWorld())) { return; } - if (Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.worldedit.bypass")) { + if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { return; } PWE.setNoMask(player); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitOfflinePlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitOfflinePlayer.java new file mode 100644 index 000000000..c09e291be --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitOfflinePlayer.java @@ -0,0 +1,38 @@ +package com.intellectualcrafters.plot.object; + +import java.util.UUID; + +import org.bukkit.OfflinePlayer; + +public class BukkitOfflinePlayer implements OfflinePlotPlayer { + + public final OfflinePlayer player; + + /** + * Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. + * @param player + */ + public BukkitOfflinePlayer(OfflinePlayer player) { + this.player = player; + } + + @Override + public UUID getUUID() { + return player.getUniqueId(); + } + + @Override + public long getLastPlayed() { + return player.getLastPlayed(); + } + + @Override + public boolean isOnline() { + return player.isOnline(); + } + + @Override + public String getName() { + return player.getName(); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 5d494de28..5c75a4ebf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -33,7 +33,7 @@ public class BukkitPlayer implements PlotPlayer { @Override public UUID getUUID() { if (this.uuid == null) { - this.uuid = UUIDHandler.getUUID(this.player); + this.uuid = UUIDHandler.getUUID(this); } return this.uuid; } 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 040b5877f..d1da24fb4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** @@ -50,7 +51,7 @@ public class InfoInventory implements InventoryHolder { } public InfoInventory build() { - UUID uuid = UUIDHandler.getUUID(player); + UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(player)); final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.getOwner()), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid)); final ItemStack helpers = getItem(Material.EMERALD, "&cHelpers", "&cAmount: &6" + this.plot.helpers.size(), "&8Click to view a list of the plot helpers"); final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of trusted players"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java new file mode 100644 index 000000000..41d3865fe --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java @@ -0,0 +1,18 @@ +package com.intellectualcrafters.plot.object; + +import java.util.UUID; + +/** + * Created 2015-02-20 for PlotSquared + * + * @author Citymonstret + */ +public interface OfflinePlotPlayer { + public UUID getUUID(); + + public long getLastPlayed(); + + public boolean isOnline(); + + public String getName(); +} 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 40cfec017..a11eef6f0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -147,7 +147,7 @@ public class Plot implements Cloneable { * @return true if the player is added as a helper or is the owner */ public boolean isAdded(final UUID uuid) { - return ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(uuid)) || ((this.owner != null) && this.owner.equals(uuid)) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.uuidWrapper.getPlayer(this.owner) != null) && (this.trusted.contains(uuid) || this.trusted.contains(DBFunc.everyone))); + return ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(uuid)) || ((this.owner != null) && this.owner.equals(uuid)) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.getPlayer(this.owner) != null) && (this.trusted.contains(uuid) || this.trusted.contains(DBFunc.everyone))); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 67cd05ef3..4a9c77f8d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -22,6 +22,7 @@ import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.SetBlockManager; @@ -258,9 +259,9 @@ public class ClusterManager { @Override public void run() { ClusterManager.regenerating.remove(cluster.world + ":" + cluster.getName()); - final Player owner = UUIDHandler.uuidWrapper.getPlayer(cluster.owner); + final PlotPlayer owner = UUIDHandler.getPlayer(cluster.owner); if (owner != null) { - MainUtil.sendMessage(BukkitUtil.getPlayer(owner), C.CLEARING_DONE); + MainUtil.sendMessage(owner, C.CLEARING_DONE); } } }, (interval * chunks.size()) + 20); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java index 8cca6b826..63cc1600e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java @@ -10,6 +10,10 @@ public class EconHandler { } public static void withdrawPlayer(PlotPlayer player, double amount) { - EconHandler.withdrawPlayer(player.getName(), amount); + PlotSquared.economy.withdrawPlayer(player.getName(), amount); + } + + public static void depositPlayer(PlotPlayer player, double amount) { + PlotSquared.economy.depositPlayer(player.getName(), amount); } } 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 4647058f6..945680cd8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -19,8 +19,10 @@ 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.Plot; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -86,7 +88,7 @@ public class ExpireManager { } final Plot plot = plots.iterator().next(); if (plot.owner != null) { - if (UUIDHandler.uuidWrapper.getPlayer(plot.owner) != null) { + if (UUIDHandler.getPlayer(plot.owner) != null) { expiredPlots.get(world).remove(plot); return; } @@ -102,9 +104,9 @@ public class ExpireManager { return; } for (final UUID helper : plot.helpers) { - final Player player = UUIDHandler.uuidWrapper.getPlayer(helper); + final PlotPlayer player = UUIDHandler.getPlayer(helper); if (player != null) { - MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.PLOT_REMOVED_HELPER, plot.id.toString()); + MainUtil.sendMessage(player, C.PLOT_REMOVED_HELPER, plot.id.toString()); } } final PlotManager manager = PlotSquared.getPlotManager(world); @@ -165,13 +167,13 @@ public class ExpireManager { if (keep.contains(uuid)) { continue; } - final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); + final PlotPlayer player = UUIDHandler.getPlayer(uuid); if (player != null) { keep.add(uuid); continue; } - final OfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); - if ((op == null) || !op.hasPlayedBefore()) { + final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); + if ((op == null) || op.getLastPlayed() == 0) { continue; } long last = op.getLastPlayed(); @@ -184,7 +186,7 @@ public class ExpireManager { if (BukkitMain.checkVersion(1, 7, 5)) { foldername = "playerdata"; try { - filename = op.getUniqueId() + ".dat"; + filename = op.getUUID() + ".dat"; } catch (final Throwable e) { filename = uuid.toString() + ".dat"; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java index 1f6f2d31d..67c08488c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java @@ -35,6 +35,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; /** @@ -88,7 +89,7 @@ public class BukkitPlayerFunctions { MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.CANNOT_AFFORD_MERGE, "" + cost); return false; } - EconHandler.withdrawPlayer(plr, cost); + EconHandler.withdrawPlayer(BukkitUtil.getPlayer(plr), cost); MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.REMOVED_BALANCE, cost + ""); } } @@ -99,11 +100,11 @@ public class BukkitPlayerFunctions { if (uuid == null) { return "unknown"; } - final OfflinePlayer plr = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); - if (!plr.hasPlayedBefore()) { + final String name = UUIDHandler.getName(uuid); + if (name == null) { return "unknown"; } - return plr.getName(); + return name; } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java index b8d708fb7..14ed0e05d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java @@ -27,7 +27,6 @@ public class BukkitUtil extends BlockManager { private static String lastString = null; private static World lastWorld = null; - private static HashMap players = new HashMap<>(); private static Player lastPlayer = null; private static PlotPlayer lastPlotPlayer = null; @@ -36,7 +35,7 @@ public class BukkitUtil extends BlockManager { lastPlayer = null; lastPlotPlayer = null; } - players.remove(plr); + UUIDHandler.players.remove(plr); } public static PlotPlayer getPlayer(Player player) { @@ -44,7 +43,7 @@ public class BukkitUtil extends BlockManager { return lastPlotPlayer; } lastPlotPlayer = new BukkitPlayer(player); - players.put(lastPlotPlayer.getName(), lastPlotPlayer); + UUIDHandler.players.put(lastPlotPlayer.getName(), lastPlotPlayer); lastPlayer = player; return lastPlotPlayer; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java index 6f61cf1ce..c398a4fc6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java @@ -86,13 +86,8 @@ public class PWE { } } - public static boolean hasMask(final Player p) { - LocalSession s; - if (PlotSquared.worldEdit == null) { - s = WorldEdit.getInstance().getSession(p.getName()); - } else { - s = PlotSquared.worldEdit.getSession(p); - } + public static boolean hasMask(final PlotPlayer p) { + LocalSession s = WorldEdit.getInstance().getSession(p.getName()); return !noMask(s); } @@ -101,14 +96,9 @@ public class PWE { } @SuppressWarnings("deprecation") - public static void setNoMask(final Player p) { + public static void setNoMask(final PlotPlayer p) { try { - LocalSession s; - if (PlotSquared.worldEdit == null) { - s = WorldEdit.getInstance().getSession(p.getName()); - } else { - s = PlotSquared.worldEdit.getSession(p); - } + LocalSession s = WorldEdit.getInstance().getSession(p.getName()); final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player); final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); 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 98f5076ef..a57033c51 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 @@ -6,16 +6,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.PlotSquared; 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.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; @@ -24,6 +22,8 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper; public class UUIDHandler { public static boolean CACHED = false; public static UUIDWrapper uuidWrapper = null; + public static HashMap players = new HashMap<>(); + /** * Map containing names and UUIDs * @@ -77,14 +77,14 @@ public class UUIDHandler { return uuidMap.containsKey(name); } - public static void cacheAll() { + public static void cacheAll(String world) { if (CACHED) { return; } PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching"); UUIDHandler.CACHED = true; final HashSet worlds = new HashSet<>(); - worlds.add(Bukkit.getWorlds().get(0).getName()); + worlds.add(world); worlds.add("world"); final HashSet uuids = new HashSet<>(); final HashSet names = new HashSet<>(); @@ -125,7 +125,7 @@ public class UUIDHandler { final UUIDWrapper wrapper = new DefaultUUIDWrapper(); for (UUID uuid : uuids) { try { - final OfflinePlayer player = wrapper.getOfflinePlayer(uuid); + final BukkitOfflinePlayer player = wrapper.getOfflinePlayer(uuid); uuid = UUIDHandler.uuidWrapper.getUUID(player); final StringWrapper name = new StringWrapper(player.getName()); add(name, uuid); @@ -134,8 +134,7 @@ public class UUIDHandler { } } for (final String name : names) { - final OfflinePlayer player = Bukkit.getOfflinePlayer(name); - final UUID uuid = UUIDHandler.uuidWrapper.getUUID(player); + final UUID uuid = uuidWrapper.getUUID(name); final StringWrapper nameWrap = new StringWrapper(name); add(nameWrap, uuid); } @@ -144,11 +143,11 @@ public class UUIDHandler { PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); } - public static UUID getUUID(final Player player) { + public static UUID getUUID(final PlotPlayer player) { return UUIDHandler.uuidWrapper.getUUID(player); } - public static UUID getUUID(final OfflinePlayer player) { + public static UUID getUUID(final BukkitOfflinePlayer player) { return UUIDHandler.uuidWrapper.getUUID(player); } @@ -157,7 +156,7 @@ public class UUIDHandler { return null; } // check online - final Player player = uuidWrapper.getPlayer(uuid); + final PlotPlayer player = UUIDHandler.getPlayer(uuid); if (player != null) { return player.getName(); } @@ -169,16 +168,27 @@ public class UUIDHandler { return null; } + public static PlotPlayer getPlayer(UUID uuid) { + for (PlotPlayer player : players.values()) { + if (player.getUUID().equals(uuid)) { + return player; + } + } + return null; + } + + public static PlotPlayer getPlayer(String name) { + return players.get(name); + } + public static UUID getUUID(final String name) { if ((name == null) || (name.length() == 0)) { return null; } // check online - final Player player = Bukkit.getPlayer(name); + final PlotPlayer player = getPlayer(name); if (player != null) { - final UUID uuid = UUIDHandler.uuidWrapper.getUUID(player); - add(new StringWrapper(name), uuid); - return uuid; + return player.getUUID(); } // check cache final StringWrapper wrap = new StringWrapper(name); 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 f251dd4d1..ca0427ae9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java @@ -3,28 +3,24 @@ package com.intellectualcrafters.plot.uuid; import java.util.UUID; import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.BukkitPlayer;; public class DefaultUUIDWrapper extends UUIDWrapper { @Override - public UUID getUUID(final Player player) { - return player.getUniqueId(); + public UUID getUUID(final PlotPlayer player) { + return ((BukkitPlayer) player).player.getUniqueId(); } @Override - public UUID getUUID(final OfflinePlayer player) { - return player.getUniqueId(); + public UUID getUUID(final BukkitOfflinePlayer player) { + return player.getUUID(); } @Override - public OfflinePlayer getOfflinePlayer(final UUID uuid) { - return Bukkit.getOfflinePlayer(uuid); - } - - @Override - public Player getPlayer(final UUID uuid) { - return Bukkit.getPlayer(uuid); + public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) { + return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid)); } @Override 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 1957cc0a4..0d7b6e167 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -11,6 +11,8 @@ import org.bukkit.entity.Player; import com.google.common.base.Charsets; import com.google.common.collect.BiMap; +import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -29,17 +31,21 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } @Override - public UUID getUUID(final Player player) { + public UUID getUUID(final PlotPlayer player) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @Override + public UUID getUUID(final BukkitOfflinePlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + } + public UUID getUUID(final OfflinePlayer player) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @Override - public OfflinePlayer getOfflinePlayer(final UUID uuid) { + public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) { final BiMap map = UUIDHandler.getUuidMap().inverse(); String name; try { @@ -50,12 +56,12 @@ public class OfflineUUIDWrapper extends UUIDWrapper { if (name != null) { final OfflinePlayer op = Bukkit.getOfflinePlayer(name); if (op.hasPlayedBefore()) { - return op; + return new BukkitOfflinePlayer(op); } } for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) { if (getUUID(player).equals(uuid)) { - return player; + return new BukkitOfflinePlayer(player); } } return null; @@ -81,16 +87,6 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } } - @Override - public Player getPlayer(final UUID uuid) { - for (final Player player : getOnlinePlayers()) { - if (getUUID(player).equals(uuid)) { - return player; - } - } - return null; - } - @Override public UUID getUUID(final String name) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); 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 09b3fa649..33b5623a6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java @@ -2,17 +2,15 @@ package com.intellectualcrafters.plot.uuid; import java.util.UUID; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; public abstract class UUIDWrapper { - public abstract UUID getUUID(Player player); + public abstract UUID getUUID(PlotPlayer player); - public abstract UUID getUUID(OfflinePlayer player); + public abstract UUID getUUID(BukkitOfflinePlayer player); public abstract UUID getUUID(String name); - public abstract OfflinePlayer getOfflinePlayer(UUID uuid); - - public abstract Player getPlayer(UUID uuid); + public abstract BukkitOfflinePlayer getOfflinePlayer(UUID uuid); }