From 48644ee53ddcc835b90b78b91407a2f9cde04297 Mon Sep 17 00:00:00 2001 From: Lauriichan Date: Thu, 20 Jan 2022 19:41:32 +0100 Subject: [PATCH] Fixed vCompat init --- .../minecraft/vcompat/VersionCompatProvider.java | 13 ++----------- .../vcompat/util/java/tools/ReflectionTools.java | 2 +- .../minecraft/vcompat/VersionCompat.java | 6 +++--- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java index 6c5ec69..536f25b 100644 --- a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java @@ -1,11 +1,10 @@ package net.sourcewriters.minecraft.vcompat; -import com.syntaxphoenix.syntaxapi.utils.java.Exceptions; import com.syntaxphoenix.syntaxapi.utils.java.tools.Container; import net.sourcewriters.minecraft.vcompat.provider.VersionControl; import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; -import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; public abstract class VersionCompatProvider { @@ -16,19 +15,11 @@ public static VersionCompatProvider get() { if (PROVIDER.isPresent()) { return PROVIDER.get(); } - try { - Class clazz = ReflectionTools.getClass(IMPLEMENTATION_PATH); - System.out.println("Class: " + (clazz == null)); - System.out.println("Class: " + IMPLEMENTATION_PATH); - Object object = clazz.getConstructor().newInstance(); + Object object = ClassLookup.of(IMPLEMENTATION_PATH).init(); if (object == null || !(object instanceof VersionCompatProvider)) { throw new IllegalStateException("Can't initialize VersionCompatProvider!"); } return PROVIDER.replace((VersionCompatProvider) object).lock().get(); - } catch (Exception exp) { - System.out.println(Exceptions.stackTraceToString(exp)); - throw new IllegalStateException("Can't initialize VersionCompatProvider!"); - } } protected final ClassLookupProvider lookupProvider = new ClassLookupProvider(); diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java index a0ee007..951a991 100644 --- a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java @@ -43,7 +43,7 @@ public static Class arrayclass(Class clazz) { public static Class getClass(String classPath) { try { - return Class.forName(classPath, true, null); + return Class.forName(classPath); } catch (ClassNotFoundException ignored) { return null; } diff --git a/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java b/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java index 091f185..1801d34 100644 --- a/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java +++ b/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java @@ -1,12 +1,12 @@ package net.sourcewriters.minecraft.vcompat; import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.sourcewriters.minecraft.vcompat.version.Versions; -import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools; public final class VersionCompat extends VersionCompatProvider { - private static final String VERSION_PATH = String.format("%s.provider.impl.v%s.VersionControl%s", VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString()); + private static final String VERSION_PATH = String.format("%s.provider.impl.%s.VersionControl%s", VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString().substring(1)); private final VersionControl control; @@ -16,7 +16,7 @@ public VersionCompat() { } private final VersionControl initControl() { - Object object = ReflectionTools.createInstance(ReflectionTools.getClass(VERSION_PATH)); + Object object = ClassLookup.of(VERSION_PATH).searchMethod("init", "init").run("init"); if (object == null || !(object instanceof VersionControl)) { throw new IllegalStateException("Can't initialize VersionControl"); }