Restructure UUID handler

This commit is contained in:
boy0001 2015-07-27 17:26:50 +10:00
parent d0a5de1c0f
commit 58ebf9d232
53 changed files with 409 additions and 688 deletions

View File

@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
@ -63,7 +64,7 @@ public interface IPlotMain {
public HybridUtils initHybridUtils(); public HybridUtils initHybridUtils();
public UUIDWrapper initUUIDHandler(); public UUIDHandlerImplementation initUUIDHandler();
public InventoryUtil initInventoryUtil(); public InventoryUtil initInventoryUtil();

View File

@ -72,8 +72,8 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.SetupUtils;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@ -171,7 +171,7 @@ public class PS {
IMP.registerChunkProcessor(); IMP.registerChunkProcessor();
} }
// create UUIDWrapper // create UUIDWrapper
UUIDHandler.setUUIDWrapper(IMP.initUUIDHandler()); UUIDHandler.implementation = IMP.initUUIDHandler();
// create event util class // create event util class
EventUtil.manager = IMP.initEventUtil(); EventUtil.manager = IMP.initEventUtil();
// create Hybrid utility class // create Hybrid utility class
@ -598,7 +598,7 @@ public class PS {
* @return Set of Plot * @return Set of Plot
*/ */
public Set<Plot> getPlots(final String world, final String player) { public Set<Plot> getPlots(final String world, final String player) {
final UUID uuid = UUIDHandler.getUUID(player); final UUID uuid = UUIDHandler.getUUID(player, null);
return getPlots(world, uuid); return getPlots(world, uuid);
} }
@ -1515,8 +1515,6 @@ public class PS {
Settings.FANCY_CHAT = false; Settings.FANCY_CHAT = false;
} }
Settings.METRICS = config.getBoolean("metrics"); Settings.METRICS = config.getBoolean("metrics");
UUIDHandler.implementation = Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler() : new FileUUIDHandler();
} }

View File

@ -48,7 +48,7 @@ import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler; 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.BukkitSetBlockManager;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;

View File

@ -31,11 +31,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -34,9 +34,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "buy", command = "buy",

View File

@ -34,9 +34,9 @@ import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "clear", command = "clear",

View File

@ -47,8 +47,8 @@ import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.SetupUtils;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "cluser", command = "cluser",

View File

@ -14,9 +14,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "database", command = "database",

View File

@ -39,9 +39,9 @@ import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "debugclaimtest", command = "debugclaimtest",

View File

@ -31,9 +31,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "debugclear", command = "debugclear",

View File

@ -33,7 +33,7 @@ import java.util.UUID;
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; 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.ChunkManager;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "debugexec", command = "debugexec",

View File

@ -31,7 +31,7 @@ import java.util.UUID;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS; 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.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;

View File

@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "delete", command = "delete",

View File

@ -31,11 +31,10 @@ import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.C; 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.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "info", command = "info",

View File

@ -27,9 +27,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "kick", command = "kick",

View File

@ -27,7 +27,7 @@ import java.util.UUID;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PS; 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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "merge", command = "merge",

View File

@ -31,9 +31,9 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -30,11 +30,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -26,7 +26,7 @@ import java.util.List;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PS; 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.SetBlockQueue;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
// TODO Make sub-subcommands // TODO Make sub-subcommands

View File

@ -33,10 +33,10 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "setowner", command = "setowner",

View File

@ -23,7 +23,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PS; 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.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "tp", command = "tp",

View File

@ -31,10 +31,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -29,11 +29,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
@CommandDeclaration( @CommandDeclaration(

View File

@ -29,10 +29,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
// UNTRUST("untrust", "ut"), // UNTRUST("untrust", "ut"),

View File

@ -30,10 +30,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.Argument; import com.intellectualsites.commands.Argument;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
@CommandDeclaration( @CommandDeclaration(
command = "visit", command = "visit",

View File

@ -32,7 +32,7 @@ import java.util.UUID;
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
import com.intellectualsites.commands.CommandDeclaration; import com.intellectualsites.commands.CommandDeclaration;
import com.intellectualsites.commands.CommandCaller; import com.intellectualsites.commands.CommandCaller;
import com.plotsquared.bukkit.util.UUIDHandler;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; 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.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.chat.FancyMessage; import com.plotsquared.bukkit.util.bukkit.chat.FancyMessage;
@CommandDeclaration( @CommandDeclaration(

View File

@ -7,7 +7,7 @@ import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotHandler { public class PlotHandler {
public static HashSet<UUID> getOwners(Plot plot) { public static HashSet<UUID> getOwners(Plot plot) {

View File

@ -23,7 +23,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
public class ClusterManager { public class ClusterManager {

View File

@ -22,7 +22,6 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.plotsquared.bukkit.util.UUIDHandler;
public class ExpireManager { public class ExpireManager {
public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>();

View File

@ -45,7 +45,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
/** /**
@ -110,7 +109,7 @@ public class MainUtil {
for (String term : split) { for (String term : split) {
try { try {
UUID uuid = UUIDHandler.getUUID(term); UUID uuid = UUIDHandler.getUUID(term, null);
if (uuid == null) { if (uuid == null) {
uuid = UUID.fromString(term); uuid = UUID.fromString(term);
} }

View File

@ -47,7 +47,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.plotsquared.bukkit.object.schematic.StateWrapper; import com.plotsquared.bukkit.object.schematic.StateWrapper;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.WorldEditSchematic; import com.plotsquared.bukkit.util.WorldEditSchematic;
import com.plotsquared.bukkit.util.bukkit.BukkitSchematicHandler; import com.plotsquared.bukkit.util.bukkit.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;

View File

@ -1,16 +1,15 @@
package com.plotsquared.bukkit.util; package com.intellectualcrafters.plot.util;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import com.plotsquared.bukkit.util.bukkit.uuid.UUIDHandlerImplementation;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PS; 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.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
@ -84,15 +83,15 @@ public class UUIDHandler {
implementation.startCaching(); implementation.startCaching();
} }
public static void cache(final Map<StringWrapper, UUID> toAdd) { public static void cache(final BiMap<StringWrapper, UUID> toAdd) {
implementation.cache(toAdd); implementation.add(toAdd);
} }
public static UUID getUUID(final PlotPlayer player) { public static UUID getUUID(final PlotPlayer player) {
return implementation.getUUID(player); return implementation.getUUID(player);
} }
public static UUID getUUID(final BukkitOfflinePlayer player) { public static UUID getUUID(final OfflinePlotPlayer player) {
return implementation.getUUID(player); return implementation.getUUID(player);
} }
@ -108,18 +107,14 @@ public class UUIDHandler {
return implementation.getPlayer(name); return implementation.getPlayer(name);
} }
public static UUID getUUID(final String name) { public static UUID getUUID(final String name, RunnableVal<UUID> ifFetch) {
return implementation.getUUID(name); return implementation.getUUID(name, ifFetch);
} }
public static Map<String, PlotPlayer> getPlayers() { public static Map<String, PlotPlayer> getPlayers() {
return implementation.getPlayers(); return implementation.getPlayers();
} }
public static void cacheWorld(String world) {
implementation.cacheWorld(world);
}
public static void handleShutdown() { public static void handleShutdown() {
implementation.handleShutdown(); implementation.handleShutdown();
} }

View File

@ -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<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
public boolean CACHED = false;
public UUIDWrapper uuidWrapper = null;
public final HashMap<String, PlotPlayer> 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<UUID> 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<StringWrapper, UUID> toAdd) {
if (uuidMap.size() == 0) {
uuidMap = toAdd;
}
TaskManager.runTask(new Runnable() {
@Override
public void run() {
for (Map.Entry<StringWrapper, UUID> 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<UUID, StringWrapper> 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<StringWrapper, UUID> 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<UUID> 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<String, PlotPlayer> getPlayers() {
return players;
}
}

View File

@ -16,7 +16,7 @@ import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper { public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
private Method getOnline = null; private Method getOnline = null;

View File

@ -16,7 +16,7 @@ import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
public class OfflineUUIDWrapper extends UUIDWrapper { public class OfflineUUIDWrapper extends UUIDWrapper {
private Method getOnline = null; private Method getOnline = null;

View File

@ -27,8 +27,9 @@ import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.SetupUtils;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.*; 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.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
@ -428,23 +429,24 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
@Override @Override
public UUIDWrapper initUUIDHandler() { public UUIDHandlerImplementation initUUIDHandler() {
final boolean checkVersion = PS.get().checkVersion(this.getServerVersion(), 1, 7, 6); final boolean checkVersion = PS.get().checkVersion(this.getServerVersion(), 1, 7, 6);
UUIDWrapper wrapper;
if (Settings.OFFLINE_MODE) { if (Settings.OFFLINE_MODE) {
if (Settings.UUID_LOWERCASE) { if (Settings.UUID_LOWERCASE) {
UUIDHandler.setUUIDWrapper(new LowerOfflineUUIDWrapper()); wrapper = (new LowerOfflineUUIDWrapper());
} else { } else {
UUIDHandler.setUUIDWrapper(new OfflineUUIDWrapper()); wrapper = (new OfflineUUIDWrapper());
} }
Settings.OFFLINE_MODE = true; Settings.OFFLINE_MODE = true;
} else if (checkVersion) { } else if (checkVersion) {
UUIDHandler.setUUIDWrapper(new DefaultUUIDWrapper()); wrapper = (new DefaultUUIDWrapper());
Settings.OFFLINE_MODE = false; Settings.OFFLINE_MODE = false;
} else { } else {
if (Settings.UUID_LOWERCASE) { if (Settings.UUID_LOWERCASE) {
UUIDHandler.setUUIDWrapper(new LowerOfflineUUIDWrapper()); wrapper = (new LowerOfflineUUIDWrapper());
} else { } else {
UUIDHandler.setUUIDWrapper(new OfflineUUIDWrapper()); wrapper = (new OfflineUUIDWrapper());
} }
Settings.OFFLINE_MODE = true; Settings.OFFLINE_MODE = true;
} }
@ -465,7 +467,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} else { } else {
log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs"); log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs");
} }
return UUIDHandler.getUUIDWrapper(); return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper);
} }
@Override @Override

View File

@ -20,7 +20,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
public class ClassicPlotMeConnector extends APlotMeConnector { public class ClassicPlotMeConnector extends APlotMeConnector {

View File

@ -20,7 +20,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotMeConnector_017 extends APlotMeConnector { public class PlotMeConnector_017 extends APlotMeConnector {
private String plugin; private String plugin;

View File

@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; 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.BukkitPlayerFunctions;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;

View File

@ -113,7 +113,7 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.RegExUtil; import com.intellectualcrafters.plot.util.RegExUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; 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; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
/** /**

View File

@ -49,7 +49,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
/** /**
* @author Citymonstret * @author Citymonstret

View File

@ -53,7 +53,7 @@ import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; 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; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
/** /**

View File

@ -9,9 +9,9 @@ import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.util.UUIDHandler;
public class WorldEvents implements Listener { public class WorldEvents implements Listener {
@ -47,6 +47,6 @@ public class WorldEvents implements Listener {
@EventHandler @EventHandler
public void worldLoad(final WorldLoadEvent event) { public void worldLoad(final WorldLoadEvent event) {
UUIDHandler.cacheWorld(event.getWorld().getName()); UUIDHandler.startCaching();
} }
} }

View File

@ -9,7 +9,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; 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.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;

View File

@ -14,7 +14,7 @@ import org.bukkit.permissions.PermissionDefault;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.util.EconHandler; 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; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
public class BukkitPlayer implements PlotPlayer { public class BukkitPlayer implements PlotPlayer {

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -16,7 +17,6 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil; import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
/** /**

View File

@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
/** /**
* Functions involving players, plots and locations. * Functions involving players, plots and locations.

View File

@ -26,7 +26,6 @@ import org.bukkit.material.WoodenStep;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock; 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.ChunkManager;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class BukkitUtil extends BlockManager { public class BukkitUtil extends BlockManager {
private static HashMap<String, World> worlds = new HashMap<>(); private static HashMap<String, World> worlds = new HashMap<>();

View File

@ -1,6 +1,16 @@
package com.plotsquared.bukkit.util.bukkit.uuid; 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.collect.HashBiMap;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.InputSupplier; 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.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; 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.ExpireManager;
import com.intellectualcrafters.plot.util.NbtFactory; import com.intellectualcrafters.plot.util.NbtFactory;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.bukkit.Bukkit; public class FileUUIDHandler extends UUIDHandlerImplementation {
import java.io.File; public FileUUIDHandler(UUIDWrapper wrapper) {
import java.io.FileInputStream; super(wrapper);
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<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
public boolean CACHED = false;
public UUIDWrapper uuidWrapper = null;
public HashMap<String, PlotPlayer> players = new HashMap<>();
@Override
public void add(final StringWrapper name, final UUID uuid) {
if ((uuid == null) || (name == null)) {
return;
}
BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
if (inverse.containsKey(uuid)) {
if (uuidMap.containsKey(name)) {
return;
}
inverse.remove(uuid);
}
uuidMap.put(name, uuid);
} }
@Override @Override
public void handleShutdown() {} public boolean startCaching() {
if (!super.startCaching()) {
@Override return false;
public BiMap<StringWrapper, UUID> 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<String, PlotPlayer> getPlayers() {
return players;
}
@Override
public void cacheWorld(final String world) {
if (CACHED) {
return;
} }
final File container = Bukkit.getWorldContainer(); final File container = Bukkit.getWorldContainer();
List<World> worlds = Bukkit.getWorlds();
final String world;
if (worlds.size() == 0) {
world = "world";
}
else {
world = worlds.get(0).getName();
}
CACHED = true; CACHED = true;
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
PS.log(C.PREFIX.s() + "&6Starting player data caching for: " + world); PS.log(C.PREFIX.s() + "&6Starting player data caching for: " + world);
final HashMap<StringWrapper, UUID> toAdd = new HashMap<>(); final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
toAdd.put(new StringWrapper("*"), DBFunc.everyone); toAdd.put(new StringWrapper("*"), DBFunc.everyone);
if (Settings.TWIN_MODE_UUID) { if (Settings.TWIN_MODE_UUID) {
HashSet<UUID> all = UUIDHandler.getAllUUIDS(); HashSet<UUID> all = UUIDHandler.getAllUUIDS();
@ -134,7 +87,7 @@ public class FileUUIDHandler implements UUIDHandlerImplementation {
} }
} }
} }
cache(toAdd); add(toAdd);
return; return;
} }
final HashSet<String> worlds = new HashSet<>(); final HashSet<String> worlds = new HashSet<>();
@ -208,7 +161,7 @@ public class FileUUIDHandler implements UUIDHandlerImplementation {
toAdd.put(nameWrap, uuid); toAdd.put(nameWrap, uuid);
} }
if (uuidMap.size() == 0) { if (getUUIDMap().size() == 0) {
for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) { if (op.getLastPlayed() != 0) {
String name = op.getName(); String name = op.getName();
@ -218,89 +171,20 @@ public class FileUUIDHandler implements UUIDHandlerImplementation {
} }
} }
} }
cache(toAdd); add(toAdd);
} }
}); });
return true;
} }
@Override @Override
public void cache(final Map<StringWrapper, UUID> toAdd) { public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
TaskManager.runTask(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) { ifFetch.value = uuidWrapper.getUUID(name);
add(entry.getKey(), entry.getValue()); TaskManager.runTask(ifFetch);
}
PS.log(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs");
} }
}); });
} }
@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;
}
} }

View File

@ -1,54 +1,57 @@
package com.plotsquared.bukkit.util.bukkit.uuid; 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.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Maps; import java.util.UUID;
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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import com.google.common.collect.BiMap; import com.intellectualcrafters.json.JSONObject;
import com.google.common.collect.HashBiMap;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.plotsquared.bukkit.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper; 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.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 com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.bukkit.OfflinePlayer; public class SQLUUIDHandler extends UUIDHandlerImplementation {
import org.bukkit.World;
import org.bukkit.event.EventHandler; public SQLUUIDHandler(UUIDWrapper wrapper) {
import org.bukkit.event.EventPriority; super(wrapper);
import org.bukkit.event.Listener; _sqLite = new SQLite("./plugins/PlotSquared/usercache.db");
import org.bukkit.event.player.PlayerLoginEvent; try {
import org.bukkit.plugin.java.JavaPlugin; _sqLite.openConnection();
} catch (final Exception e) {
public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation { 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 { private class SQLUUIDHandlerException extends RuntimeException {
SQLUUIDHandlerException(String s, Throwable c) { SQLUUIDHandlerException(String s, Throwable c) {
super("SQLUUIDHandler caused an exception: " + s, c); super("SQLUUIDHandler caused an exception: " + s, c);
@ -58,85 +61,20 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
super("SQLUUIDHandler caused an exception: " + s); super("SQLUUIDHandler caused an exception: " + s);
} }
} }
private final SQLite _sqLite; private final SQLite _sqLite;
private final BiMap<String, UUID> _uuidMap;
private UUIDWrapper _uuidWrapper;
private final Map<String, PlotPlayer> _players = new ConcurrentHashMap<>();
private Connection getConnection() { private Connection getConnection() {
synchronized (_sqLite) { synchronized (_sqLite) {
return _sqLite.getConnection(); return _sqLite.getConnection();
} }
} }
public SQLUUIDHandler() { @Override
Bukkit.getPluginManager().registerEvents(this, JavaPlugin.getPlugin(BukkitMain.class)); public boolean startCaching() {
if (!super.startCaching()) {
_sqLite = new SQLite("./plugins/PlotSquared/usercache.db"); return false;
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();
}
_uuidMap = Maps.synchronizedBiMap(HashBiMap.create(new HashMap<String, UUID>()));
_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<String, PlotPlayer> getPlayers() {
return _players;
}
public void _startCaching() {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -150,17 +88,17 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
found = true; found = true;
username = new StringWrapper(resultSet.getString("username")); username = new StringWrapper(resultSet.getString("username"));
uuid = UUID.fromString(resultSet.getString("uuid")); 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(); statement.close();
if (!found) { if (!found) {
PS.log(C.PREFIX.s() + "&cUsing player data files, couldn't find any cached UUIDs"); PS.log(C.PREFIX.s() + "&cUsing player data files, couldn't find any cached UUIDs");
for (World world : Bukkit.getWorlds()) { 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!"); PS.log(C.PREFIX.s() + "&cWill fetch the uuids for all plots!");
List<UUID> toFetch = new ArrayList<>(); List<UUID> toFetch = new ArrayList<>();
for (UUID u : UUIDHandler.getAllUUIDS()) { for (UUID u : UUIDHandler.getAllUUIDS()) {
if (!uuidExists(u)) { if (!uuidExists(u)) {
@ -168,21 +106,11 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
} }
} }
PS.log(C.PREFIX.s() + "&cFetching &6" + toFetch.size() + "&c uuids!"); 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<UUID> fetched = new ArrayList<>(); List<UUID> fetched = new ArrayList<>();
for (UUID u : toFetch) { for (UUID u : toFetch) {
OfflinePlayer plr = Bukkit.getOfflinePlayer(u); OfflinePlayer plr = Bukkit.getOfflinePlayer(u);
if (plr != null) { if (plr != null) {
if (plr.getName() != null) { if (plr.getName() != null) {
add(new StringWrapper(plr.getName()), u); add(new StringWrapper(plr.getName()), u);
fetched.add(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!"); PS.log(C.PREFIX.s() + "&cWill fetch &6" + toFetch.size() + "&c from mojang!");
int i = 0; int i = 0;
Iterator<UUID> iterator = toFetch.iterator(); Iterator<UUID> iterator = toFetch.iterator();
while(iterator.hasNext()) { while (iterator.hasNext()) {
StringBuilder url = new StringBuilder("http://api.intellectualsites.com/uuid/?user="); StringBuilder url = new StringBuilder("http://api.intellectualsites.com/uuid/?user=");
List<UUID> currentIteration = new ArrayList<>(); List<UUID> currentIteration = new ArrayList<>();
while (i++ <= 15 && iterator.hasNext()) { while (i++ <= 15 && iterator.hasNext()) {
@ -227,7 +155,7 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
} }
add(new StringWrapper(o.toString()), _u); add(new StringWrapper(o.toString()), _u);
} }
} catch(final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
i = 0; i = 0;
@ -239,305 +167,11 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
} }
} }
}); });
return true;
} }
@Override @Override
public void add(final StringWrapper name, final UUID uuid) { public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
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<StringWrapper, UUID> getUUIDMap() {
BiMap<StringWrapper, UUID> map = HashBiMap.create();
for (Map.Entry<String, UUID> 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<StringWrapper, UUID> toAdd = new HashMap<>();
if (Settings.TWIN_MODE_UUID) {
Set<UUID> 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<FileInputStream> 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<String> worlds = new HashSet<>();
worlds.add(world);
worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> 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<FileInputStream> 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<StringWrapper, UUID> toAdd) {
for (Map.Entry<StringWrapper, UUID> 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;
}
PS.log(C.PREFIX.s() + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!"); PS.log(C.PREFIX.s() + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!");
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
@ -554,8 +188,74 @@ public class SQLUUIDHandler implements Listener, UUIDHandlerImplementation {
} }
reader.close(); reader.close();
JSONObject object = new JSONObject(rawJSON.toString()); JSONObject object = new JSONObject(rawJSON.toString());
UUID uuid = UUID.fromString(object.getJSONObject(name).getString("dashed")); ifFetch.value = UUID.fromString(object.getJSONObject(name).getString("dashed"));
add(new StringWrapper(name), uuid); 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -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<StringWrapper, UUID> getUUIDMap();
boolean nameExists(final StringWrapper wrapper);
void handleShutdown();
void cacheWorld(String world);
void cache(final Map<StringWrapper, UUID> 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<String, PlotPlayer> getPlayers();
}

View File

@ -35,10 +35,10 @@ import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.listeners.APlotListener; import com.plotsquared.bukkit.listeners.APlotListener;
import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.SetupUtils;
import com.plotsquared.bukkit.util.UUIDHandler;
/** /**
* Created by robin on 01/11/2014 * Created by robin on 01/11/2014