Skip to content

Commit bc4e2c5

Browse files
authored
fix: update to changes in 1.21 class paths (#4546)
1 parent c46b4dd commit bc4e2c5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,9 @@ public void setGenerator(final @NonNull String worldName) {
11711171
@Override
11721172
public @NonNull String serverNativePackage() {
11731173
final String name = Bukkit.getServer().getClass().getPackage().getName();
1174-
return name.substring(name.lastIndexOf('.') + 1);
1174+
String ver = name.substring(name.lastIndexOf('.') + 1);
1175+
// org.bukkit.craftbukkit is no longer suffixed by a version
1176+
return ver.equals("craftbukkit") ? "" : ver;
11751177
}
11761178

11771179
@Override

Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ public SingleWorldListener() throws Exception {
4949
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
5050
} catch (NoSuchMethodException ignored) {
5151
try {
52-
ReflectionUtils.RefClass classChunkStatus = getRefClass("net.minecraft.world.level.chunk.ChunkStatus");
52+
String chunkStatus = PlotSquared.platform().serverVersion()[1] < 21
53+
? "net.minecraft.world.level.chunk" + ".ChunkStatus"
54+
: "net.minecraft.world.level.chunk.status.ChunkStatus";
55+
ReflectionUtils.RefClass classChunkStatus = getRefClass(chunkStatus);
5356
this.objChunkStatusFull = classChunkStatus.getRealClass().getField("n").get(null);
54-
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle", classChunkStatus.getRealClass()).getRealMethod();
57+
this.methodGetHandleChunk = classCraftChunk
58+
.getMethod("getHandle", classChunkStatus.getRealClass())
59+
.getRealMethod();
5560
} catch (NoSuchMethodException ex) {
5661
throw new RuntimeException(ex);
5762
}

Core/src/main/java/com/plotsquared/core/PlotSquared.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ public PlotSquared(
206206
GlobalFlagContainer.setup();
207207

208208
try {
209-
new ReflectionUtils(this.platform.serverNativePackage());
209+
String ver = this.platform.serverNativePackage();
210+
new ReflectionUtils(ver.isEmpty() ? null : ver);
210211
try {
211212
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
212213
this.jarFile = new File(
213214
URI.create(
214215
logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
215216
.getPath());
216217
} catch (URISyntaxException | SecurityException e) {
217-
e.printStackTrace();
218+
LOGGER.error(e);
218219
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
219220
if (!this.jarFile.exists()) {
220221
this.jarFile = new File(
@@ -238,7 +239,7 @@ public PlotSquared(
238239
copyFile("skyblock.template", Settings.Paths.TEMPLATES);
239240
showDebug();
240241
} catch (Throwable e) {
241-
e.printStackTrace();
242+
LOGGER.error(e);
242243
}
243244
}
244245

0 commit comments

Comments
 (0)