diff --git a/vcompat-1_18_R1/.gitignore b/vcompat-1_18_R1/.gitignore index c71ea97..00d2ab7 100644 --- a/vcompat-1_18_R1/.gitignore +++ b/vcompat-1_18_R1/.gitignore @@ -1 +1,2 @@ /.apt_generated/ +/.apt_generated_tests/ diff --git a/vcompat-api/pom.xml b/vcompat-api/pom.xml index edae13e..3a9bd4a 100644 --- a/vcompat-api/pom.xml +++ b/vcompat-api/pom.xml @@ -1,63 +1,61 @@ - - 4.0.0 - - net.sourcewriters.minecraft - vcompat-parent - 3.0.0 - - vcompat-api + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat-api - + - + - - com.syntaxphoenix.syntaxapi - java - 2.0.14 - - - com.syntaxphoenix.syntaxapi - nbt - 2.0.12 - - - com.syntaxphoenix.syntaxapi - version - 2.0.12 - - - com.syntaxphoenix.syntaxapi - key - 2.0.11 - - - com.syntaxphoenix.syntaxapi - random - 2.0.11 - - - com.syntaxphoenix.syntaxapi - logging - 2.0.11 - - - com.syntaxphoenix.syntaxapi - json-lib - 2.0.11 - + + com.syntaxphoenix.syntaxapi + java + 2.0.14 + + + com.syntaxphoenix.syntaxapi + nbt + 2.0.12 + + + com.syntaxphoenix.syntaxapi + version + 2.0.12 + + + com.syntaxphoenix.syntaxapi + key + 2.0.11 + + + com.syntaxphoenix.syntaxapi + random + 2.0.11 + + + com.syntaxphoenix.syntaxapi + logging + 2.0.11 + + + com.syntaxphoenix.syntaxapi + json-lib + 2.0.11 + - + - - jline - jline - 2.12.1 - provided - - + + jline + jline + 2.12.1 + provided + + @@ -93,4 +91,4 @@ - + \ No newline at end of file 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 40d6a04..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 @@ -9,18 +9,19 @@ public abstract class VersionCompatProvider { protected static final Container PROVIDER = Container.of(); + private static final String IMPLEMENTATION_PATH = VersionCompatProvider.class.getPackageName() + ".VersionCompat"; public static VersionCompatProvider get() { if (PROVIDER.isPresent()) { return PROVIDER.get(); } - Object object = ClassLookup.of(VersionCompatProvider.class.getPackageName() + ".VersionCompat").init(); - if (object == null || !(object instanceof VersionCompatProvider)) { - throw new IllegalStateException("Can't initialize VersionCompatProvider!"); - } - return PROVIDER.replace((VersionCompatProvider) object).lock().get(); + 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(); } - + protected final ClassLookupProvider lookupProvider = new ClassLookupProvider(); /* @@ -28,7 +29,7 @@ public static VersionCompatProvider get() { */ public abstract VersionControl getControl(); - + public final ClassLookupProvider getLookupProvider() { return lookupProvider; } 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 a86ac9b..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 @@ -49,6 +49,14 @@ public static Class getClass(String classPath) { } } + public static Object createInstance(Class clazz) { + try { + return clazz.getConstructor().newInstance(); + } catch (Exception ignored) { + return null; + } + } + public static Object getValue(Field field, Object source) { if (field != null) { boolean access = field.canAccess(source); diff --git a/vcompat-core/pom.xml b/vcompat-core/pom.xml index 9e39d44..4d3a05a 100644 --- a/vcompat-core/pom.xml +++ b/vcompat-core/pom.xml @@ -1,15 +1,13 @@ - - 4.0.0 - - net.sourcewriters.minecraft - vcompat-parent - 3.0.0 - - vcompat + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat - + @@ -36,48 +34,48 @@ vcompat-1_18_R1 3.0.0 - + - - - - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.syntaxphoenix.syntaxapi - net.sourcewriters.minecraft.vcompat.shaded.syntaxapi - - - - - - org.apache.maven.plugins - maven-deploy-plugin - 3.0.0-M2 - - false - - - - - + + + + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.syntaxphoenix.syntaxapi + net.sourcewriters.minecraft.vcompat.shaded.syntaxapi + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0-M2 + + false + + + + + \ No newline at end of file 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 3dc33df..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 @@ -4,9 +4,9 @@ import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.sourcewriters.minecraft.vcompat.version.Versions; -final class VersionCompat extends VersionCompatProvider { - - public static final String CLASSPATH = "%s.provider.impl.v%s.VersionControl%s"; +public final class VersionCompat extends VersionCompatProvider { + + 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,9 +16,7 @@ public VersionCompat() { } private final VersionControl initControl() { - Object object = ClassLookup - .of(String.format(CLASSPATH, VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString())) - .init(); + Object object = ClassLookup.of(VERSION_PATH).searchMethod("init", "init").run("init"); if (object == null || !(object instanceof VersionControl)) { throw new IllegalStateException("Can't initialize VersionControl"); }