Files
KauriV3-mirror/src/main/java/dev/brighten/ac/data/PlayerRegistry.java
T
Dawson 234744e98d Updating commands and Packet API
- Added wrapper for PacketHandshakeInSetProtocol
- Took ProtocolAPI from Atlas to implement ViaVersion and ProtocolSupport version checking hooks.
- Added hook into "Login" style packets.
- Wth this new hook, we get player version numbers and store them by Channel now.
- Packets are now initialized in the same join listener as where APlayer is generated in JoinListener class.
- Removed Listener extension from HandlerAbstract, ModernHandler, LegacvHandler

NOTE: Protocol version grabbing needs implemented for LegacyHandler (1.7.10 version)
2022-08-11 12:27:16 -04:00

48 lines
1.4 KiB
Java

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.ofNullable(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.ofNullable(aplayerMap.remove(uuid.hashCode())).ifPresent(APlayer::unload);
}
}
public void unregisterAll() {
synchronized (aplayerMap) {
aplayerMap.forEach((key, val) -> val.unload());
aplayerMap.clear();
}
}
}