35 lines
909 B
Java
35 lines
909 B
Java
package net.viper.status.stats;
|
|
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
public class StatsManager {
|
|
private final ConcurrentHashMap<UUID, PlayerStats> map = new ConcurrentHashMap<>();
|
|
|
|
public PlayerStats get(UUID uuid, String name) {
|
|
return map.compute(uuid, (k, v) -> {
|
|
if (v == null) {
|
|
return new PlayerStats(uuid, name != null ? name : "");
|
|
} else {
|
|
if (name != null && !name.isEmpty()) v.name = name;
|
|
return v;
|
|
}
|
|
});
|
|
}
|
|
|
|
public PlayerStats getIfPresent(UUID uuid) {
|
|
return map.get(uuid);
|
|
}
|
|
|
|
public Iterable<PlayerStats> all() {
|
|
return map.values();
|
|
}
|
|
|
|
public void put(PlayerStats ps) {
|
|
map.put(ps.uuid, ps);
|
|
}
|
|
|
|
public void remove(UUID uuid) {
|
|
map.remove(uuid);
|
|
}
|
|
} |