Skip to content

Commit a322c10

Browse files
committed
fix: use Bukkit API instead of NMS getAllLevels() for world iteration
MinecraftServer.getAllLevels() obfuscated method name changed in 1.21.11. Switch to using Bukkit.getWorlds() with CraftWorld.getHandle() which is more stable across version updates.
1 parent b83fcbf commit a322c10

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cf.catworlds.dynamicspigotsetting.utils;
22

3-
import net.minecraft.server.MinecraftServer;
43
import org.bukkit.Bukkit;
4+
import org.bukkit.World;
5+
import org.bukkit.craftbukkit.CraftWorld;
56

67
public class ServerHelper {
78

@@ -11,22 +12,28 @@ static public double getTPS() {
1112

1213
@SuppressWarnings("deprecation")
1314
static public double getItemMerge() {
14-
return MinecraftServer.getServer().getAllLevels().iterator().next().spigotConfig.itemMerge;
15+
World world = Bukkit.getWorlds().get(0);
16+
return ((CraftWorld) world).getHandle().spigotConfig.itemMerge;
1517
}
1618

1719
@SuppressWarnings("deprecation")
1820
static public void setItemMerge(double radius) {
19-
MinecraftServer.getServer().getAllLevels().forEach((ws) -> ws.spigotConfig.itemMerge = radius);
21+
for (World world : Bukkit.getWorlds()) {
22+
((CraftWorld) world).getHandle().spigotConfig.itemMerge = radius;
23+
}
2024
}
2125

2226
@SuppressWarnings("deprecation")
2327
static public double getExpMerge() {
24-
return MinecraftServer.getServer().getAllLevels().iterator().next().spigotConfig.expMerge;
28+
World world = Bukkit.getWorlds().get(0);
29+
return ((CraftWorld) world).getHandle().spigotConfig.expMerge;
2530
}
2631

2732
@SuppressWarnings("deprecation")
2833
static public void setExpMerge(double radius) {
29-
MinecraftServer.getServer().getAllLevels().forEach((ws) -> ws.spigotConfig.expMerge = radius);
34+
for (World world : Bukkit.getWorlds()) {
35+
((CraftWorld) world).getHandle().spigotConfig.expMerge = radius;
36+
}
3037
}
3138

3239
}

0 commit comments

Comments
 (0)