New Speed check and lots of new stuff implemented

This commit is contained in:
Dawson
2022-08-09 17:03:15 -04:00
parent 281f716f20
commit d9b35af788
55 changed files with 2950 additions and 90 deletions
@@ -0,0 +1,47 @@
package dev.brighten.ac.data;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Optional;
import java.util.UUID;
public class PlayerRegistry {
public PlayerRegistry() {
Bukkit.getOnlinePlayers().forEach(this::generate);
}
public final Int2ObjectMap<APlayer> aplayerMap = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
public Optional<APlayer> getPlayer(UUID uuid) {
return Optional.of(aplayerMap.get(uuid.hashCode()));
}
public APlayer generate(Player player) {
if(aplayerMap.containsKey(player.getUniqueId().hashCode())) {
unregister(player.getUniqueId());
}
synchronized (aplayerMap) {
APlayer aplayer = new APlayer(player);
aplayerMap.put(player.getUniqueId().hashCode(), aplayer);
return aplayer;
}
}
public void unregister(UUID uuid) {
synchronized (aplayerMap) {
Optional.of(aplayerMap.remove(uuid.hashCode())).ifPresent(APlayer::unload);
}
}
public void unregisterAll() {
synchronized (aplayerMap) {
aplayerMap.forEach((key, val) -> val.unload());
aplayerMap.clear();
}
}
}