diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 0bad7ac2d..632a4532c 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.PlayerManager; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.plotsquared.bukkit.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -63,7 +64,7 @@ public interface IPlotMain { public HybridUtils initHybridUtils(); - public UUIDWrapper initUUIDHandler(); + public UUIDHandlerImplementation initUUIDHandler(); public InventoryUtil initInventoryUtil(); diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 16c434d16..dda181c75 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -72,8 +72,8 @@ import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.PlayerManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.SetupUtils; -import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @@ -171,7 +171,7 @@ public class PS { IMP.registerChunkProcessor(); } // create UUIDWrapper - UUIDHandler.setUUIDWrapper(IMP.initUUIDHandler()); + UUIDHandler.implementation = IMP.initUUIDHandler(); // create event util class EventUtil.manager = IMP.initEventUtil(); // create Hybrid utility class @@ -598,7 +598,7 @@ public class PS { * @return Set of Plot */ public Set getPlots(final String world, final String player) { - final UUID uuid = UUIDHandler.getUUID(player); + final UUID uuid = UUIDHandler.getUUID(player, null); return getPlots(world, uuid); } @@ -1515,8 +1515,6 @@ public class PS { Settings.FANCY_CHAT = false; } Settings.METRICS = config.getBoolean("metrics"); - - UUIDHandler.implementation = Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler() : new FileUUIDHandler(); } diff --git a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index da9cddcea..74f824ceb 100644 --- a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -48,7 +48,7 @@ import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitSetBlockManager; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.uuid.UUIDWrapper; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Add.java b/src/main/java/com/intellectualcrafters/plot/commands/Add.java index f7e1bfc4f..76e2cf790 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Add.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Add.java @@ -31,11 +31,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; - -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index bb04ad6a8..0ba318ee3 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -34,9 +34,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "buy", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index d2d3ab44f..68079ff44 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -34,9 +34,9 @@ import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "clear", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 79cb25fc8..b71f2722f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -47,8 +47,8 @@ import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.SetupUtils; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "cluser", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 16bc80951..1840a2cfd 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -14,9 +14,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "database", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 94732474c..c26db1ca4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -39,9 +39,9 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "debugclaimtest", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java index 083d6e5aa..fc13bb66c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java @@ -31,9 +31,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "debugclear", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 8f024bf44..08a541d37 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -33,7 +33,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -52,6 +52,7 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; @CommandDeclaration( command = "debugexec", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java index d2873a4bc..01a7ff053 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -31,7 +31,7 @@ import java.util.UUID; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.bukkit.Bukkit; import com.intellectualcrafters.plot.PS; @@ -46,7 +46,7 @@ import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.TaskManager; - +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index eca0d33fa..17c200d52 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "delete", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index 024705270..90e2fe1f1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -31,11 +31,10 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; - -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/src/main/java/com/intellectualcrafters/plot/commands/Info.java index d6ec58d6f..347c65b9f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; @@ -45,6 +45,7 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; @CommandDeclaration( command = "info", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 97e2de4dc..01243156c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -27,9 +27,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "kick", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index d37a6cbab..26f5f8ad8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -27,7 +27,7 @@ import java.util.UUID; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.PS; @@ -42,6 +42,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; @CommandDeclaration( command = "merge", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index e0f17534f..92f2494cf 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -31,9 +31,9 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java index 5872909d1..041e22d3d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java @@ -30,11 +30,10 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; - -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/src/main/java/com/intellectualcrafters/plot/commands/Set.java index b6b5b014b..055a4ce4b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -26,7 +26,7 @@ import java.util.List; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.PS; @@ -50,6 +50,7 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.UUIDHandler; // TODO Make sub-subcommands diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index 5b8880d4f..2759c87c0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -33,10 +33,10 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "setowner", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/TP.java b/src/main/java/com/intellectualcrafters/plot/commands/TP.java index ac9d80596..33bd9fe5f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/TP.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/TP.java @@ -23,7 +23,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.PS; @@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; @CommandDeclaration( command = "tp", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Trust.java b/src/main/java/com/intellectualcrafters/plot/commands/Trust.java index 2091c5244..6fb3247a4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Trust.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Trust.java @@ -31,10 +31,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Undeny.java b/src/main/java/com/intellectualcrafters/plot/commands/Undeny.java index f0a01f976..fd87d5c17 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Undeny.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Undeny.java @@ -29,11 +29,10 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; - -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Untrust.java b/src/main/java/com/intellectualcrafters/plot/commands/Untrust.java index cf9ca0239..0f9c3471d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Untrust.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Untrust.java @@ -29,10 +29,10 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; // UNTRUST("untrust", "ut"), diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index c9b54b536..e53da4d46 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -30,10 +30,10 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; @CommandDeclaration( command = "visit", diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index 6e07a3ddf..41a2598c6 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -32,7 +32,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandCaller; -import com.plotsquared.bukkit.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -49,7 +49,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringComparison; - +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.chat.FancyMessage; @CommandDeclaration( diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java b/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java index 6e78b2452..46f7021da 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java @@ -7,7 +7,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; public class PlotHandler { public static HashSet getOwners(Plot plot) { diff --git a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index f61d39e5b..4f63e6310 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -23,7 +23,6 @@ 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.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; public class ClusterManager { diff --git a/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index c0166ac57..c1983f92f 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -22,7 +22,6 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal; -import com.plotsquared.bukkit.util.UUIDHandler; public class ExpireManager { public static ConcurrentHashMap> expiredPlots = new ConcurrentHashMap<>(); diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 5bc7bfd91..da4c3f365 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -45,7 +45,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RunnableVal; -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; /** @@ -110,7 +109,7 @@ public class MainUtil { for (String term : split) { try { - UUID uuid = UUIDHandler.getUUID(term); + UUID uuid = UUIDHandler.getUUID(term, null); if (uuid == null) { uuid = UUID.fromString(term); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 08d5c0950..0f8231ff7 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -47,7 +47,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.plotsquared.bukkit.object.schematic.StateWrapper; -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.WorldEditSchematic; import com.plotsquared.bukkit.util.bukkit.BukkitSchematicHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; diff --git a/src/main/java/com/plotsquared/bukkit/util/UUIDHandler.java b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java similarity index 84% rename from src/main/java/com/plotsquared/bukkit/util/UUIDHandler.java rename to src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index e6bb5c38a..7751b069d 100644 --- a/src/main/java/com/plotsquared/bukkit/util/UUIDHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -1,16 +1,15 @@ -package com.plotsquared.bukkit.util; +package com.intellectualcrafters.plot.util; import java.util.HashSet; import java.util.Map; import java.util.UUID; -import com.plotsquared.bukkit.util.bukkit.uuid.UUIDHandlerImplementation; - import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.PS; -import com.plotsquared.bukkit.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -84,15 +83,15 @@ public class UUIDHandler { implementation.startCaching(); } - public static void cache(final Map toAdd) { - implementation.cache(toAdd); + public static void cache(final BiMap toAdd) { + implementation.add(toAdd); } public static UUID getUUID(final PlotPlayer player) { return implementation.getUUID(player); } - public static UUID getUUID(final BukkitOfflinePlayer player) { + public static UUID getUUID(final OfflinePlotPlayer player) { return implementation.getUUID(player); } @@ -108,18 +107,14 @@ public class UUIDHandler { return implementation.getPlayer(name); } - public static UUID getUUID(final String name) { - return implementation.getUUID(name); + public static UUID getUUID(final String name, RunnableVal ifFetch) { + return implementation.getUUID(name, ifFetch); } public static Map getPlayers() { return implementation.getPlayers(); } - public static void cacheWorld(String world) { - implementation.cacheWorld(world); - } - public static void handleShutdown() { implementation.handleShutdown(); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java new file mode 100644 index 000000000..e69c5ea59 --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -0,0 +1,176 @@ +package com.intellectualcrafters.plot.util; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public abstract class UUIDHandlerImplementation { + + private BiMap uuidMap = HashBiMap.create(new HashMap()); + public boolean CACHED = false; + public UUIDWrapper uuidWrapper = null; + public final HashMap players; + + public UUIDHandlerImplementation(UUIDWrapper wrapper) { + this.uuidWrapper = wrapper; + this.players = new HashMap<>(); + } + + /** + * If the UUID is not found, some commands can request to fetch the UUID when possible + * @param player + * @param ifFetch + */ + public abstract void fetchUUID(String name, RunnableVal ifFetch); + + /** + * Start UUID caching (this should be an async task) + * Recommended to override this is you want to cache offline players + */ + public boolean startCaching() { + if (CACHED) { + return false; + } + return this.CACHED = true; + } + + public UUIDWrapper getUUIDWrapper() { + return this.uuidWrapper; + } + + public void setUUIDWrapper(UUIDWrapper wrapper) { + this.uuidWrapper = wrapper; + } + + public void add(final BiMap toAdd) { + if (uuidMap.size() == 0) { + uuidMap = toAdd; + } + TaskManager.runTask(new Runnable() { + @Override + public void run() { + for (Map.Entry entry : toAdd.entrySet()) { + add(entry.getKey(), entry.getValue()); + } + PS.log(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs"); + } + }); + } + + public boolean add(final StringWrapper name, final UUID uuid) { + if ((uuid == null) || (name == null)) { + return false; + } + BiMap inverse = uuidMap.inverse(); + if (inverse.containsKey(uuid)) { + if (uuidMap.containsKey(name)) { + return false; + } + inverse.remove(uuid); + } + uuidMap.put(name, uuid); + return true; + } + + public boolean uuidExists(final UUID uuid) { + return uuidMap.containsValue(uuid); + } + + public BiMap getUUIDMap() { + return uuidMap; + } + + public boolean nameExists(final StringWrapper wrapper) { + return uuidMap.containsKey(wrapper); + } + + public void handleShutdown() { + players.clear(); + uuidMap.clear(); + uuidWrapper = null; + } + + public String getName(final UUID uuid) { + if (uuid == null) { + return null; + } + // check online + final PlotPlayer player = getPlayer(uuid); + if (player != null) { + return player.getName(); + } + // check cache + final StringWrapper name = uuidMap.inverse().get(uuid); + if (name != null) { + return name.value; + } + return null; + } + + public UUID getUUID(final String name, RunnableVal ifFetch) { + if ((name == null) || (name.length() == 0)) { + return null; + } + // check online + final PlotPlayer player = getPlayer(name); + if (player != null) { + return player.getUUID(); + } + // check cache + final StringWrapper wrap = new StringWrapper(name); + UUID uuid = uuidMap.get(wrap); + if (uuid != null) { + return uuid; + } + // Read from disk OR convert directly to offline UUID + if (uuidWrapper instanceof OfflineUUIDWrapper || uuidWrapper instanceof LowerOfflineUUIDWrapper) { + uuid = uuidWrapper.getUUID(name); + add(new StringWrapper(name), uuid); + return uuid; + } + if (Settings.UUID_FROM_DISK && ifFetch != null) { + fetchUUID(name, ifFetch); + return null; + } + return null; + } + + public UUID getUUID(final PlotPlayer player) { + return uuidWrapper.getUUID(player); + } + + public UUID getUUID(final OfflinePlotPlayer player) { + return uuidWrapper.getUUID(player); + } + + public PlotPlayer getPlayer(final UUID uuid) { + for (final PlotPlayer player : players.values()) { + if (player.getUUID().equals(uuid)) { + return player; + } + } + return null; + } + + public PlotPlayer getPlayer(String name) { + return players.get(name); + } + + public Map getPlayers() { + return players; + } + +} diff --git a/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java b/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java index 26ce82799..b1d6f288c 100644 --- a/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java +++ b/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java @@ -16,7 +16,7 @@ import com.plotsquared.bukkit.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper { private Method getOnline = null; diff --git a/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java b/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java index 187d831c0..08c8c51a0 100644 --- a/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java +++ b/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -16,7 +16,7 @@ import com.plotsquared.bukkit.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; public class OfflineUUIDWrapper extends UUIDWrapper { private Method getOnline = null; diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 9d64f61be..97c9963ba 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -27,8 +27,9 @@ import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.bukkit.util.SetupUtils; -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.*; +import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler; +import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.WorldEditPlugin; @@ -428,23 +429,24 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } @Override - public UUIDWrapper initUUIDHandler() { + public UUIDHandlerImplementation initUUIDHandler() { final boolean checkVersion = PS.get().checkVersion(this.getServerVersion(), 1, 7, 6); + UUIDWrapper wrapper; if (Settings.OFFLINE_MODE) { if (Settings.UUID_LOWERCASE) { - UUIDHandler.setUUIDWrapper(new LowerOfflineUUIDWrapper()); + wrapper = (new LowerOfflineUUIDWrapper()); } else { - UUIDHandler.setUUIDWrapper(new OfflineUUIDWrapper()); + wrapper = (new OfflineUUIDWrapper()); } Settings.OFFLINE_MODE = true; } else if (checkVersion) { - UUIDHandler.setUUIDWrapper(new DefaultUUIDWrapper()); + wrapper = (new DefaultUUIDWrapper()); Settings.OFFLINE_MODE = false; } else { if (Settings.UUID_LOWERCASE) { - UUIDHandler.setUUIDWrapper(new LowerOfflineUUIDWrapper()); + wrapper = (new LowerOfflineUUIDWrapper()); } else { - UUIDHandler.setUUIDWrapper(new OfflineUUIDWrapper()); + wrapper = (new OfflineUUIDWrapper()); } Settings.OFFLINE_MODE = true; } @@ -465,7 +467,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } else { log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs"); } - return UUIDHandler.getUUIDWrapper(); + return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper); } @Override diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java index 9bab014af..65fbf6948 100644 --- a/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java +++ b/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java @@ -20,7 +20,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; public class ClassicPlotMeConnector extends APlotMeConnector { diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java index c8d00d478..b6c0744d9 100644 --- a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java +++ b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java @@ -20,7 +20,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; public class PlotMeConnector_017 extends APlotMeConnector { private String plugin; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java index ed705c1f5..0ec5fc635 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitPlayerFunctions; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 376f90c65..fa4573f6a 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -113,7 +113,7 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.RegExUtil; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; /** diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java b/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java index 66ed3c0c1..e7d2cd2c9 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java @@ -49,7 +49,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * @author Citymonstret diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java b/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java index 0215029c3..8b24cbac4 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -53,7 +53,7 @@ import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; /** diff --git a/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java index 70d2d3bc5..3edd76f77 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java @@ -9,9 +9,9 @@ import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.plotsquared.bukkit.util.UUIDHandler; public class WorldEvents implements Listener { @@ -47,6 +47,6 @@ public class WorldEvents implements Listener { @EventHandler public void worldLoad(final WorldLoadEvent event) { - UUIDHandler.cacheWorld(event.getWorld().getName()); + UUIDHandler.startCaching(); } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java index 971b6337e..62d5ee86a 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java @@ -9,7 +9,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index f5c6e4225..67236a987 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -14,7 +14,7 @@ import org.bukkit.permissions.PermissionDefault; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.util.EconHandler; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; public class BukkitPlayer implements PlotPlayer { diff --git a/src/main/java/com/plotsquared/bukkit/object/InfoInventory.java b/src/main/java/com/plotsquared/bukkit/object/InfoInventory.java index 505156fa1..79dde8c97 100644 --- a/src/main/java/com/plotsquared/bukkit/object/InfoInventory.java +++ b/src/main/java/com/plotsquared/bukkit/object/InfoInventory.java @@ -6,6 +6,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.UUIDHandler; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -16,7 +17,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.BukkitUtil; /** diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitPlayerFunctions.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitPlayerFunctions.java index 2a34ebd79..861e4ba5c 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitPlayerFunctions.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitPlayerFunctions.java @@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.bukkit.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * Functions involving players, plots and locations. diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java index 43879bb94..f88a1ed7a 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java @@ -26,7 +26,6 @@ import org.bukkit.material.WoodenStep; import org.bukkit.material.Wool; import com.plotsquared.bukkit.object.BukkitPlayer; -import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; @@ -36,6 +35,7 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualcrafters.plot.util.UUIDHandler; public class BukkitUtil extends BlockManager { private static HashMap worlds = new HashMap<>(); diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/FileUUIDHandler.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/FileUUIDHandler.java index 5a0a8ba8c..973006524 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/FileUUIDHandler.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/FileUUIDHandler.java @@ -1,6 +1,16 @@ package com.plotsquared.bukkit.util.bukkit.uuid; -import com.google.common.collect.BiMap; +import java.io.File; +import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.World; + import com.google.common.collect.HashBiMap; import com.google.common.io.Files; import com.google.common.io.InputSupplier; @@ -8,99 +18,42 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.NbtFactory; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.object.BukkitOfflinePlayer; -import com.plotsquared.bukkit.util.UUIDHandler; -import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.uuid.UUIDWrapper; -import org.bukkit.Bukkit; +public class FileUUIDHandler extends UUIDHandlerImplementation { -import java.io.File; -import java.io.FileInputStream; -import java.io.FilenameFilter; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.UUID; - -public class FileUUIDHandler implements UUIDHandlerImplementation { - - private final BiMap uuidMap = HashBiMap.create(new HashMap()); - public boolean CACHED = false; - public UUIDWrapper uuidWrapper = null; - public HashMap players = new HashMap<>(); - - @Override - public void add(final StringWrapper name, final UUID uuid) { - if ((uuid == null) || (name == null)) { - return; - } - BiMap inverse = uuidMap.inverse(); - if (inverse.containsKey(uuid)) { - if (uuidMap.containsKey(name)) { - return; - } - inverse.remove(uuid); - } - uuidMap.put(name, uuid); + public FileUUIDHandler(UUIDWrapper wrapper) { + super(wrapper); } - + @Override - public void handleShutdown() {} - - @Override - public BiMap getUUIDMap() { - return uuidMap; - } - - @Override - public boolean uuidExists(final UUID uuid) { - return uuidMap.containsValue(uuid); - } - - @Override - public boolean nameExists(final StringWrapper name) { - return uuidMap.containsKey(name); - } - - @Override - public void startCaching() { - if (Bukkit.getWorlds().size() > 1) { - cacheWorld(Bukkit.getWorlds().get(0).getName()); - } - } - - @Override - public void setUUIDWrapper(UUIDWrapper wrapper) { - this.uuidWrapper = wrapper; - } - - @Override - public UUIDWrapper getUUIDWrapper() { - return uuidWrapper; - } - - @Override - public Map getPlayers() { - return players; - } - - @Override - public void cacheWorld(final String world) { - if (CACHED) { - return; + public boolean startCaching() { + if (!super.startCaching()) { + return false; } final File container = Bukkit.getWorldContainer(); + List worlds = Bukkit.getWorlds(); + final String world; + if (worlds.size() == 0) { + world = "world"; + } + else { + world = worlds.get(0).getName(); + } CACHED = true; TaskManager.runTaskAsync(new Runnable() { @Override public void run() { PS.log(C.PREFIX.s() + "&6Starting player data caching for: " + world); - final HashMap toAdd = new HashMap<>(); + final HashBiMap toAdd = HashBiMap.create(new HashMap()); toAdd.put(new StringWrapper("*"), DBFunc.everyone); if (Settings.TWIN_MODE_UUID) { HashSet all = UUIDHandler.getAllUUIDS(); @@ -134,7 +87,7 @@ public class FileUUIDHandler implements UUIDHandlerImplementation { } } } - cache(toAdd); + add(toAdd); return; } final HashSet worlds = new HashSet<>(); @@ -208,7 +161,7 @@ public class FileUUIDHandler implements UUIDHandlerImplementation { toAdd.put(nameWrap, uuid); } - if (uuidMap.size() == 0) { + if (getUUIDMap().size() == 0) { for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { if (op.getLastPlayed() != 0) { String name = op.getName(); @@ -218,89 +171,20 @@ public class FileUUIDHandler implements UUIDHandlerImplementation { } } } - cache(toAdd); + add(toAdd); } }); + return true; } @Override - public void cache(final Map toAdd) { - TaskManager.runTask(new Runnable() { + public void fetchUUID(final String name, final RunnableVal ifFetch) { + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - for (Map.Entry entry : toAdd.entrySet()) { - add(entry.getKey(), entry.getValue()); - } - PS.log(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs"); + ifFetch.value = uuidWrapper.getUUID(name); + TaskManager.runTask(ifFetch); } }); } - - @Override - public UUID getUUID(final PlotPlayer player) { - return uuidWrapper.getUUID(player); - } - - @Override - public UUID getUUID(final BukkitOfflinePlayer player) { - return uuidWrapper.getUUID(player); - } - - @Override - public String getName(final UUID uuid) { - if (uuid == null) { - return null; - } - // check online - final PlotPlayer player = getPlayer(uuid); - if (player != null) { - return player.getName(); - } - // check cache - final StringWrapper name = uuidMap.inverse().get(uuid); - if (name != null) { - return name.value; - } - return null; - } - - @Override - public PlotPlayer getPlayer(final UUID uuid) { - for (final PlotPlayer player : players.values()) { - if (player.getUUID().equals(uuid)) { - return player; - } - } - return null; - } - - @Override - public PlotPlayer getPlayer(final String name) { - return players.get(name); - } - - @Override - public UUID getUUID(final String name) { - if ((name == null) || (name.length() == 0)) { - return null; - } - // check online - final PlotPlayer player = getPlayer(name); - if (player != null) { - return player.getUUID(); - } - // check cache - final StringWrapper wrap = new StringWrapper(name); - UUID uuid = uuidMap.get(wrap); - if (uuid != null) { - return uuid; - } - // Read from disk OR convert directly to offline UUID - if (Settings.UUID_FROM_DISK || (uuidWrapper instanceof OfflineUUIDWrapper)) { - uuid = uuidWrapper.getUUID(name); - add(new StringWrapper(name), uuid); - return uuid; - } - return null; - } } diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/SQLUUIDHandler.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/SQLUUIDHandler.java index 1d76d8db3..1e63efbc5 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/SQLUUIDHandler.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/SQLUUIDHandler.java @@ -1,54 +1,57 @@ package com.plotsquared.bukkit.util.bukkit.uuid; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import com.google.common.collect.Maps; -import com.intellectualcrafters.json.JSONObject; -import com.plotsquared.bukkit.BukkitMain; -import com.intellectualcrafters.plot.database.SQLite; -import com.plotsquared.bukkit.util.UUIDHandler; -import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.io.Files; -import com.google.common.io.InputSupplier; +import com.intellectualcrafters.json.JSONObject; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.plotsquared.bukkit.object.BukkitOfflinePlayer; -import com.intellectualcrafters.plot.object.OfflinePlotPlayer; -import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.NbtFactory; -import com.intellectualcrafters.plot.util.NbtFactory.NbtCompound; -import com.intellectualcrafters.plot.util.NbtFactory.StreamOptions; import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.uuid.UUIDWrapper; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.plugin.java.JavaPlugin; - -public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { - +public class SQLUUIDHandler extends UUIDHandlerImplementation { + + public SQLUUIDHandler(UUIDWrapper wrapper) { + super(wrapper); + _sqLite = new SQLite("./plugins/PlotSquared/usercache.db"); + try { + _sqLite.openConnection(); + } catch (final Exception e) { + e.printStackTrace(); + } + + try { + PreparedStatement stmt = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS `usercache` (cache_key INTEGER PRIMARY KEY, uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL)"); + stmt.execute(); + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + startCaching(); + } + private class SQLUUIDHandlerException extends RuntimeException { SQLUUIDHandlerException(String s, Throwable c) { super("SQLUUIDHandler caused an exception: " + s, c); @@ -58,85 +61,20 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { super("SQLUUIDHandler caused an exception: " + s); } } - + private final SQLite _sqLite; - private final BiMap _uuidMap; - private UUIDWrapper _uuidWrapper; - private final Map _players = new ConcurrentHashMap<>(); - + private Connection getConnection() { synchronized (_sqLite) { return _sqLite.getConnection(); } } - - public SQLUUIDHandler() { - Bukkit.getPluginManager().registerEvents(this, JavaPlugin.getPlugin(BukkitMain.class)); - - _sqLite = new SQLite("./plugins/PlotSquared/usercache.db"); - - try { - _sqLite.openConnection(); - } catch(final Exception e) { - e.printStackTrace(); + + @Override + public boolean startCaching() { + if (!super.startCaching()) { + return false; } - - try { - PreparedStatement stmt = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS `usercache` (cache_key INTEGER PRIMARY KEY, uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL)"); - stmt.execute(); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - - _uuidMap = Maps.synchronizedBiMap(HashBiMap.create(new HashMap())); - - _startCaching(); - } - - @Override - public void handleShutdown() { - try { - getConnection().close(); - } catch (SQLException e) { - throw new SQLUUIDHandlerException("Couldn't close database connection", e); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - @SuppressWarnings("unused") - public void onPlayerJoin(final PlayerLoginEvent event) { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - if (!nameExists(new StringWrapper(event.getPlayer().getName()))) { - add(new StringWrapper(event.getPlayer().getName()), event.getPlayer().getUniqueId()); - } - } - }); - } - - @Override - public void startCaching() { - // startCaching(); - } - - @Override - public void setUUIDWrapper(UUIDWrapper wrapper) { - this._uuidWrapper = wrapper; - } - - @Override - public UUIDWrapper getUUIDWrapper() { - return _uuidWrapper; - } - - @Override - public Map getPlayers() { - return _players; - } - - public void _startCaching() { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { @@ -150,17 +88,17 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { found = true; username = new StringWrapper(resultSet.getString("username")); uuid = UUID.fromString(resultSet.getString("uuid")); - _uuidMap.put(username.value, uuid); + add(new StringWrapper(username.value), uuid); } - _uuidMap.put("*", DBFunc.everyone); + add(new StringWrapper("*"), DBFunc.everyone); statement.close(); if (!found) { PS.log(C.PREFIX.s() + "&cUsing player data files, couldn't find any cached UUIDs"); for (World world : Bukkit.getWorlds()) { - _cacheAll(world.getName()); + FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper); + fileHandler.startCaching(); } PS.log(C.PREFIX.s() + "&cWill fetch the uuids for all plots!"); - List toFetch = new ArrayList<>(); for (UUID u : UUIDHandler.getAllUUIDS()) { if (!uuidExists(u)) { @@ -168,21 +106,11 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { } } PS.log(C.PREFIX.s() + "&cFetching &6" + toFetch.size() + "&c uuids!"); - if (Settings.OFFLINE_MODE) { - if (!(_uuidWrapper instanceof OfflineUUIDWrapper)) { - PS.log(C.PREFIX.s() + "Offline mode is on, but the uuid wrapper isn't set for offline mode. Activating appropriate uuid wrapper"); - if (Settings.UUID_LOWERCASE) { - _uuidWrapper = new LowerOfflineUUIDWrapper(); - } else { - _uuidWrapper = new OfflineUUIDWrapper(); - } - } - } List fetched = new ArrayList<>(); for (UUID u : toFetch) { OfflinePlayer plr = Bukkit.getOfflinePlayer(u); if (plr != null) { - if (plr.getName() != null) { + if (plr.getName() != null) { add(new StringWrapper(plr.getName()), u); fetched.add(u); } @@ -197,7 +125,7 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { PS.log(C.PREFIX.s() + "&cWill fetch &6" + toFetch.size() + "&c from mojang!"); int i = 0; Iterator iterator = toFetch.iterator(); - while(iterator.hasNext()) { + while (iterator.hasNext()) { StringBuilder url = new StringBuilder("http://api.intellectualsites.com/uuid/?user="); List currentIteration = new ArrayList<>(); while (i++ <= 15 && iterator.hasNext()) { @@ -227,7 +155,7 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { } add(new StringWrapper(o.toString()), _u); } - } catch(final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } i = 0; @@ -239,305 +167,11 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { } } }); + return true; } - + @Override - public void add(final StringWrapper name, final UUID uuid) { - if ((uuid == null) || (name == null)) { - PS.log(C.PREFIX.s() + "&cSQL Caching Failed: name/uuid was null??"); - return; - } - if (name.value == null) { - PS.log(C.PREFIX.s() + "&cname.value == null for: " + uuid); - return; - } - if (_uuidMap.containsKey(name.value)) { - _uuidMap.remove(name.value); - } - if (_uuidMap.containsValue(uuid)) { - _uuidMap.inverse().remove(uuid); - } - _uuidMap.put(name.value, uuid); - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - try { - PreparedStatement statement = getConnection().prepareStatement("INSERT INTO usercache (`uuid`, `username`) VALUES(?, ?)"); - statement.setString(1, uuid.toString()); - statement.setString(2, name.toString()); - statement.execute(); - PS.log(C.PREFIX.s() + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'"); - } catch (SQLException e) { - e.printStackTrace(); - } - } - }); - } - - @Override - public boolean uuidExists(final UUID uuid) { - return _uuidMap.containsValue(uuid); - } - - @Override - public BiMap getUUIDMap() { - BiMap map = HashBiMap.create(); - for (Map.Entry entry : _uuidMap.entrySet()) { - map.put(new StringWrapper(entry.getKey()), entry.getValue()); - } - return map; - } - - @Override - public boolean nameExists(final StringWrapper name) { - return _uuidMap.containsKey(name.value); - } - - @Override - public void cacheWorld(String world) {} - - @SuppressWarnings("deprecation") - private void _cacheAll(final String world) { - final File container = Bukkit.getWorldContainer(); - PS.log(C.PREFIX.s() + "&6Starting player data caching for: " + world); - final HashMap toAdd = new HashMap<>(); - if (Settings.TWIN_MODE_UUID) { - Set all = getUUIDMap().values(); - PS.log("&aFast mode UUID caching enabled!"); - final File playerdataFolder = new File(container, world + File.separator + "playerdata"); - String[] dat = playerdataFolder.list(new FilenameFilter() { - @Override - public boolean accept(final File f, final String s) { - return s.endsWith(".dat"); - } - }); - boolean check = all.size() == 0; - if (dat != null) { - for (final String current : dat) { - final String s = current.replaceAll(".dat$", ""); - try { - UUID uuid = UUID.fromString(s); - if (check || all.contains(uuid)) { - File file = new File(playerdataFolder + File.separator + current); - InputSupplier is = Files.newInputStreamSupplier(file); - NbtCompound compound = NbtFactory.fromStream(is, StreamOptions.GZIP_COMPRESSION); - NbtCompound bukkit = (NbtCompound) compound.get("bukkit"); - String name = (String) bukkit.get("lastKnownName"); - long last = (long) bukkit.get("lastPlayed"); - ExpireManager.dates.put(uuid, last); - toAdd.put(new StringWrapper(name), uuid); - } - } catch (final Exception e) { - e.printStackTrace(); - PS.log(C.PREFIX.s() + "Invalid playerdata: " + current); - } - } - } - cache(toAdd); - return; - } - final HashSet worlds = new HashSet<>(); - worlds.add(world); - worlds.add("world"); - final HashSet uuids = new HashSet<>(); - final HashSet names = new HashSet<>(); - File playerdataFolder = null; - for (final String worldname : worlds) { - // Getting UUIDs - playerdataFolder = new File(container, worldname + File.separator + "playerdata"); - String[] dat = playerdataFolder.list(new FilenameFilter() { - @Override - public boolean accept(final File f, final String s) { - return s.endsWith(".dat"); - } - }); - if (dat != null && dat.length != 0) { - for (final String current : dat) { - final String s = current.replaceAll(".dat$", ""); - try { - final UUID uuid = UUID.fromString(s); - uuids.add(uuid); - } catch (final Exception e) { - PS.log(C.PREFIX.s() + "Invalid playerdata: " + current); - } - } - break; - } - // Getting names - final File playersFolder = new File(worldname + File.separator + "players"); - dat = playersFolder.list(new FilenameFilter() { - @Override - public boolean accept(final File f, final String s) { - return s.endsWith(".dat"); - } - }); - if (dat != null && dat.length != 0) { - for (final String current : dat) { - names.add(current.replaceAll(".dat$", "")); - } - break; - } - } - for (UUID uuid : uuids) { - try { - File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat"); - InputSupplier is = Files.newInputStreamSupplier(file); - NbtCompound compound = NbtFactory.fromStream(is, StreamOptions.GZIP_COMPRESSION); - NbtCompound bukkit = (NbtCompound) compound.get("bukkit"); - String name = (String) bukkit.get("lastKnownName"); - long last = (long) bukkit.get("lastPlayed"); - if (Settings.OFFLINE_MODE) { - if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) { - uuid = _uuidWrapper.getUUID(name); - } else { - long most = (long) compound.get("UUIDMost"); - long least = (long) compound.get("UUIDLeast"); - uuid = new UUID(most, least); - } - } - ExpireManager.dates.put(uuid, last); - toAdd.put(new StringWrapper(name), uuid); - } catch (final Throwable e) { - PS.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); - } - } - for (final String name : names) { - final UUID uuid = _uuidWrapper.getUUID(name); - final StringWrapper nameWrap = new StringWrapper(name); - toAdd.put(nameWrap, uuid); - } - - if (_uuidMap.size() == 0) { - for (OfflinePlotPlayer op : _uuidWrapper.getOfflinePlayers()) { - if (op.getLastPlayed() != 0) { - String name = op.getName(); - StringWrapper wrap = new StringWrapper(name); - UUID uuid = _uuidWrapper.getUUID(op); - toAdd.put(wrap, uuid); - } - } - } - cache(toAdd); - } - - @Override - public void cache(final Map toAdd) { - for (Map.Entry entry : toAdd.entrySet()) { - add(entry.getKey(), entry.getValue()); - } - } - - @Override - public String getName(final UUID uuid) { - if (uuid == null) { - return null; - } - final PlotPlayer player = getPlayer(uuid); - if (player != null) { - return player.getName(); - } - if (_uuidMap.containsValue(uuid)) { - return _uuidMap.inverse().get(uuid); - } - if (Settings.OFFLINE_MODE) { - if (!(_uuidWrapper instanceof OfflineUUIDWrapper)) { - PS.log(C.PREFIX.s() + "Offline mode is on, but the uuid wrapper isn't set for offline mode. Activating appropriate uuid wrapper"); - if (Settings.UUID_LOWERCASE) { - _uuidWrapper = new LowerOfflineUUIDWrapper(); - } else { - _uuidWrapper = new OfflineUUIDWrapper(); - } - } - } - OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid); - if (plr != null) { - add(new StringWrapper(plr.getName()), plr.getUniqueId()); - return plr.getName(); - } - if (!Settings.OFFLINE_MODE) { - PS.log(C.PREFIX.s() + "Name for '" + uuid + "' was null. We'll cache this from the mojang servers!"); - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - String url = "http://api.intellectualsites.com/uuid/?user=" + uuid; - try { - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String line; - StringBuilder rawJSON = new StringBuilder(); - while ((line = reader.readLine()) != null) { - rawJSON.append(line); - } - reader.close(); - JSONObject object = new JSONObject(rawJSON.toString()); - String username = object.getJSONObject(uuid.toString().replace("-", "")).getString("username"); - add(new StringWrapper(username), uuid); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - } - return null; - } - - @Override - public UUID getUUID(final PlotPlayer player) { - return _uuidWrapper.getUUID(player); - } - - @Override - public UUID getUUID(final BukkitOfflinePlayer player) { - return _uuidWrapper.getUUID(player); - } - - @Override - public PlotPlayer getPlayer(final UUID uuid) { - for (final PlotPlayer player : _players.values()) { - if (player.getUUID().equals(uuid)) { - return player; - } - } - return null; - } - - @Override - public PlotPlayer getPlayer(final String name) { - return _players.get(name); - } - - @Override - public UUID getUUID(final String name) { - if ((name == null) || (name.length() == 0)) { - return null; - } - // check online - final PlotPlayer player = getPlayer(name); - if (player != null) { - return player.getUUID(); - } - // check cache - UUID uuid = _uuidMap.get(name); - if (uuid != null) { - return uuid; - } - if (Settings.OFFLINE_MODE) { - if (!(_uuidWrapper instanceof OfflineUUIDWrapper)) { - PS.log(C.PREFIX.s() + "Offline mode is on, but the uuid wrapper isn't set for offline mode. Activating appropriate uuid wrapper"); - if (Settings.UUID_LOWERCASE) { - _uuidWrapper = new LowerOfflineUUIDWrapper(); - } else { - _uuidWrapper = new OfflineUUIDWrapper(); - } - } - } - // Read from disk OR convert directly to offline UUID - if (Settings.UUID_FROM_DISK || (_uuidWrapper instanceof OfflineUUIDWrapper)) { - uuid = _uuidWrapper.getUUID(name); - add(new StringWrapper(name), uuid); - return uuid; - } + public void fetchUUID(final String name, final RunnableVal ifFetch) { PS.log(C.PREFIX.s() + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!"); TaskManager.runTaskAsync(new Runnable() { @Override @@ -554,8 +188,74 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { } reader.close(); JSONObject object = new JSONObject(rawJSON.toString()); - UUID uuid = UUID.fromString(object.getJSONObject(name).getString("dashed")); - add(new StringWrapper(name), uuid); + ifFetch.value = UUID.fromString(object.getJSONObject(name).getString("dashed")); + add(new StringWrapper(name), ifFetch.value); + } catch (IOException e) { + e.printStackTrace(); + } + TaskManager.runTask(ifFetch); + } + }); + } + + @Override + public void handleShutdown() { + super.handleShutdown(); + try { + getConnection().close(); + } catch (SQLException e) { + throw new SQLUUIDHandlerException("Couldn't close database connection", e); + } + } + + @Override + public boolean add(final StringWrapper name, final UUID uuid) { + // Ignoring duplicates + if (!super.add(name, uuid)) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + try { + PreparedStatement statement = getConnection().prepareStatement("INSERT INTO usercache (`uuid`, `username`) VALUES(?, ?)"); + statement.setString(1, uuid.toString()); + statement.setString(2, name.toString()); + statement.execute(); + PS.log(C.PREFIX.s() + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + }); + return false; + } + return true; + } + + /** + * This isn't used as any UUID that is unknown is bulk cached (in lots of 16) + * @param uuid + * @return + */ + @Deprecated + public String getName__unused__(final UUID uuid) { + PS.log(C.PREFIX.s() + "Name for '" + uuid + "' was null. We'll cache this from the mojang servers!"); + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + String url = "http://api.intellectualsites.com/uuid/?user=" + uuid; + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + StringBuilder rawJSON = new StringBuilder(); + while ((line = reader.readLine()) != null) { + rawJSON.append(line); + } + reader.close(); + JSONObject object = new JSONObject(rawJSON.toString()); + String username = object.getJSONObject(uuid.toString().replace("-", "")).getString("username"); + add(new StringWrapper(username), uuid); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/UUIDHandlerImplementation.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/UUIDHandlerImplementation.java deleted file mode 100644 index 6e8118a3b..000000000 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/uuid/UUIDHandlerImplementation.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.plotsquared.bukkit.util.bukkit.uuid; - -import com.google.common.collect.BiMap; -import com.plotsquared.bukkit.object.BukkitOfflinePlayer; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.uuid.UUIDWrapper; - -import java.util.Map; -import java.util.UUID; - -public interface UUIDHandlerImplementation { - - void add(final StringWrapper name, final UUID uuid); - boolean uuidExists(final UUID uuid); - BiMap getUUIDMap(); - boolean nameExists(final StringWrapper wrapper); - void handleShutdown(); - void cacheWorld(String world); - void cache(final Map toAdd); - String getName(final UUID uuid); - UUID getUUID(final PlotPlayer player); - UUID getUUID(final BukkitOfflinePlayer player); - PlotPlayer getPlayer(final UUID uuid); - PlotPlayer getPlayer(String name); - UUID getUUID(String name); - void startCaching(); - void setUUIDWrapper(UUIDWrapper wrapper); - UUIDWrapper getUUIDWrapper(); - Map getPlayers(); - -} diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 7fe553d67..398b1a758 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -35,10 +35,10 @@ import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.bukkit.listeners.APlotListener; import com.plotsquared.bukkit.util.SetupUtils; -import com.plotsquared.bukkit.util.UUIDHandler; /** * Created by robin on 01/11/2014