mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
33 lines
1.0 KiB
Java
33 lines
1.0 KiB
Java
package de.shiewk.smoderation.util;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.UUID;
|
|
|
|
public abstract class PlayerUtil {
|
|
private PlayerUtil(){}
|
|
|
|
public static final UUID UUID_CONSOLE = new UUID(0, 0);
|
|
|
|
public static @NotNull String offlinePlayerName(UUID uuid){
|
|
if (uuid.equals(UUID_CONSOLE)){
|
|
return "UUID_CONSOLE";
|
|
}
|
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
|
return player.getName() == null ? uuid.toString() : player.getName();
|
|
}
|
|
|
|
public static @Nullable UUID offlinePlayerUUIDByName(String name){
|
|
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(name);// getOfflinePlayerIfCached(String) is safer (I have experience with getOfflinePlayer(String) returning wrong UUIDs)
|
|
if (offlinePlayer != null) {
|
|
return offlinePlayer.getUniqueId();
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|