Compare commits

..

1 Commits

Author SHA1 Message Date
Maurice Eisenblätter 45ccda0aaa
Merge f822c8523c into e1255edb32 2024-04-23 22:17:33 +00:00
5 changed files with 494 additions and 522 deletions

View File

@ -33,8 +33,7 @@ final class ChannelProtocolUtil {
BiFunction<Channel, PacketType.Sender, Object> baseResolver = null;
if (attributeKeys.isEmpty()) {
// since 1.20.5 the protocol is stored as final field in de-/encoder
baseResolver = new Post1_20_5WrappedResolver();
baseResolver = new Post1_20_4WrappedResolver();
} else if (attributeKeys.size() == 1) {
// if there is only one attribute key we can assume it's the correct one (1.8 - 1.20.1)
Object protocolKey = Accessors.getFieldAccessor(attributeKeys.get(0)).get(null);
@ -138,10 +137,7 @@ final class ChannelProtocolUtil {
}
}
/**
* Since 1.20.5 the protocol is stored as final field in de-/encoder
*/
private static final class Post1_20_5WrappedResolver implements BiFunction<Channel, PacketType.Sender, Object> {
private static final class Post1_20_4WrappedResolver implements BiFunction<Channel, PacketType.Sender, Object> {
// lazy initialized when needed
private Function<Object, Object> serverProtocolAccessor;
@ -155,11 +151,23 @@ final class ChannelProtocolUtil {
return null;
}
Function<Object, Object> protocolAccessor = this.getProtocolAccessor(codecHandler.getClass(), sender);
Function<Object, Object> protocolAccessor = this.getProtocolAccessor(sender, codecHandler.getClass());
return protocolAccessor.apply(codecHandler);
}
private Function<Object, Object> getProtocolAccessor(Class<?> codecHandler, PacketType.Sender sender) {
private String getKeyForSender(PacketType.Sender sender) {
switch (sender) {
case SERVER:
return "encoder";
case CLIENT:
return "decoder";
default:
throw new IllegalArgumentException("Illegal packet sender " + sender.name());
}
}
private Function<Object, Object> getProtocolAccessor(PacketType.Sender sender, Class<?> codecHandler) {
switch (sender) {
case SERVER:
if (this.serverProtocolAccessor == null) {
@ -176,27 +184,17 @@ final class ChannelProtocolUtil {
}
}
private String getKeyForSender(PacketType.Sender sender) {
switch (sender) {
case SERVER:
return "encoder";
case CLIENT:
return "decoder";
default:
throw new IllegalArgumentException("Illegal packet sender " + sender.name());
}
}
private Function<Object, Object> getProtocolAccessor(Class<?> codecHandler) {
Class<?> protocolInfoClass = MinecraftReflection.getProtocolInfoClass();
Class<?> protocolInfoClass = MinecraftReflection.getMinecraftClass("network.ProtocolInfo");
MethodAccessor protocolAccessor = Accessors.getMethodAccessor(FuzzyReflection
.fromClass(protocolInfoClass)
.getMethodByReturnTypeAndParameters("id", MinecraftReflection.getEnumProtocolClass(), new Class[0]));
MethodAccessor protocolAccessor = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(protocolInfoClass)
.getMethod(FuzzyMethodContract.newBuilder()
.returnTypeExact(MinecraftReflection.getEnumProtocolClass())
.build()));
FieldAccessor protocolInfoAccessor = Accessors.getFieldAccessor(codecHandler, protocolInfoClass, true);
// get ProtocolInfo from handler and get EnumProtocol of ProtocolInfo
return (handler) -> {
Object protocolInfo = protocolInfoAccessor.get(handler);
return protocolAccessor.invoke(protocolInfo);

View File

@ -31,7 +31,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoop;
import io.netty.util.AttributeKey;
import org.bukkit.Server;
@ -203,18 +202,9 @@ public class NettyChannelInjector implements Injector {
return false;
}
ChannelPipeline pipeline = this.wrappedChannel.pipeline();
// since 1.20.5 the encoder is renamed to outbound_config only in the handshake phase
String encoderName = pipeline.get("outbound_config") != null
? "outbound_config" : "encoder";
// inject our handlers
pipeline.addAfter(
encoderName,
WIRE_PACKET_ENCODER_NAME,
WIRE_PACKET_ENCODER);
pipeline.addAfter(
this.wrappedChannel.pipeline().addAfter("encoder", WIRE_PACKET_ENCODER_NAME, WIRE_PACKET_ENCODER);
this.wrappedChannel.pipeline().addAfter(
"decoder",
INTERCEPTOR_NAME,
new InboundPacketInterceptor(this, this.channelListener));

View File

@ -638,8 +638,7 @@ public final class MinecraftReflection {
}
public static boolean isBundleDelimiter(Class<?> packetClass) {
Class<?> bundleDelimiterClass = getBundleDelimiterClass().orElse(null);
return bundleDelimiterClass != null && (packetClass.equals(bundleDelimiterClass) || bundleDelimiterClass.isAssignableFrom(packetClass));
return Optionals.Equals(getBundleDelimiterClass(), packetClass);
}
public static Optional<Class<?>> getBundleDelimiterClass() {
@ -1725,8 +1724,4 @@ public final class MinecraftReflection {
public static Class<?> getHolderLookupProviderClass() {
return getMinecraftClass("core.HolderLookup$a" /* Spigot Mappings */, "core.HolderLookup$Provider" /* Mojang Mappings */);
}
public static Class<?> getProtocolInfoClass() {
return getMinecraftClass("network.ProtocolInfo");
}
}

View File

@ -9,16 +9,11 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
/**
* Static getter for the registry access accessor which is need for most of the methods
* since 1.20.5 that access the registry and in form.
*/
public class MinecraftRegistryAccess {
private static MethodAccessor GET_SERVER = null;
private static MethodAccessor REGISTRY_ACCESS = null;
// lazy initialized
private static Object registryAccess = null;
static {
@ -39,12 +34,6 @@ public class MinecraftRegistryAccess {
}
}
/**
* Returns the composite global registry access. Equiv. of
* <pre>((CraftServer) Bukkit.getServer()).getServer().registryAccess()</pre>
*
* @return composite registy acesss
*/
public static Object get() {
if (GET_SERVER == null || REGISTRY_ACCESS == null) {
return null;