Skip to content

Commit

Permalink
Fixed vCompat init
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Jan 20, 2022
1 parent c46dc3c commit 48644ee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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");
}
Expand Down

0 comments on commit 48644ee

Please sign in to comment.