mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 23:13:48 +01:00
55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
package com.gamingmesh.jobs.stuff;
|
|
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import com.gamingmesh.jobs.config.ConfigManager;
|
|
|
|
public class OfflinePlayerList {
|
|
|
|
private static ConcurrentHashMap<String, OfflinePlayer> map = new ConcurrentHashMap<String, OfflinePlayer>();
|
|
private static ConcurrentHashMap<UUID, OfflinePlayer> uuidmap = new ConcurrentHashMap<UUID, OfflinePlayer>();
|
|
|
|
public static void fillList() {
|
|
for (OfflinePlayer one : Bukkit.getOfflinePlayers()) {
|
|
if (one == null)
|
|
continue;
|
|
if (one.getName() == null)
|
|
continue;
|
|
if (one.getUniqueId() == null)
|
|
continue;
|
|
map.put(one.getName().toLowerCase(), one);
|
|
uuidmap.put(one.getUniqueId(), one);
|
|
}
|
|
return;
|
|
}
|
|
|
|
public static OfflinePlayer getPlayer(UUID uuid) {
|
|
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)
|
|
return Bukkit.getOfflinePlayer(uuid);
|
|
|
|
if (uuidmap.containsKey(uuid))
|
|
return uuidmap.get(uuid);
|
|
return null;
|
|
}
|
|
|
|
@SuppressWarnings("deprecation")
|
|
public static OfflinePlayer getPlayer(String name) {
|
|
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)
|
|
return Bukkit.getOfflinePlayer(name);
|
|
|
|
if (map.containsKey(name.toLowerCase()))
|
|
return map.get(name.toLowerCase());
|
|
return null;
|
|
}
|
|
|
|
public static void addPlayer(OfflinePlayer player) {
|
|
map.put(player.getName().toLowerCase(), player);
|
|
uuidmap.put(player.getUniqueId(), player);
|
|
}
|
|
|
|
}
|