PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java

122 lines
3.4 KiB
Java
Raw Normal View History

2015-07-27 09:26:50 +02:00
package com.intellectualcrafters.plot.util;
2014-11-05 04:42:08 +01:00
2015-07-27 19:50:04 +02:00
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
2015-07-30 16:25:16 +02:00
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PS;
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;
2015-07-03 11:30:26 +02:00
public class UUIDHandler {
2015-07-24 16:06:58 +02:00
public static UUIDHandlerImplementation implementation;
2015-02-23 02:32:27 +01:00
public static void add(final StringWrapper name, final UUID uuid) {
2015-07-24 16:06:58 +02:00
implementation.add(name, uuid);
}
2015-02-23 02:32:27 +01:00
2014-10-28 01:57:14 +01:00
/**
* Get the map containing all names/uuids
2014-11-05 04:42:08 +01:00
*
2014-10-28 01:57:14 +01:00
* @return map with names + uuids
2014-12-18 03:15:11 +01:00
*
2014-11-20 00:00:38 +01:00
* @see com.google.common.collect.BiMap
2014-10-28 01:57:14 +01:00
*/
2014-10-21 11:58:52 +02:00
public static BiMap<StringWrapper, UUID> getUuidMap() {
2015-07-24 16:06:58 +02:00
return implementation.getUUIDMap();
2014-10-12 01:18:47 +02:00
}
2015-02-23 02:32:27 +01:00
2014-10-28 01:57:14 +01:00
/**
* Check if a uuid is cached
2014-11-05 04:42:08 +01:00
*
2014-12-18 03:15:11 +01:00
* @param uuid to check
*
2014-10-28 01:57:14 +01:00
* @return true of the uuid is cached
2014-12-18 03:15:11 +01:00
*
2014-11-20 00:00:38 +01:00
* @see com.google.common.collect.BiMap#containsValue(Object)
2014-10-28 01:57:14 +01:00
*/
2014-11-05 04:42:08 +01:00
public static boolean uuidExists(final UUID uuid) {
2015-07-24 16:06:58 +02:00
return implementation.uuidExists(uuid);
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
2014-10-28 01:57:14 +01:00
/**
* Check if a name is cached
2014-11-05 04:42:08 +01:00
*
2014-12-18 03:15:11 +01:00
* @param name to check
*
2014-10-28 01:57:14 +01:00
* @return true of the name is cached
2014-12-18 03:15:11 +01:00
*
2014-11-20 00:00:38 +01:00
* @see com.google.common.collect.BiMap#containsKey(Object)
2014-10-28 01:57:14 +01:00
*/
2014-11-05 04:42:08 +01:00
public static boolean nameExists(final StringWrapper name) {
2015-07-24 16:06:58 +02:00
return implementation.nameExists(name);
2014-11-05 04:42:08 +01:00
}
2015-05-02 12:08:30 +02:00
public static HashSet<UUID> getAllUUIDS() {
2015-07-24 16:06:58 +02:00
HashSet<UUID> uuids = new HashSet<>();
for (Plot plot : PS.get().getPlotsRaw()) {
2015-05-02 12:08:30 +02:00
if (plot.owner != null) {
uuids.add(plot.owner);
2015-07-21 20:31:12 +02:00
uuids.addAll(plot.getTrusted());
uuids.addAll(plot.getMembers());
uuids.addAll(plot.getDenied());
2015-05-02 12:08:30 +02:00
}
}
return uuids;
}
2015-07-24 16:06:58 +02:00
public static UUIDWrapper getUUIDWrapper() {
return implementation.getUUIDWrapper();
2015-06-24 16:32:27 +02:00
}
2015-07-24 16:06:58 +02:00
public static void setUUIDWrapper(final UUIDWrapper wrapper) {
implementation.setUUIDWrapper(wrapper);
}
2015-07-27 15:10:14 +02:00
public static void startCaching(Runnable whenDone) {
implementation.startCaching(whenDone);
2015-07-24 16:06:58 +02:00
}
2015-07-27 09:26:50 +02:00
public static void cache(final BiMap<StringWrapper, UUID> toAdd) {
implementation.add(toAdd);
}
2015-02-23 02:32:27 +01:00
2015-02-21 13:52:50 +01:00
public static UUID getUUID(final PlotPlayer player) {
2015-07-24 16:06:58 +02:00
return implementation.getUUID(player);
}
2015-02-23 02:32:27 +01:00
2015-07-27 09:26:50 +02:00
public static UUID getUUID(final OfflinePlotPlayer player) {
2015-07-24 16:06:58 +02:00
return implementation.getUUID(player);
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public static String getName(final UUID uuid) {
2015-07-24 16:06:58 +02:00
return implementation.getName(uuid);
2014-12-13 12:59:43 +01:00
}
2015-02-23 02:32:27 +01:00
public static PlotPlayer getPlayer(final UUID uuid) {
2015-07-24 16:06:58 +02:00
return implementation.getPlayer(uuid);
2015-02-21 13:52:50 +01:00
}
2015-02-23 02:32:27 +01:00
public static PlotPlayer getPlayer(final String name) {
2015-07-24 16:06:58 +02:00
return implementation.getPlayer(name);
2015-02-21 13:52:50 +01:00
}
2015-02-23 02:32:27 +01:00
2015-07-27 09:26:50 +02:00
public static UUID getUUID(final String name, RunnableVal<UUID> ifFetch) {
return implementation.getUUID(name, ifFetch);
2015-07-24 16:06:58 +02:00
}
public static Map<String, PlotPlayer> getPlayers() {
return implementation.getPlayers();
}
public static void handleShutdown() {
implementation.handleShutdown();
2014-12-13 12:59:43 +01:00
}
2014-10-06 14:51:28 +02:00
}