Skip to content

Commit

Permalink
fix: removal of bukkit package remapping in paper (#370)
Browse files Browse the repository at this point in the history
* fix: removale of bukkit package remapping in paper

* fix: github ci
  • Loading branch information
Ingrim4 authored May 7, 2024
1 parent 5c50f4f commit ee5e1a8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ checkVersion "1.19.4" "17"
checkVersion "1.20.1" "17"
checkVersion "1.20.2" "17"
checkVersion "1.20.4" "17"
checkVersion "1.20.5" "21"
checkVersion "1.20.6" "21"
Original file line number Diff line number Diff line change
@@ -1,49 +1,181 @@
package net.imprex.orebfuscator.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;

public final class MinecraftVersion {
public final class MinecraftVersion implements Comparable<MinecraftVersion> {

private static final Pattern VERSION_PATTERN = Pattern.compile("org\\.bukkit\\.craftbukkit\\.(v(\\d+)_(\\d+)_R(\\d+))");
private static final class NmsMapping {

private static final String NMS_VERSION;
private static final int MAJOR_VERSION;
private static final int MINOR_VERSION;
private static final int REVISION_NUMBER;
private static final List<NmsMapping> MAPPINGS = new ArrayList<>();

static {
MAPPINGS.add(new NmsMapping("1.20.5", "v1_20_R4"));
}

public static String get(MinecraftVersion version) {
for (NmsMapping mapping : MAPPINGS) {
if (version.isAtOrAbove(mapping.version)) {
if (mapping.version.minor() != version.minor()) {
OFCLogger.warn(String.format("Using nms mapping with mismatched minor versions: %s - %s",
mapping.version, version));
}

return mapping.nmsVersion;
}
}

throw new RuntimeException("Can't get nms package version for minecraft version: " + version);
}

private final MinecraftVersion version;
private final String nmsVersion;

public NmsMapping(String version, String nmsVersion) {
this.version = new MinecraftVersion(version);
this.nmsVersion = nmsVersion;
}
}

private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(?:\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?");
private static final Pattern PACKAGE_PATTERN = Pattern.compile("org\\.bukkit\\.craftbukkit\\.(v\\d+_\\d+_R\\d+)");

private static final MinecraftVersion CURRENT_VERSION = new MinecraftVersion(Bukkit.getBukkitVersion());

private static String NMS_VERSION;

static {
String craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();
Matcher matcher = VERSION_PATTERN.matcher(craftBukkitPackage);
Matcher matcher = PACKAGE_PATTERN.matcher(craftBukkitPackage);

if (!matcher.find()) {
throw new RuntimeException("Can't parse craftbukkit package version " + craftBukkitPackage);
if (matcher.find()) {
NMS_VERSION = matcher.group(1);
} else {
NMS_VERSION = NmsMapping.get(CURRENT_VERSION);
}

NMS_VERSION = matcher.group(1);
MAJOR_VERSION = Integer.parseInt(matcher.group(2));
MINOR_VERSION = Integer.parseInt(matcher.group(3));
REVISION_NUMBER = Integer.parseInt(matcher.group(4));
}

public static String nmsVersion() {
return NMS_VERSION;
}

public static int majorVersion() {
return MAJOR_VERSION;
return CURRENT_VERSION.major;
}

public static int minorVersion() {
return MINOR_VERSION;
return CURRENT_VERSION.minor;
}

public static int patchVersion() {
return CURRENT_VERSION.patch;
}

public static boolean isAbove(String version) {
return CURRENT_VERSION.isAbove(new MinecraftVersion(version));
}

public static boolean isAtOrAbove(String version) {
return CURRENT_VERSION.isAtOrAbove(new MinecraftVersion(version));
}

public static boolean isAtOrBelow(String version) {
return CURRENT_VERSION.isAtOrBelow(new MinecraftVersion(version));
}

public static boolean isBelow(String version) {
return CURRENT_VERSION.isBelow(new MinecraftVersion(version));
}

private final int major;
private final int minor;
private final int patch;

public MinecraftVersion(String version) {
Matcher matcher = VERSION_PATTERN.matcher(version);

if (!matcher.find()) {
throw new IllegalArgumentException("can't parse minecraft version: " + version);
}

this.major = Integer.parseInt(matcher.group("major"));
this.minor = Integer.parseInt(matcher.group("minor"));

String patch = matcher.group("patch");
if (patch != null) {
this.patch = Integer.parseInt(patch);
} else {
this.patch = 0;
}
}

public int major() {
return this.major;
}

public int minor() {
return this.minor;
}

public int patch() {
return this.patch;
}

public boolean isAbove(MinecraftVersion version) {
return this.compareTo(version) > 0;
}

public boolean isAtOrAbove(MinecraftVersion version) {
return this.compareTo(version) >= 0;
}

public static int revisionNumber() {
return REVISION_NUMBER;
public boolean isAtOrBelow(MinecraftVersion version) {
return this.compareTo(version) <= 0;
}

public boolean isBelow(MinecraftVersion version) {
return this.compareTo(version) < 0;
}

@Override
public int compareTo(MinecraftVersion other) {
int major = Integer.compare(this.major, other.major);
if (major != 0) {
return major;
}

int minor = Integer.compare(this.minor, other.minor);
if (minor != 0) {
return minor;
}

return Integer.compare(this.patch, other.patch);
}

@Override
public int hashCode() {
return Objects.hash(major, minor, patch);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MinecraftVersion)) {
return false;
}
MinecraftVersion other = (MinecraftVersion) obj;
return major == other.major && minor == other.minor && patch == other.patch;
}

private MinecraftVersion() {
@Override
public String toString() {
return String.format("%s.%s.%s", this.major, this.minor, this.patch);
}
}
10 changes: 5 additions & 5 deletions orebfuscator-nms/orebfuscator-nms-v1_20_R4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.5-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
Expand Down Expand Up @@ -54,9 +54,9 @@
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<srgIn>org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedDependencies>org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
Expand All @@ -69,8 +69,8 @@
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
<srgIn>org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ public final class ChunkCapabilities {
// hasDirectPaletteZeroLength < 1.13
// hasLight < 1.14

private static final boolean hasChunkPosFieldUnloadPacket = MinecraftVersion.minorVersion() > 20 ||
(MinecraftVersion.minorVersion() == 20 && MinecraftVersion.revisionNumber() >= 2);
private static final boolean hasClientboundLevelChunkPacketData = MinecraftVersion.minorVersion() >= 18;
private static final boolean hasBiomePalettedContainer = MinecraftVersion.minorVersion() >= 18;
private static final boolean hasSingleValuePalette = MinecraftVersion.minorVersion() >= 18;
private static final boolean hasHeightBitMask = MinecraftVersion.minorVersion() <= 17;
private static final boolean hasDynamicHeight = MinecraftVersion.minorVersion() >= 17;
private static final boolean hasSimpleVarBitBuffer = MinecraftVersion.minorVersion() >= 16;
private static final boolean hasBlockCount = MinecraftVersion.minorVersion() >= 14;
private static final boolean hasDirectPaletteZeroLength = MinecraftVersion.minorVersion() < 13;
private static final boolean hasLightArray = MinecraftVersion.minorVersion() < 14;
private static final boolean hasChunkPosFieldUnloadPacket = MinecraftVersion.isAtOrAbove("1.20.2");
private static final boolean hasClientboundLevelChunkPacketData = MinecraftVersion.isAtOrAbove("1.18");
private static final boolean hasBiomePalettedContainer = MinecraftVersion.isAtOrAbove("1.18");
private static final boolean hasSingleValuePalette = MinecraftVersion.isAtOrAbove("1.18");
private static final boolean hasHeightBitMask = MinecraftVersion.isAtOrBelow("1.17");
private static final boolean hasDynamicHeight = MinecraftVersion.isAtOrAbove("1.17");
private static final boolean hasSimpleVarBitBuffer = MinecraftVersion.isAtOrAbove("1.16");
private static final boolean hasBlockCount = MinecraftVersion.isAtOrAbove("1.14");
private static final boolean hasDirectPaletteZeroLength = MinecraftVersion.isBelow("1.13");
private static final boolean hasLightArray = MinecraftVersion.isBelow("1.14");

private ChunkCapabilities() {
}
Expand Down

0 comments on commit ee5e1a8

Please sign in to comment.