3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Support for new PS when package isn't found

Dieser Commit ist enthalten in:
Myles 2016-10-26 17:33:16 +01:00
Ursprung 783542401b
Commit 55fccba711

Datei anzeigen

@ -3,16 +3,12 @@ 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();
@ -37,8 +33,8 @@ public class ClassGenerator {
addSpigotCompatibility(pool, BukkitDecodeHandler.class, decodeSuper); addSpigotCompatibility(pool, BukkitDecodeHandler.class, decodeSuper);
addSpigotCompatibility(pool, BukkitEncodeHandler.class, encodeSuper); addSpigotCompatibility(pool, BukkitEncodeHandler.class, encodeSuper);
} else { } else {
Class decodeSuper = Class.forName(getPSPackage() + ".wrapped.WrappedDecoder"); Class decodeSuper = Class.forName(getPSPackage().equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketDecoder" : getPSPackage() + ".wrapped.WrappedDecoder");
Class encodeSuper = Class.forName(getPSPackage() + ".wrapped.WrappedEncoder"); Class encodeSuper = Class.forName(getPSPackage().equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketEncoder" : getPSPackage() + ".wrapped.WrappedEncoder");
// Generate the classes // Generate the classes
addPSCompatibility(pool, BukkitDecodeHandler.class, decodeSuper); addPSCompatibility(pool, BukkitDecodeHandler.class, decodeSuper);
addPSCompatibility(pool, BukkitEncodeHandler.class, encodeSuper); addPSCompatibility(pool, BukkitEncodeHandler.class, encodeSuper);
@ -114,6 +110,7 @@ public class ClassGenerator {
} }
private static Class addPSCompatibility(ClassPool pool, Class input, Class superclass) { private static Class addPSCompatibility(ClassPool pool, Class input, Class superclass) {
boolean newPS = getPSPackage().equals("unknown");
String newName = "us.myles.ViaVersion.classgenerator.generated." + input.getSimpleName(); String newName = "us.myles.ViaVersion.classgenerator.generated." + input.getSimpleName();
try { try {
@ -122,6 +119,7 @@ public class ClassGenerator {
CtClass toExtend = pool.get(superclass.getName()); CtClass toExtend = pool.get(superclass.getName());
generated.setSuperclass(toExtend); generated.setSuperclass(toExtend);
if (!newPS) {
// Override setRealEncoder / setRealDecoder // Override setRealEncoder / setRealDecoder
pool.importPackage(getPSPackage()); pool.importPackage(getPSPackage());
pool.importPackage(getPSPackage() + ".wrapped"); pool.importPackage(getPSPackage() + ".wrapped");
@ -150,6 +148,7 @@ public class ClassGenerator {
" }", generated)); " }", generated));
} }
} }
}
return generated.toClass(HandlerConstructor.class.getClassLoader()); return generated.toClass(HandlerConstructor.class.getClassLoader());
} catch (NotFoundException e) { } catch (NotFoundException e) {
e.printStackTrace(); e.printStackTrace();