Skip to content

Commit ee5e1a8

Browse files
authored
fix: removal of bukkit package remapping in paper (#370)
* fix: removale of bukkit package remapping in paper * fix: github ci
1 parent 5c50f4f commit ee5e1a8

4 files changed

Lines changed: 167 additions & 36 deletions

File tree

.github/workflows/buildtools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ checkVersion "1.19.4" "17"
4444
checkVersion "1.20.1" "17"
4545
checkVersion "1.20.2" "17"
4646
checkVersion "1.20.4" "17"
47-
checkVersion "1.20.5" "21"
47+
checkVersion "1.20.6" "21"
Lines changed: 151 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,181 @@
11
package net.imprex.orebfuscator.util;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Objects;
36
import java.util.regex.Matcher;
47
import java.util.regex.Pattern;
58

69
import org.bukkit.Bukkit;
710

8-
public final class MinecraftVersion {
11+
public final class MinecraftVersion implements Comparable<MinecraftVersion> {
912

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

12-
private static final String NMS_VERSION;
13-
private static final int MAJOR_VERSION;
14-
private static final int MINOR_VERSION;
15-
private static final int REVISION_NUMBER;
15+
private static final List<NmsMapping> MAPPINGS = new ArrayList<>();
16+
17+
static {
18+
MAPPINGS.add(new NmsMapping("1.20.5", "v1_20_R4"));
19+
}
20+
21+
public static String get(MinecraftVersion version) {
22+
for (NmsMapping mapping : MAPPINGS) {
23+
if (version.isAtOrAbove(mapping.version)) {
24+
if (mapping.version.minor() != version.minor()) {
25+
OFCLogger.warn(String.format("Using nms mapping with mismatched minor versions: %s - %s",
26+
mapping.version, version));
27+
}
28+
29+
return mapping.nmsVersion;
30+
}
31+
}
32+
33+
throw new RuntimeException("Can't get nms package version for minecraft version: " + version);
34+
}
35+
36+
private final MinecraftVersion version;
37+
private final String nmsVersion;
38+
39+
public NmsMapping(String version, String nmsVersion) {
40+
this.version = new MinecraftVersion(version);
41+
this.nmsVersion = nmsVersion;
42+
}
43+
}
44+
45+
private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(?:\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?");
46+
private static final Pattern PACKAGE_PATTERN = Pattern.compile("org\\.bukkit\\.craftbukkit\\.(v\\d+_\\d+_R\\d+)");
47+
48+
private static final MinecraftVersion CURRENT_VERSION = new MinecraftVersion(Bukkit.getBukkitVersion());
49+
50+
private static String NMS_VERSION;
1651

1752
static {
1853
String craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();
19-
Matcher matcher = VERSION_PATTERN.matcher(craftBukkitPackage);
54+
Matcher matcher = PACKAGE_PATTERN.matcher(craftBukkitPackage);
2055

21-
if (!matcher.find()) {
22-
throw new RuntimeException("Can't parse craftbukkit package version " + craftBukkitPackage);
56+
if (matcher.find()) {
57+
NMS_VERSION = matcher.group(1);
58+
} else {
59+
NMS_VERSION = NmsMapping.get(CURRENT_VERSION);
2360
}
24-
25-
NMS_VERSION = matcher.group(1);
26-
MAJOR_VERSION = Integer.parseInt(matcher.group(2));
27-
MINOR_VERSION = Integer.parseInt(matcher.group(3));
28-
REVISION_NUMBER = Integer.parseInt(matcher.group(4));
2961
}
3062

3163
public static String nmsVersion() {
3264
return NMS_VERSION;
3365
}
3466

3567
public static int majorVersion() {
36-
return MAJOR_VERSION;
68+
return CURRENT_VERSION.major;
3769
}
3870

3971
public static int minorVersion() {
40-
return MINOR_VERSION;
72+
return CURRENT_VERSION.minor;
73+
}
74+
75+
public static int patchVersion() {
76+
return CURRENT_VERSION.patch;
77+
}
78+
79+
public static boolean isAbove(String version) {
80+
return CURRENT_VERSION.isAbove(new MinecraftVersion(version));
81+
}
82+
83+
public static boolean isAtOrAbove(String version) {
84+
return CURRENT_VERSION.isAtOrAbove(new MinecraftVersion(version));
85+
}
86+
87+
public static boolean isAtOrBelow(String version) {
88+
return CURRENT_VERSION.isAtOrBelow(new MinecraftVersion(version));
89+
}
90+
91+
public static boolean isBelow(String version) {
92+
return CURRENT_VERSION.isBelow(new MinecraftVersion(version));
93+
}
94+
95+
private final int major;
96+
private final int minor;
97+
private final int patch;
98+
99+
public MinecraftVersion(String version) {
100+
Matcher matcher = VERSION_PATTERN.matcher(version);
101+
102+
if (!matcher.find()) {
103+
throw new IllegalArgumentException("can't parse minecraft version: " + version);
104+
}
105+
106+
this.major = Integer.parseInt(matcher.group("major"));
107+
this.minor = Integer.parseInt(matcher.group("minor"));
108+
109+
String patch = matcher.group("patch");
110+
if (patch != null) {
111+
this.patch = Integer.parseInt(patch);
112+
} else {
113+
this.patch = 0;
114+
}
115+
}
116+
117+
public int major() {
118+
return this.major;
119+
}
120+
121+
public int minor() {
122+
return this.minor;
123+
}
124+
125+
public int patch() {
126+
return this.patch;
127+
}
128+
129+
public boolean isAbove(MinecraftVersion version) {
130+
return this.compareTo(version) > 0;
131+
}
132+
133+
public boolean isAtOrAbove(MinecraftVersion version) {
134+
return this.compareTo(version) >= 0;
41135
}
42136

43-
public static int revisionNumber() {
44-
return REVISION_NUMBER;
137+
public boolean isAtOrBelow(MinecraftVersion version) {
138+
return this.compareTo(version) <= 0;
139+
}
140+
141+
public boolean isBelow(MinecraftVersion version) {
142+
return this.compareTo(version) < 0;
143+
}
144+
145+
@Override
146+
public int compareTo(MinecraftVersion other) {
147+
int major = Integer.compare(this.major, other.major);
148+
if (major != 0) {
149+
return major;
150+
}
151+
152+
int minor = Integer.compare(this.minor, other.minor);
153+
if (minor != 0) {
154+
return minor;
155+
}
156+
157+
return Integer.compare(this.patch, other.patch);
158+
}
159+
160+
@Override
161+
public int hashCode() {
162+
return Objects.hash(major, minor, patch);
163+
}
164+
165+
@Override
166+
public boolean equals(Object obj) {
167+
if (this == obj) {
168+
return true;
169+
}
170+
if (!(obj instanceof MinecraftVersion)) {
171+
return false;
172+
}
173+
MinecraftVersion other = (MinecraftVersion) obj;
174+
return major == other.major && minor == other.minor && patch == other.patch;
45175
}
46176

47-
private MinecraftVersion() {
177+
@Override
178+
public String toString() {
179+
return String.format("%s.%s.%s", this.major, this.minor, this.patch);
48180
}
49181
}

orebfuscator-nms/orebfuscator-nms-v1_20_R4/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.spigotmc</groupId>
2222
<artifactId>spigot</artifactId>
23-
<version>1.20.5-R0.1-SNAPSHOT</version>
23+
<version>1.20.6-R0.1-SNAPSHOT</version>
2424
<classifier>remapped-mojang</classifier>
2525
<scope>provided</scope>
2626
</dependency>
@@ -54,9 +54,9 @@
5454
</goals>
5555
<id>remap-obf</id>
5656
<configuration>
57-
<srgIn>org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
57+
<srgIn>org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
5858
<reverse>true</reverse>
59-
<remappedDependencies>org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
59+
<remappedDependencies>org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
6060
<remappedArtifactAttached>true</remappedArtifactAttached>
6161
<remappedClassifierName>remapped-obf</remappedClassifierName>
6262
</configuration>
@@ -69,8 +69,8 @@
6969
<id>remap-spigot</id>
7070
<configuration>
7171
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
72-
<srgIn>org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
73-
<remappedDependencies>org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
72+
<srgIn>org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
73+
<remappedDependencies>org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
7474
</configuration>
7575
</execution>
7676
</executions>

orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/ChunkCapabilities.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ public final class ChunkCapabilities {
1515
// hasDirectPaletteZeroLength < 1.13
1616
// hasLight < 1.14
1717

18-
private static final boolean hasChunkPosFieldUnloadPacket = MinecraftVersion.minorVersion() > 20 ||
19-
(MinecraftVersion.minorVersion() == 20 && MinecraftVersion.revisionNumber() >= 2);
20-
private static final boolean hasClientboundLevelChunkPacketData = MinecraftVersion.minorVersion() >= 18;
21-
private static final boolean hasBiomePalettedContainer = MinecraftVersion.minorVersion() >= 18;
22-
private static final boolean hasSingleValuePalette = MinecraftVersion.minorVersion() >= 18;
23-
private static final boolean hasHeightBitMask = MinecraftVersion.minorVersion() <= 17;
24-
private static final boolean hasDynamicHeight = MinecraftVersion.minorVersion() >= 17;
25-
private static final boolean hasSimpleVarBitBuffer = MinecraftVersion.minorVersion() >= 16;
26-
private static final boolean hasBlockCount = MinecraftVersion.minorVersion() >= 14;
27-
private static final boolean hasDirectPaletteZeroLength = MinecraftVersion.minorVersion() < 13;
28-
private static final boolean hasLightArray = MinecraftVersion.minorVersion() < 14;
18+
private static final boolean hasChunkPosFieldUnloadPacket = MinecraftVersion.isAtOrAbove("1.20.2");
19+
private static final boolean hasClientboundLevelChunkPacketData = MinecraftVersion.isAtOrAbove("1.18");
20+
private static final boolean hasBiomePalettedContainer = MinecraftVersion.isAtOrAbove("1.18");
21+
private static final boolean hasSingleValuePalette = MinecraftVersion.isAtOrAbove("1.18");
22+
private static final boolean hasHeightBitMask = MinecraftVersion.isAtOrBelow("1.17");
23+
private static final boolean hasDynamicHeight = MinecraftVersion.isAtOrAbove("1.17");
24+
private static final boolean hasSimpleVarBitBuffer = MinecraftVersion.isAtOrAbove("1.16");
25+
private static final boolean hasBlockCount = MinecraftVersion.isAtOrAbove("1.14");
26+
private static final boolean hasDirectPaletteZeroLength = MinecraftVersion.isBelow("1.13");
27+
private static final boolean hasLightArray = MinecraftVersion.isBelow("1.14");
2928

3029
private ChunkCapabilities() {
3130
}

0 commit comments

Comments
 (0)