From 4f9f3254bee90e77d382528f56bc523b7680ce0a Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 15 May 2021 09:28:18 +0200 Subject: [PATCH] Fix PS compatibility on Java 16 --- .../bukkit/classgenerator/ClassGenerator.java | 11 ++++++----- .../bukkit/handlers/BukkitChannelInitializer.java | 2 +- .../generated}/BasicHandlerConstructor.java | 2 +- .../generated}/HandlerConstructor.java | 2 +- .../viaversion/viaversion/util/ConcurrentList.java | 14 +------------- gradle/libs.versions.toml | 2 +- 6 files changed, 11 insertions(+), 22 deletions(-) rename bukkit/src/main/java/com/viaversion/viaversion/{bukkit/classgenerator => classgenerator/generated}/BasicHandlerConstructor.java (96%) rename bukkit/src/main/java/com/viaversion/viaversion/{bukkit/classgenerator => classgenerator/generated}/HandlerConstructor.java (95%) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java index f4be26243..0365d694c 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java @@ -21,6 +21,8 @@ import com.viaversion.viaversion.ViaVersionPlugin; import com.viaversion.viaversion.bukkit.handlers.BukkitDecodeHandler; import com.viaversion.viaversion.bukkit.handlers.BukkitEncodeHandler; import com.viaversion.viaversion.bukkit.util.NMSUtil; +import com.viaversion.viaversion.classgenerator.generated.BasicHandlerConstructor; +import com.viaversion.viaversion.classgenerator.generated.HandlerConstructor; import javassist.CannotCompileException; import javassist.ClassPool; import javassist.CtClass; @@ -144,7 +146,7 @@ public class ClassGenerator { } } } - return generated.toClass(HandlerConstructor.class.getClassLoader()); + return generated.toClass(HandlerConstructor.class); } catch (NotFoundException e) { e.printStackTrace(); } catch (CannotCompileException e) { @@ -153,7 +155,7 @@ public class ClassGenerator { return null; } - private static Class addPSCompatibility(ClassPool pool, Class input, Class superclass) { + private static void addPSCompatibility(ClassPool pool, Class input, Class superclass) { boolean newPS = getOldPSPackage().equals("unknown"); String newName = "com.viaversion.viaversion.classgenerator.generated." + input.getSimpleName(); @@ -193,13 +195,12 @@ public class ClassGenerator { } } } - return generated.toClass(HandlerConstructor.class.getClassLoader()); + generated.toClass(HandlerConstructor.class); } catch (NotFoundException e) { e.printStackTrace(); } catch (CannotCompileException e) { e.printStackTrace(); } - return null; } private static Class makePSConnectListener(ClassPool pool, boolean newVersionMethod) { @@ -247,7 +248,7 @@ public class ClassGenerator { // In any case, remove the packet listener and wrap up. + " connection.removePacketListener(this);\n" + "}", connectListenerClazz)); - return connectListenerClazz.toClass(HandlerConstructor.class.getClassLoader()); + return connectListenerClazz.toClass(HandlerConstructor.class); } catch (Exception e) { e.printStackTrace(); } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java index 9c7223408..d76f78554 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java @@ -19,7 +19,7 @@ package com.viaversion.viaversion.bukkit.handlers; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator; -import com.viaversion.viaversion.bukkit.classgenerator.HandlerConstructor; +import com.viaversion.viaversion.classgenerator.generated.HandlerConstructor; import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import io.netty.channel.Channel; diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/BasicHandlerConstructor.java b/bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/BasicHandlerConstructor.java similarity index 96% rename from bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/BasicHandlerConstructor.java rename to bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/BasicHandlerConstructor.java index c23919d2a..43cc14fd7 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/BasicHandlerConstructor.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/BasicHandlerConstructor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.bukkit.classgenerator; +package com.viaversion.viaversion.classgenerator.generated; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.bukkit.handlers.BukkitDecodeHandler; diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/HandlerConstructor.java b/bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/HandlerConstructor.java similarity index 95% rename from bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/HandlerConstructor.java rename to bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/HandlerConstructor.java index 5b568fd67..656054add 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/HandlerConstructor.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/classgenerator/generated/HandlerConstructor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.bukkit.classgenerator; +package com.viaversion.viaversion.classgenerator.generated; import com.viaversion.viaversion.api.connection.UserConnection; import io.netty.handler.codec.ByteToMessageDecoder; diff --git a/common/src/main/java/com/viaversion/viaversion/util/ConcurrentList.java b/common/src/main/java/com/viaversion/viaversion/util/ConcurrentList.java index 8a89e1f3d..e0843ed31 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/ConcurrentList.java +++ b/common/src/main/java/com/viaversion/viaversion/util/ConcurrentList.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.util; -import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -79,17 +77,7 @@ public class ConcurrentList extends ArrayList { @Override public Object clone() { synchronized (lock) { - try { - ConcurrentList clist = (ConcurrentList) super.clone(); - clist.modCount = 0; - Field f = ArrayList.class.getDeclaredField("elementData"); - f.setAccessible(true); - f.set(clist, Arrays.copyOf((Object[]) f.get(this), this.size())); - - return clist; - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return super.clone(); } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9c2af2b48..817c9d769 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ adventure = "4.7.0" gson = "2.8.6" fastutil = "8.3.1" openNBT = "2.0-SNAPSHOT" -javassist = "3.27.0-GA" +javassist = "3.28.0-GA" # Common provided netty = "4.0.20.Final"