Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
Tell ProtocolSupport to decode MINECRAFT_FUTURE packets using the default decoder (for 1.9.4)
Dieser Commit ist enthalten in:
Ursprung
8093c424e2
Commit
f92b7e5b80
@ -3,12 +3,16 @@ package us.myles.ViaVersion.bukkit.classgenerator;
|
|||||||
import javassist.*;
|
import javassist.*;
|
||||||
import javassist.expr.ConstructorCall;
|
import javassist.expr.ConstructorCall;
|
||||||
import javassist.expr.ExprEditor;
|
import javassist.expr.ExprEditor;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.bukkit.handlers.BukkitDecodeHandler;
|
import us.myles.ViaVersion.bukkit.handlers.BukkitDecodeHandler;
|
||||||
import us.myles.ViaVersion.bukkit.handlers.BukkitEncodeHandler;
|
import us.myles.ViaVersion.bukkit.handlers.BukkitEncodeHandler;
|
||||||
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||||
|
import us.myles.ViaVersion.handlers.ViaHandler;
|
||||||
|
|
||||||
public class ClassGenerator {
|
public class ClassGenerator {
|
||||||
private static HandlerConstructor constructor = new BasicHandlerConstructor();
|
private static HandlerConstructor constructor = new BasicHandlerConstructor();
|
||||||
@ -124,16 +128,25 @@ public class ClassGenerator {
|
|||||||
if (superclass.getName().endsWith("Decoder")) {
|
if (superclass.getName().endsWith("Decoder")) {
|
||||||
// Decoder
|
// Decoder
|
||||||
generated.addMethod(CtMethod.make("public void setRealDecoder(IPacketDecoder dec) {\n" +
|
generated.addMethod(CtMethod.make("public void setRealDecoder(IPacketDecoder dec) {\n" +
|
||||||
" WrappedDecoder decoder = new WrappedDecoder();" +
|
" ((WrappedDecoder) this.minecraftDecoder).setRealDecoder(dec);\n" +
|
||||||
" decoder.setRealDecoder(dec);\n" +
|
|
||||||
" this.minecraftDecoder = decoder;\n" +
|
|
||||||
" }", generated));
|
" }", generated));
|
||||||
} else {
|
} else {
|
||||||
// Encoder
|
// Encoder
|
||||||
|
pool.importPackage("protocolsupport.api");
|
||||||
|
pool.importPackage("java.lang.reflect");
|
||||||
generated.addMethod(CtMethod.make("public void setRealEncoder(IPacketEncoder enc) {\n" +
|
generated.addMethod(CtMethod.make("public void setRealEncoder(IPacketEncoder enc) {\n" +
|
||||||
" WrappedEncoder encoder = new WrappedEncoder();" +
|
" try {\n" +
|
||||||
" encoder.setRealEncoder(enc);\n" +
|
// Tell ProtocolSupport to decode MINECRAFT_FUTURE packets using the default decoder (for 1.9.4)
|
||||||
" this.minecraftEncoder = encoder;\n" +
|
" Field field = enc.getClass().getDeclaredField(\"version\");\n" +
|
||||||
|
" field.setAccessible(true);\n" +
|
||||||
|
" ProtocolVersion version = (ProtocolVersion) field.get(enc);\n" +
|
||||||
|
|
||||||
|
" if (version == ProtocolVersion.MINECRAFT_FUTURE) enc = enc.getClass().getConstructor(\n" +
|
||||||
|
" new Class[]{ProtocolVersion.class}).newInstance(new Object[] {ProtocolVersion.getLatest()});\n" +
|
||||||
|
" } catch (Exception e) {\n" +
|
||||||
|
// I guess we're not on 1.9.4
|
||||||
|
" }\n" +
|
||||||
|
" ((WrappedEncoder) this.minecraftEncoder).setRealEncoder(enc);\n" +
|
||||||
" }", generated));
|
" }", generated));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaHand
|
|||||||
|
|
||||||
public void transform(ByteBuf bytebuf) throws Exception {
|
public void transform(ByteBuf bytebuf) throws Exception {
|
||||||
if (bytebuf.readableBytes() == 0) {
|
if (bytebuf.readableBytes() == 0) {
|
||||||
throw new CancelException();
|
return; // Someone Already Decoded It!
|
||||||
}
|
}
|
||||||
// Increment sent
|
// Increment sent
|
||||||
info.incrementSent();
|
info.incrementSent();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren