Skip to content

Commit

Permalink
Merge pull request #32 from SourceWriters/development
Browse files Browse the repository at this point in the history
Fix reflections
  • Loading branch information
YellowPhoenix18 authored Jan 20, 2022
2 parents b695f0f + 48644ee commit e8a5580
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 124 deletions.
1 change: 1 addition & 0 deletions vcompat-1_18_R1/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.apt_generated/
/.apt_generated_tests/
110 changes: 54 additions & 56 deletions vcompat-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat-api</artifactId>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat-api</artifactId>

<dependencies>
<dependencies>

<!-- Syntax Api -->
<!-- Syntax Api -->

<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>java</artifactId>
<version>2.0.14</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>nbt</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>version</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>key</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>random</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>logging</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>json-lib</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>java</artifactId>
<version>2.0.14</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>nbt</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>version</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>key</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>random</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>logging</artifactId>
<version>2.0.11</version>
</dependency>
<dependency>
<groupId>com.syntaxphoenix.syntaxapi</groupId>
<artifactId>json-lib</artifactId>
<version>2.0.11</version>
</dependency>

<!-- Minecraft -->
<!-- Minecraft -->

<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down Expand Up @@ -93,4 +91,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
public abstract class VersionCompatProvider {

protected static final Container<VersionCompatProvider> 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();

/*
* Impl
*/

public abstract VersionControl getControl();

public final ClassLookupProvider getLookupProvider() {
return lookupProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
108 changes: 53 additions & 55 deletions vcompat-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat</artifactId>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>vcompat</artifactId>

<dependencies>
<dependencies>

<!-- vCompat Api -->

Expand All @@ -36,48 +34,48 @@
<artifactId>vcompat-1_18_R1</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.syntaxphoenix.syntaxapi</pattern>
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.syntaxphoenix.syntaxapi</pattern>
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit e8a5580

Please sign in to comment.