mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Merge pull request #29 from ShadowRanger/master
Fix & improve UUID retrieval
This commit is contained in:
commit
4f40459b96
1 changed files with 21 additions and 20 deletions
|
@ -34,35 +34,36 @@ public class UUIDUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
private static UUID getUUIDLocally(String name) {
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
|
||||||
|
return offlinePlayer.hasPlayedBefore() ? offlinePlayer.getUniqueId() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public static UUID getUUIDOf(String name) {
|
public static UUID getUUIDOf(String name) {
|
||||||
UUID uuid = null;
|
UUID uuid;
|
||||||
Player player = getPlayer(name);
|
Player player = getPlayer(name);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
// Player was found online
|
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Player was not found online. Fetch their UUID instead
|
if (Bukkit.getServer().getOnlineMode()) {
|
||||||
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
|
if (!Bukkit.getServer().isPrimaryThread()) {
|
||||||
Map<String, UUID> response;
|
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
|
||||||
|
Map<String, UUID> response;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = fetcher.call();
|
response = fetcher.call();
|
||||||
uuid = response.get(name.toLowerCase());
|
uuid = response.get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
/*
|
uuid = getUUIDLocally(name);
|
||||||
Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
|
}
|
||||||
e.printStackTrace();
|
} else {
|
||||||
*/
|
uuid = getUUIDLocally(name);
|
||||||
|
|
||||||
// Failed to retrieve with UUIDFetcher, server might be offline?
|
|
||||||
// Fallback on searching for the player via their name
|
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
|
|
||||||
if (offlinePlayer != null) {
|
|
||||||
uuid = offlinePlayer.getUniqueId();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
uuid = getUUIDLocally(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue