ClientVersion#getLatest added;
ClientVersion#getOldest added; PlayerManager#getClientVersion(ChannelAbstract) bukkit impl improved
This commit is contained in:
1 parent
1d014a5848
commit
8eb8a7ea2d
5 files changed
+31
-11
No files matched your search
+2
-3
@@ -31,7 +31,6 @@ public class EntityTypes {
|
||||
private static final Map<String, EntityType> ENTITY_TYPE_MAP = new HashMap<>();
|
||||
private static final Map<Integer, EntityType> ENTITY_TYPE_ID_MAP = new HashMap<>();
|
||||
private static JsonObject MODERN_ENTITY_TYPES_JSON;
|
||||
private static JsonObject LEGACY_ENTITY_TYPES_JSON;
|
||||
|
||||
public static EntityType define(String key) {
|
||||
if (MODERN_ENTITY_TYPES_JSON == null) {
|
||||
@@ -57,7 +56,7 @@ public class EntityTypes {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EntityType) {
|
||||
return getId() == ((EntityType)obj).getId();
|
||||
return getId() == ((EntityType) obj).getId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +72,7 @@ public class EntityTypes {
|
||||
return id;
|
||||
}
|
||||
//TODO Hard coded conversions
|
||||
return MappingHelper.transformID(LEGACY_ENTITY_TYPES_JSON, id, targetProtocolVersion);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static EntityType getByKey(String key) {
|
||||
|
||||
@@ -168,6 +168,14 @@ public enum ClientVersion {
|
||||
}
|
||||
}
|
||||
|
||||
public static ClientVersion getLatest() {
|
||||
return REVERSED_VALUES[6];
|
||||
}
|
||||
|
||||
public static ClientVersion getOldest() {
|
||||
return values()[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Protocol version of this client version.
|
||||
*
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.github.retrooper.packetevents.protocol.potion;
|
||||
import com.github.retrooper.packetevents.protocol.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.MappingHelper;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -61,10 +62,12 @@ public class PotionTypes {
|
||||
return potionType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PotionType getByKey(String key) {
|
||||
return POTION_TYPE_MAP.get(key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PotionType getById(int id) {
|
||||
return POTION_TYPE_ID_MAP.get(id);
|
||||
}
|
||||
|
||||
+17
-7
@@ -49,8 +49,7 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
Map<Class<? extends PlayerAttributeObject>, PlayerAttributeObject> attributes = PLAYER_ATTRIBUTES.get(uuid);
|
||||
if (attributes != null) {
|
||||
return (T) attributes.get(clazz);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
attributes = new HashMap<>();
|
||||
attributes.put(defaultReturnValue.getClass(), defaultReturnValue);
|
||||
PLAYER_ATTRIBUTES.put(uuid, attributes);
|
||||
@@ -63,8 +62,7 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
Map<Class<? extends PlayerAttributeObject>, PlayerAttributeObject> attributes = PLAYER_ATTRIBUTES.get(uuid);
|
||||
if (attributes != null) {
|
||||
return (T) attributes.get(clazz);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PLAYER_ATTRIBUTES.put(uuid, new HashMap<>());
|
||||
return null;
|
||||
}
|
||||
@@ -105,7 +103,7 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
if (MinecraftReflectionUtil.V_1_17_OR_HIGHER) {
|
||||
return PlayerPingAccessorModern.getPing((Player) player);
|
||||
} else {
|
||||
return MinecraftReflectionUtil.getPlayerPing((Player) player);
|
||||
return MinecraftReflectionUtil.getPlayerPingLegacy((Player) player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +148,19 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
|
||||
@Override
|
||||
public ClientVersion getClientVersion(ChannelAbstract channel) {
|
||||
return CLIENT_VERSIONS.get(channel);
|
||||
ClientVersion version = CLIENT_VERSIONS.get(channel);
|
||||
if (version == null || !version.isResolved()) {
|
||||
if (!DependencyUtil.isProtocolTranslationDependencyAvailable()) {
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion() == ServerVersion.V_1_7_10) {
|
||||
return version;
|
||||
} else {
|
||||
int protocolVersion = PacketEvents.getAPI().getServerManager().getVersion().getProtocolVersion();
|
||||
version = ClientVersion.getClientVersionByProtocolVersion(protocolVersion);
|
||||
CLIENT_VERSIONS.put(channel, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +214,7 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
|
||||
@Override
|
||||
public boolean isGeyserPlayer(@NotNull Object player) {
|
||||
return isGeyserPlayer(((Player)player).getUniqueId());
|
||||
return isGeyserPlayer(((Player) player).getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -330,7 +330,7 @@ public final class MinecraftReflectionUtil {
|
||||
|
||||
//TODO Inspect again
|
||||
@Deprecated
|
||||
public static int getPlayerPing(Player player) {
|
||||
public static int getPlayerPingLegacy(Player player) {
|
||||
if (ENTITY_PLAYER_PING_FIELD != null) {
|
||||
Object entityPlayer = getEntityPlayer(player);
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user