Skip to content

Commit e8a5580

Browse files
Merge pull request #32 from SourceWriters/development
Fix reflections
2 parents b695f0f + 48644ee commit e8a5580

File tree

6 files changed

+128
-124
lines changed

6 files changed

+128
-124
lines changed

vcompat-1_18_R1/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.apt_generated/
2+
/.apt_generated_tests/

vcompat-api/pom.xml

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>net.sourcewriters.minecraft</groupId>
7-
<artifactId>vcompat-parent</artifactId>
8-
<version>3.0.0</version>
9-
</parent>
10-
<artifactId>vcompat-api</artifactId>
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>net.sourcewriters.minecraft</groupId>
5+
<artifactId>vcompat-parent</artifactId>
6+
<version>3.0.0</version>
7+
</parent>
8+
<artifactId>vcompat-api</artifactId>
119

12-
<dependencies>
10+
<dependencies>
1311

14-
<!-- Syntax Api -->
12+
<!-- Syntax Api -->
1513

16-
<dependency>
17-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
18-
<artifactId>java</artifactId>
19-
<version>2.0.14</version>
20-
</dependency>
21-
<dependency>
22-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
23-
<artifactId>nbt</artifactId>
24-
<version>2.0.12</version>
25-
</dependency>
26-
<dependency>
27-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
28-
<artifactId>version</artifactId>
29-
<version>2.0.12</version>
30-
</dependency>
31-
<dependency>
32-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
33-
<artifactId>key</artifactId>
34-
<version>2.0.11</version>
35-
</dependency>
36-
<dependency>
37-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
38-
<artifactId>random</artifactId>
39-
<version>2.0.11</version>
40-
</dependency>
41-
<dependency>
42-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
43-
<artifactId>logging</artifactId>
44-
<version>2.0.11</version>
45-
</dependency>
46-
<dependency>
47-
<groupId>com.syntaxphoenix.syntaxapi</groupId>
48-
<artifactId>json-lib</artifactId>
49-
<version>2.0.11</version>
50-
</dependency>
14+
<dependency>
15+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
16+
<artifactId>java</artifactId>
17+
<version>2.0.14</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
21+
<artifactId>nbt</artifactId>
22+
<version>2.0.12</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
26+
<artifactId>version</artifactId>
27+
<version>2.0.12</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
31+
<artifactId>key</artifactId>
32+
<version>2.0.11</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
36+
<artifactId>random</artifactId>
37+
<version>2.0.11</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
41+
<artifactId>logging</artifactId>
42+
<version>2.0.11</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.syntaxphoenix.syntaxapi</groupId>
46+
<artifactId>json-lib</artifactId>
47+
<version>2.0.11</version>
48+
</dependency>
5149

52-
<!-- Minecraft -->
50+
<!-- Minecraft -->
5351

54-
<dependency>
55-
<groupId>jline</groupId>
56-
<artifactId>jline</artifactId>
57-
<version>2.12.1</version>
58-
<scope>provided</scope>
59-
</dependency>
60-
</dependencies>
52+
<dependency>
53+
<groupId>jline</groupId>
54+
<artifactId>jline</artifactId>
55+
<version>2.12.1</version>
56+
<scope>provided</scope>
57+
</dependency>
58+
</dependencies>
6159

6260
<build>
6361
<plugins>
@@ -93,4 +91,4 @@
9391
</plugin>
9492
</plugins>
9593
</build>
96-
</project>
94+
</project>

vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@
99
public abstract class VersionCompatProvider {
1010

1111
protected static final Container<VersionCompatProvider> PROVIDER = Container.of();
12+
private static final String IMPLEMENTATION_PATH = VersionCompatProvider.class.getPackageName() + ".VersionCompat";
1213

1314
public static VersionCompatProvider get() {
1415
if (PROVIDER.isPresent()) {
1516
return PROVIDER.get();
1617
}
17-
Object object = ClassLookup.of(VersionCompatProvider.class.getPackageName() + ".VersionCompat").init();
18-
if (object == null || !(object instanceof VersionCompatProvider)) {
19-
throw new IllegalStateException("Can't initialize VersionCompatProvider!");
20-
}
21-
return PROVIDER.replace((VersionCompatProvider) object).lock().get();
18+
Object object = ClassLookup.of(IMPLEMENTATION_PATH).init();
19+
if (object == null || !(object instanceof VersionCompatProvider)) {
20+
throw new IllegalStateException("Can't initialize VersionCompatProvider!");
21+
}
22+
return PROVIDER.replace((VersionCompatProvider) object).lock().get();
2223
}
23-
24+
2425
protected final ClassLookupProvider lookupProvider = new ClassLookupProvider();
2526

2627
/*
2728
* Impl
2829
*/
2930

3031
public abstract VersionControl getControl();
31-
32+
3233
public final ClassLookupProvider getLookupProvider() {
3334
return lookupProvider;
3435
}

vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public static Class<?> getClass(String classPath) {
4949
}
5050
}
5151

52+
public static Object createInstance(Class<?> clazz) {
53+
try {
54+
return clazz.getConstructor().newInstance();
55+
} catch (Exception ignored) {
56+
return null;
57+
}
58+
}
59+
5260
public static Object getValue(Field field, Object source) {
5361
if (field != null) {
5462
boolean access = field.canAccess(source);

vcompat-core/pom.xml

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>net.sourcewriters.minecraft</groupId>
7-
<artifactId>vcompat-parent</artifactId>
8-
<version>3.0.0</version>
9-
</parent>
10-
<artifactId>vcompat</artifactId>
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>net.sourcewriters.minecraft</groupId>
5+
<artifactId>vcompat-parent</artifactId>
6+
<version>3.0.0</version>
7+
</parent>
8+
<artifactId>vcompat</artifactId>
119

12-
<dependencies>
10+
<dependencies>
1311

1412
<!-- vCompat Api -->
1513

@@ -36,48 +34,48 @@
3634
<artifactId>vcompat-1_18_R1</artifactId>
3735
<version>3.0.0</version>
3836
</dependency>
39-
</dependencies>
37+
</dependencies>
4038

41-
<build>
42-
<plugins>
43-
<plugin>
44-
<artifactId>maven-shade-plugin</artifactId>
45-
<version>3.2.4</version>
46-
<executions>
47-
<execution>
48-
<phase>package</phase>
49-
<goals>
50-
<goal>shade</goal>
51-
</goals>
52-
</execution>
53-
</executions>
54-
<configuration>
55-
<filters>
56-
<filter>
57-
<artifact>*:*</artifact>
58-
<excludes>
59-
<exclude>META-INF/*.SF</exclude>
60-
<exclude>META-INF/*.DSA</exclude>
61-
<exclude>META-INF/*.RSA</exclude>
62-
</excludes>
63-
</filter>
64-
</filters>
65-
<relocations>
66-
<relocation>
67-
<pattern>com.syntaxphoenix.syntaxapi</pattern>
68-
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
69-
</relocation>
70-
</relocations>
71-
</configuration>
72-
</plugin>
73-
<plugin>
74-
<groupId>org.apache.maven.plugins</groupId>
75-
<artifactId>maven-deploy-plugin</artifactId>
76-
<version>3.0.0-M2</version>
77-
<configuration>
78-
<skip>false</skip>
79-
</configuration>
80-
</plugin>
81-
</plugins>
82-
</build>
83-
</project>
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<artifactId>maven-shade-plugin</artifactId>
43+
<version>3.2.4</version>
44+
<executions>
45+
<execution>
46+
<phase>package</phase>
47+
<goals>
48+
<goal>shade</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
<configuration>
53+
<filters>
54+
<filter>
55+
<artifact>*:*</artifact>
56+
<excludes>
57+
<exclude>META-INF/*.SF</exclude>
58+
<exclude>META-INF/*.DSA</exclude>
59+
<exclude>META-INF/*.RSA</exclude>
60+
</excludes>
61+
</filter>
62+
</filters>
63+
<relocations>
64+
<relocation>
65+
<pattern>com.syntaxphoenix.syntaxapi</pattern>
66+
<shadedPattern>net.sourcewriters.minecraft.vcompat.shaded.syntaxapi</shadedPattern>
67+
</relocation>
68+
</relocations>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-deploy-plugin</artifactId>
74+
<version>3.0.0-M2</version>
75+
<configuration>
76+
<skip>false</skip>
77+
</configuration>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
</project>

vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup;
55
import net.sourcewriters.minecraft.vcompat.version.Versions;
66

7-
final class VersionCompat extends VersionCompatProvider {
8-
9-
public static final String CLASSPATH = "%s.provider.impl.v%s.VersionControl%s";
7+
public final class VersionCompat extends VersionCompatProvider {
8+
9+
private static final String VERSION_PATH = String.format("%s.provider.impl.%s.VersionControl%s", VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString().substring(1));
1010

1111
private final VersionControl control;
1212

@@ -16,9 +16,7 @@ public VersionCompat() {
1616
}
1717

1818
private final VersionControl initControl() {
19-
Object object = ClassLookup
20-
.of(String.format(CLASSPATH, VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString()))
21-
.init();
19+
Object object = ClassLookup.of(VERSION_PATH).searchMethod("init", "init").run("init");
2220
if (object == null || !(object instanceof VersionControl)) {
2321
throw new IllegalStateException("Can't initialize VersionControl");
2422
}

0 commit comments

Comments
 (0)