mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-06-05 07:42:17 +00:00
234744e98d
- 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)
48 lines
1.4 KiB
Java
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();
|
|
}
|
|
}
|
|
}
|