Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulloy2 committed Oct 26, 2024
1 parent 3442d3f commit 6845acd
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 318 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.comphenix.protocol'
version = '5.3.0'
version = '5.4.0-SNAPSHOT'
description = 'Provides access to the Minecraft protocol'

def isSnapshot = version.endsWith('-SNAPSHOT')
Expand Down Expand Up @@ -34,8 +34,8 @@ repositories {

dependencies {
implementation 'net.bytebuddy:byte-buddy:1.15.1'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT'
compileOnly 'io.netty:netty-all:4.0.23.Final'
compileOnly 'net.kyori:adventure-text-serializer-gson:4.14.0'
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
Expand All @@ -46,14 +46,14 @@ dependencies {
testImplementation 'org.mockito:mockito-core:5.6.0'
testImplementation 'io.netty:netty-common:4.1.97.Final'
testImplementation 'io.netty:netty-transport:4.1.97.Final'
testImplementation 'org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT'
testImplementation 'org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT'
testImplementation 'net.kyori:adventure-text-serializer-gson:4.14.0'
testImplementation 'net.kyori:adventure-text-serializer-plain:4.14.0'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

withJavadocJar()
withSourcesJar()
Expand Down
319 changes: 163 additions & 156 deletions src/main/java/com/comphenix/protocol/PacketType.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
* @author Kristian
*/
public final class MinecraftVersion implements Comparable<MinecraftVersion>, Serializable {
/**
* Version 1.21.2 - the bundles of bravery drop
*/
public static final MinecraftVersion v1_21_2 = new MinecraftVersion("1.21.2");

/**
* Version 1.21.0 - the tricky trials update
*/
Expand Down Expand Up @@ -149,7 +154,7 @@ public final class MinecraftVersion implements Comparable<MinecraftVersion>, Ser
/**
* The latest release version of minecraft.
*/
public static final MinecraftVersion LATEST = v1_21_0;
public static final MinecraftVersion LATEST = v1_21_2;

// used when serializing
private static final long serialVersionUID = -8695133558996459770L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Protocol;
import com.comphenix.protocol.ProtocolLogger;
Expand All @@ -27,6 +23,10 @@
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;

import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;

/**
* Represents a generic enum converter.
* @author Kristian
Expand Down Expand Up @@ -140,6 +140,7 @@ public enum PlayerInfoAction {
UPDATE_LISTED,
UPDATE_LATENCY,
UPDATE_DISPLAY_NAME,
UPDATE_LIST_ORDER,
/**
* @deprecated Removed in 1.19.3
*/
Expand Down
108 changes: 71 additions & 37 deletions src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
*/
package com.comphenix.protocol.wrappers;

import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nullable;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.reflect.EquivalentConverter;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;

import javax.annotation.Nullable;
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;

/**
* Represents an immutable PlayerInfoData in the PLAYER_INFO packet.
Expand All @@ -41,6 +40,7 @@ public class PlayerInfoData {

private final UUID profileId;
private final int latency;
private final int listOrder = 0;
private final boolean listed;
private final NativeGameMode gameMode;
private final WrappedGameProfile profile;
Expand Down Expand Up @@ -202,7 +202,9 @@ public WrappedRemoteChatSessionData getRemoteChatSessionData() {
* @return A new converter.
*/
public static EquivalentConverter<PlayerInfoData> getConverter() {
return new EquivalentConverter<PlayerInfoData>() {
return new EquivalentConverter<>() {
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];

@Override
public Object getGeneric(PlayerInfoData specific) {
if (constructor == null) {
Expand All @@ -225,13 +227,17 @@ public Object getGeneric(PlayerInfoData specific) {
args.add(EnumWrappers.getGameModeClass());
args.add(MinecraftReflection.getIChatBaseComponentClass());

if (MinecraftVersion.v1_21_2.atOrAbove()) {
args.add(int.class);
}

if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
args.add(MinecraftReflection.getRemoteChatSessionDataClass());
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
args.add(MinecraftReflection.getProfilePublicKeyDataClass());
}

constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(args.toArray(new Class<?>[0]));
constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(args.toArray(EMPTY_CLASS_ARRAY));
} catch (Exception e) {
throw new RuntimeException("Cannot find PlayerInfoData constructor.", e);
}
Expand All @@ -242,30 +248,58 @@ public Object getGeneric(PlayerInfoData specific) {
try {
Object gameMode = EnumWrappers.getGameModeConverter().getGeneric(specific.gameMode);
Object displayName = specific.displayName != null ? specific.displayName.handle : null;

Object profile = specific.profile != null ? specific.profile.handle : null;
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
return constructor.newInstance(
specific.profileId,
profile,
specific.listed,
specific.latency,
gameMode,
displayName,
specific.remoteChatSessionData != null ? BukkitConverters.getWrappedRemoteChatSessionDataConverter().getGeneric(specific.remoteChatSessionData) : null
);
Object remoteChatSessionData = specific.remoteChatSessionData != null ? BukkitConverters.getWrappedRemoteChatSessionDataConverter().getGeneric(specific.remoteChatSessionData) : null;

Object[] args;

if (MinecraftVersion.v1_21_2.atOrAbove()) {
args = new Object[] {
specific.profileId,
profile,
specific.listed,
specific.latency,
gameMode,
displayName,
specific.listOrder,
remoteChatSessionData
};
} else if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
args = new Object[] {
specific.profileId,
profile,
specific.listed,
specific.latency,
gameMode,
displayName,
remoteChatSessionData
};
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
return constructor.newInstance(
profile,
specific.latency,
gameMode,
displayName,
specific.profileKeyData == null ? null : specific.profileKeyData.handle);
args = new Object[] {
profile,
specific.latency,
gameMode,
displayName,
specific.profileKeyData == null ? null : specific.profileKeyData.handle
};
} else if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) {
return constructor.newInstance(profile, specific.latency, gameMode, displayName);
args = new Object[] {
profile,
specific.latency,
gameMode,
displayName
};
} else {
return constructor.newInstance(null, profile, specific.latency, gameMode, displayName);
args = new Object[] {
null,
profile,
specific.latency,
gameMode,
displayName
};
}

return constructor.newInstance(args);
} catch (Exception e) {
throw new RuntimeException("Failed to construct PlayerInfoData.", e);
}
Expand All @@ -275,37 +309,37 @@ public Object getGeneric(PlayerInfoData specific) {
public PlayerInfoData getSpecific(Object generic) {
if (MinecraftReflection.isPlayerInfoData(generic)) {
StructureModifier<Object> modifier = new StructureModifier<>(generic.getClass(), null, false)
.withTarget(generic);
.withTarget(generic);

StructureModifier<WrappedGameProfile> gameProfiles = modifier.withType(
MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter());
MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter());
WrappedGameProfile gameProfile = gameProfiles.read(0);

StructureModifier<Integer> ints = modifier.withType(int.class);
int latency = ints.read(0);

StructureModifier<NativeGameMode> gameModes = modifier.withType(
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
NativeGameMode gameMode = gameModes.read(0);

StructureModifier<WrappedChatComponent> displayNames = modifier.withType(
MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter());
MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter());
WrappedChatComponent displayName = displayNames.read(0);

if(MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
return new PlayerInfoData(modifier.<UUID>withType(UUID.class).read(0),
latency,
modifier.<Boolean>withType(boolean.class).read(0),
gameMode,
gameProfile,
displayName,
modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0)
);
latency,
modifier.<Boolean>withType(boolean.class).read(0),
gameMode,
gameProfile,
displayName,
modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0)
);
}
WrappedProfileKeyData key = null;
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
StructureModifier<WrappedProfileKeyData> keyData = modifier.withType(
MinecraftReflection.getProfilePublicKeyDataClass(), BukkitConverters.getWrappedPublicKeyDataConverter());
MinecraftReflection.getProfilePublicKeyDataClass(), BukkitConverters.getWrappedPublicKeyDataConverter());
key = keyData.read(0);
}

Expand Down
Loading

0 comments on commit 6845acd

Please sign in to comment.