Skip to content

Commit

Permalink
New version matcher for different bytecode versions problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-nsiqueira committed Aug 8, 2021
1 parent 53253b9 commit 4bb3e41
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions api/src/main/java/net/wesjd/anvilgui/version/VersionMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@ public class VersionMatcher {
* The server's version
*/
private final String serverVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].substring(1);
/**
* All available {@link VersionWrapper}s
*/
private final List<Class<? extends VersionWrapper>> versions = Arrays.asList(
Wrapper1_7_R4.class,
Wrapper1_8_R1.class,
Wrapper1_8_R2.class,
Wrapper1_8_R3.class,
Wrapper1_9_R1.class,
Wrapper1_9_R2.class,
Wrapper1_10_R1.class,
Wrapper1_11_R1.class,
Wrapper1_12_R1.class,
Wrapper1_13_R1.class,
Wrapper1_13_R2.class,
Wrapper1_14_R1.class,
Wrapper1_15_R1.class,
Wrapper1_16_R1.class,
Wrapper1_16_R2.class,
Wrapper1_16_R3.class,
Wrapper1_17_R1.class
);

/**
* Matches the server version to it's {@link VersionWrapper}
Expand All @@ -48,12 +26,11 @@ public class VersionMatcher {
*/
public VersionWrapper match() {
try {
return versions.stream()
.filter(version -> version.getSimpleName().substring(7).equals(serverVersion))
.findFirst().orElseThrow(() -> new RuntimeException("Your server version isn't supported in AnvilGUI!"))
.newInstance();
return (VersionWrapper) Class.forName(this.getClass().getPackage().getName() + ".Wrapper" + serverVersion).newInstance();
} catch (IllegalAccessException | InstantiationException ex) {
throw new RuntimeException(ex);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Your server version isn't supported in AnvilGUI!");
}
}

Expand Down

0 comments on commit 4bb3e41

Please sign in to comment.