Skip to content

Commit

Permalink
v1.2 - Fix 1.20.6+ on Paper
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakllp committed Aug 31, 2024
1 parent 3a47096 commit a8f8cf6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.mypet</groupId>
<artifactId>MyPetDownloader</artifactId>
<version>1.1</version>
<version>1.2</version>
<name>MyPetDownloader</name>

<build>
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/org/mypet/MyPetDownloader/MyPetDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public String toString() {
}

private static final Pattern PACKAGE_VERSION_MATCHER = Pattern.compile(".*\\.(v\\d+_\\d+_R\\d+)(?:.+)?");
private static final Pattern MINECRAFT_VERSION_MATCHER = Pattern.compile("\\(MC: (\\d\\.\\d+(?:\\.\\d+)?)");
private static final Pattern VERSION_MATCHER = Pattern.compile("\\d\\.\\d+(?:\\.\\d+)?");

private Map<String, Integer> compareCache = new HashMap<>();
private String minecraftVersion = "0.0.0";
protected static String internalVersion;
Expand All @@ -69,6 +72,15 @@ public void onLoad() {
if (regexMatcher.find()) {
internalVersion = regexMatcher.group(1);
}
regexMatcher = MINECRAFT_VERSION_MATCHER.matcher(Bukkit.getVersion());
if (regexMatcher.find()) {
minecraftVersion = regexMatcher.group(1);
}

// Paper 1.20.6+ works differently - yay
if (internalVersion == null) {
internalVersion = GetBukkitVersionFromMinecraftVersion();
}

Runnable generalDownloadRunner = () -> {
Optional<Download> download = check();
Expand All @@ -93,6 +105,22 @@ public void onLoad() {
}
}

private String GetBukkitVersionFromMinecraftVersion() {
String bukkitVersion;
switch(minecraftVersion) {
case "1.20.6":
bukkitVersion = "v1_20_R4";
break;
case "1.21":
case "1.21.1":
bukkitVersion = "v1_21_R1";
break;
default:
bukkitVersion=null;
}
return bukkitVersion;
}

private Optional<Download> check() {
try {
String url = "https://api.github.com/repos/MyPetORG/MyPet/releases";
Expand Down Expand Up @@ -168,11 +196,14 @@ private void download() {
}

private int compareWithMinecraftVersion(String version) {
if (compareCache.containsKey(minecraftVersion + "-::-" + version)) {
return compareCache.get(minecraftVersion + "-::-" + version);
if (VERSION_MATCHER.matcher(version).find()) {
if (compareCache.containsKey(minecraftVersion + "-::-" + version)) {
return compareCache.get(minecraftVersion + "-::-" + version);
}
int compare = Util.versionCompare(minecraftVersion, version);
compareCache.put(minecraftVersion + "-::-" + version, compare);
return compare;
}
int compare = Util.versionCompare(minecraftVersion, version);
compareCache.put(minecraftVersion + "-::-" + version, compare);
return compare;
throw new IllegalArgumentException("\"version\" must be a valid Minecraft version. \"" + version + "\" given.");
}
}

0 comments on commit a8f8cf6

Please sign in to comment.