Skip to content

Commit

Permalink
Fix VersionMatcher compatibility with other 1.20.x versions (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda authored Jun 21, 2024
1 parent 0b2dd5f commit ae7b777
Show file tree
Hide file tree
Showing 35 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion 1_10_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_10_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_11_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_11_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_12_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_12_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_13_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_13_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_13_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_13_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_14_4_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_14_4_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_14_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_14_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_15_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_15_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_16_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_16_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_16_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_16_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_16_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_16_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_17_1_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_17_1_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_17_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_17_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_18_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_18_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_18_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_18_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_19_1_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_19_1_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_19_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_19_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_19_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_19_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_19_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_19_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_20_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_20_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_20_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_20_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_20_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_20_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_20_R4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_20_R4</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_21_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_21_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_7_R4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_7_R4</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_8_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_8_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_8_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_8_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_8_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_8_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_9_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_9_R1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion 1_9_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-1_9_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AnvilGUI requires the usage of Maven or a Maven compatible build system.
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</dependency>

<repository>
Expand Down
2 changes: 1 addition & 1 deletion abstraction/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui-abstraction</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
</parent>

<artifactId>anvilgui</artifactId>
Expand Down
35 changes: 19 additions & 16 deletions api/src/main/java/net/wesjd/anvilgui/version/VersionMatcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.wesjd.anvilgui.version;

import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;

/**
Expand All @@ -9,6 +11,21 @@
* @since 1.2.1
*/
public class VersionMatcher {
/** Maps a Minecraft version string to the corresponding revision string */
private static final Map<String, String> VERSION_TO_REVISION = new HashMap<String, String>() {
{
this.put("1.20", "1_20_R1");
this.put("1.20.1", "1_20_R1");
this.put("1.20.2", "1_20_R2");
this.put("1.20.3", "1_20_R3");
this.put("1.20.4", "1_20_R3");
this.put("1.20.5", "1_20_R4");
this.put("1.20.6", "1_20_R4");
this.put("1.21", "1_21_R1");
}
};
/* This needs to be updated to reflect the newest available version wrapper */
private static final String FALLBACK_REVISION = "1_21_R1";

/**
* Matches the server version to it's {@link VersionWrapper}
Expand All @@ -17,26 +34,12 @@ public class VersionMatcher {
* @throws IllegalStateException If the version wrapper failed to be instantiated or is unable to be found
*/
public VersionWrapper match() {

String craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();

String rVersion;
if (!craftBukkitPackage.contains(".v")) { // cb package not relocated (i.e. paper 1.20.5+)
// separating major and minor versions, example: 1.20.4-R0.1-SNAPSHOT -> major = 20, minor = 4
final String[] versionNumbers =
Bukkit.getBukkitVersion().split("-")[0].split("\\.");
int major = Integer.parseInt(versionNumbers[1]);
int minor = Integer.parseInt(versionNumbers[2]);

if (major == 20 && minor >= 5) {
rVersion = "1_20_R4";
} else if (major == 21) {
rVersion = "1_21_R1";
} else {
throw new IllegalStateException(
"AnvilGUI does not support bukkit server version \"" + Bukkit.getBukkitVersion() + "\"");
}

final String version = Bukkit.getBukkitVersion().split("-")[0];
rVersion = VERSION_TO_REVISION.getOrDefault(version, FALLBACK_REVISION);
} else {
rVersion = craftBukkitPackage.split("\\.")[3].substring(1);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.wesjd</groupId>
<artifactId>anvilgui-parent</artifactId>
<version>1.9.5-SNAPSHOT</version>
<version>1.9.6-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit ae7b777

Please sign in to comment.