Reformat.

This commit is contained in:
drtshock 2014-12-17 20:15:11 -06:00
parent 59be72aefe
commit 73e92b8341
167 changed files with 3705 additions and 5553 deletions

View file

@ -21,70 +21,57 @@
package com.intellectualcrafters.plot.util;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.NameFetcher;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDFetcher;
import com.intellectualcrafters.plot.uuid.UUIDSaver;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.intellectualcrafters.plot.uuid.*;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
/**
* This class can be used to efficiently translate UUIDs and names back and
* forth.
* It uses three primary methods of achieving this:
* - Read From Cache
* - Read from OfflinePlayer objects
* - Read from (if onlinemode: mojang api) (else: playername hashing)
* All UUIDs/Usernames will be stored in a map (cache) until the server is
* restarted.
* This class can be used to efficiently translate UUIDs and names back and forth. It uses three primary methods of
* achieving this: - Read From Cache - Read from OfflinePlayer objects - Read from (if onlinemode: mojang api) (else:
* playername hashing) All UUIDs/Usernames will be stored in a map (cache) until the server is restarted.
* <p/>
* You can use getUuidMap() to save the uuids/names to a file (SQLite db for
* example). Primary methods: getUUID(String name) & getName(UUID uuid) <-- You
* should ONLY use these. Call startFetch(JavaPlugin plugin) in your onEnable().
* You can use getUuidMap() to save the uuids/names to a file (SQLite db for example). Primary methods: getUUID(String
* name) & getName(UUID uuid) <-- You should ONLY use these. Call startFetch(JavaPlugin plugin) in your onEnable().
* <p/>
* Originally created by:
*
* @author Citymonstret
* @author Empire92
* for PlotSquared.
* @author Empire92 for PlotSquared.
*/
@SuppressWarnings("unused")
public class UUIDHandler {
@SuppressWarnings("unused") public class UUIDHandler {
public static UUIDWrapper uuidWrapper = null;
public static UUIDWrapper uuidWrapper = null;
/**
* Online mode
*
* @see org.bukkit.Server#getOnlineMode()
*/
private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
/**
* Map containing names and UUIDs
*
* @see com.google.common.collect.BiMap
*/
private final static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
private final static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
/**
* Get the map containing all names/uuids
*
* @return map with names + uuids
*
* @see com.google.common.collect.BiMap
*/
public static BiMap<StringWrapper, UUID> getUuidMap() {
@ -94,9 +81,10 @@ public class UUIDHandler {
/**
* Check if a uuid is cached
*
* @param uuid
* to check
* @param uuid to check
*
* @return true of the uuid is cached
*
* @see com.google.common.collect.BiMap#containsValue(Object)
*/
public static boolean uuidExists(final UUID uuid) {
@ -106,9 +94,10 @@ public class UUIDHandler {
/**
* Check if a name is cached
*
* @param name
* to check
* @param name to check
*
* @return true of the name is cached
*
* @see com.google.common.collect.BiMap#containsKey(Object)
*/
public static boolean nameExists(final StringWrapper name) {
@ -118,10 +107,8 @@ public class UUIDHandler {
/**
* Add a set to the cache
*
* @param name
* to cache
* @param uuid
* to cache
* @param name to cache
* @param uuid to cache
*/
public static void add(final StringWrapper name, final UUID uuid) {
if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) {
@ -130,8 +117,8 @@ public class UUIDHandler {
}
/**
* @param name
* to use as key
* @param name to use as key
*
* @return uuid
*/
public static UUID getUUID(final String name) {
@ -139,8 +126,7 @@ public class UUIDHandler {
if (uuidMap.containsKey(nameWrap)) {
return uuidMap.get(nameWrap);
}
@SuppressWarnings("deprecation")
final Player player = Bukkit.getPlayer(name);
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(name);
if (player != null) {
final UUID uuid = getUUID(player);
add(nameWrap, uuid);
@ -154,38 +140,33 @@ public class UUIDHandler {
}
try {
return PlotMain.getUUIDSaver().mojangUUID(name);
}
catch (final Exception e) {
} catch (final Exception e) {
try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(nameWrap, uuid);
}
catch (final Exception ex) {
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}
else {
} else {
try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(nameWrap, uuid);
}
catch (final Exception ex) {
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}
else {
} else {
return getUuidOfflineMode(nameWrap);
}
return null;
}
/**
* @param uuid
* to use as key
* @param uuid to use as key
*
* @return name (cache)
*/
private static StringWrapper loopSearch(final UUID uuid) {
@ -193,8 +174,8 @@ public class UUIDHandler {
}
/**
* @param uuid
* to use as key
* @param uuid to use as key
*
* @return Name
*/
public static String getName(final UUID uuid) {
@ -215,51 +196,44 @@ public class UUIDHandler {
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
}
catch (final Exception ex) {
} catch (final Exception ex) {
ex.printStackTrace();
}
}
else {
} else {
try {
return PlotMain.getUUIDSaver().mojangName(uuid);
}
catch (final Exception e) {
} catch (final Exception e) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
}
catch (final Exception ex) {
} catch (final Exception ex) {
e.printStackTrace();
}
}
}
try {
return PlotMain.getUUIDSaver().mojangName(uuid);
}
catch (final Exception e) {
} catch (final Exception e) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
}
catch (final Exception ex) {
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}
else {
} else {
return "unknown";
}
return "";
}
/**
* @param name
* to use as key
* @param name to use as key
*
* @return UUID (name hash)
*/
private static UUID getUuidOfflineMode(final StringWrapper name) {
@ -269,8 +243,8 @@ public class UUIDHandler {
}
/**
* @param uuid
* to use as key
* @param uuid to use as key
*
* @return String - name
*/
private static String getNameOnlinePlayer(final UUID uuid) {
@ -284,8 +258,8 @@ public class UUIDHandler {
}
/**
* @param uuid
* to use as key
* @param uuid to use as key
*
* @return String - name
*/
private static String getNameOfflinePlayer(final UUID uuid) {
@ -299,13 +273,12 @@ public class UUIDHandler {
}
/**
* @param name
* to use as key
* @param name to use as key
*
* @return UUID
*/
private static UUID getUuidOnlinePlayer(final StringWrapper name) {
@SuppressWarnings("deprecation")
final Player player = Bukkit.getPlayer(name.value);
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(name.value);
if (player == null) {
return null;
}
@ -330,8 +303,7 @@ public class UUIDHandler {
try {
getUUID(player);
uuidWrapper = new DefaultUUIDWrapper();
}
catch (final Throwable e) {
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
}
}
@ -339,29 +311,25 @@ public class UUIDHandler {
}
/**
* Safely provide the correct UUID provider. Ignores user preference if not
* possible rather than break the plugin.
* Safely provide the correct UUID provider. Ignores user preference if not possible rather than break the plugin.
*/
public static UUID getUUID(final OfflinePlayer player) {
if (uuidWrapper == null) {
if (Settings.OFFLINE_MODE) {
uuidWrapper = new OfflineUUIDWrapper();
}
else {
} else {
try {
getUUID(player);
uuidWrapper = new DefaultUUIDWrapper();
}
catch (final Throwable e) {
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
}
}
}
try {
return uuidWrapper.getUUID(player);
}
catch (final Throwable e) {
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
return uuidWrapper.getUUID(player);
}