Skip to content

Commit a8f2d67

Browse files
committed
- properly fix IllegalArgumentException in /paper mobcaps command
- fix IllegalArgumentException in `/paper playermobcaps` command - add missing Validate calls to CraftServer#getSpawnLimit(SpawnCategory)
1 parent e6898ff commit a8f2d67

4 files changed

+66
-13
lines changed

patches/server/0741-Add-paper-mobcaps-and-paper-playermobcaps.patch

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Also has a hover text on each mob category listing what entity types are
1010
in said category
1111

1212
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
13-
index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f2b7dd452 100644
13+
index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..be1da6ebf8c1468182cbb92a16e4866bfb2ecfc3 100644
1414
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
1515
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
1616
@@ -3,6 +3,7 @@ package com.destroystokyo.paper;
@@ -213,7 +213,7 @@ index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f
213213
+ sender.sendMessage(Component.join(JoinConfiguration.noSeparators(), Component.text("Mobcaps for player: "), Component.text(player.getName(), NamedTextColor.GREEN)));
214214
+ sender.sendMessage(this.buildMobcapsComponent(
215215
+ category -> level.chunkSource.chunkMap.getMobCountNear(serverPlayer, category),
216-
+ category -> level.getWorld().getSpawnLimit(org.bukkit.craftbukkit.util.CraftSpawnCategory.toBukkit(category))
216+
+ category -> level.getWorld().getSpawnLimitUnsafe(org.bukkit.craftbukkit.util.CraftSpawnCategory.toBukkit(category))
217217
+ ));
218218
+ }
219219
+
@@ -272,19 +272,16 @@ index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f
272272
List<org.bukkit.World> worlds;
273273
if (args.length < 2 || args[1].equals("*")) {
274274
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
275-
index 8e63d93a574f2c37094770099ea8e1f45cde3db5..ded0c79bcf1f78c6858270c6787aa5baced856b6 100644
275+
index 8e63d93a574f2c37094770099ea8e1f45cde3db5..6dba117b4f5dc6c4e078a32037a4026b45bf2176 100644
276276
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
277277
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
278-
@@ -191,6 +191,19 @@ public final class NaturalSpawner {
278+
@@ -191,6 +191,16 @@ public final class NaturalSpawner {
279279
world.getProfiler().pop();
280280
}
281281

282282
+ // Paper start
283283
+ public static int globalLimitForCategory(final ServerLevel level, final MobCategory category, final int spawnableChunkCount) {
284-
+ if (category == MobCategory.MISC) {
285-
+ return -1;
286-
+ }
287-
+ final int categoryLimit = level.getWorld().getSpawnLimit(CraftSpawnCategory.toBukkit(category));
284+
+ final int categoryLimit = level.getWorld().getSpawnLimitUnsafe(CraftSpawnCategory.toBukkit(category));
288285
+ if (categoryLimit < 1) {
289286
+ return categoryLimit;
290287
+ }
@@ -295,6 +292,42 @@ index 8e63d93a574f2c37094770099ea8e1f45cde3db5..ded0c79bcf1f78c6858270c6787aa5ba
295292
// Paper start - add parameters and int ret type
296293
public static void spawnCategoryForChunk(MobCategory group, ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnPredicate checker, NaturalSpawner.AfterSpawnCallback runner) {
297294
spawnCategoryForChunk(group, world, chunk, checker, runner, Integer.MAX_VALUE, null);
295+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
296+
index e0e7fb4cc5516d8712f384fb5cb4d22c5bdceff5..51f537069c195edf1b7a60f233997d3cc03d304a 100644
297+
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
298+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
299+
@@ -2145,6 +2145,11 @@ public final class CraftServer implements Server {
300+
301+
@Override
302+
public int getSpawnLimit(SpawnCategory spawnCategory) {
303+
+ // Paper start
304+
+ return this.getSpawnLimitUnsafe(spawnCategory);
305+
+ }
306+
+ public int getSpawnLimitUnsafe(final SpawnCategory spawnCategory) {
307+
+ // Paper end
308+
return this.spawnCategoryLimit.getOrDefault(spawnCategory, -1);
309+
}
310+
311+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
312+
index 004af6a256e76389234723e0f79634f5a8e26c23..9dd77d989fa6e33ce55525b88fb21a863e156810 100644
313+
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
314+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
315+
@@ -1707,9 +1707,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
316+
Validate.notNull(spawnCategory, "SpawnCategory cannot be null");
317+
Validate.isTrue(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory." + spawnCategory + " are not supported.");
318+
319+
+ // Paper start
320+
+ return this.getSpawnLimitUnsafe(spawnCategory);
321+
+ }
322+
+ public final int getSpawnLimitUnsafe(final SpawnCategory spawnCategory) {
323+
int limit = this.spawnCategoryLimit.getOrDefault(spawnCategory, -1);
324+
if (limit < 0) {
325+
- limit = this.server.getSpawnLimit(spawnCategory);
326+
+ limit = this.server.getSpawnLimitUnsafe(spawnCategory);
327+
+ // Paper end
328+
}
329+
return limit;
330+
}
298331
diff --git a/src/test/java/io/papermc/paper/PaperCommandTest.java b/src/test/java/io/papermc/paper/PaperCommandTest.java
299332
new file mode 100644
300333
index 0000000000000000000000000000000000000000..4b5b368ef17bdb90f50e6ccc1f814cf93c7c0590

patches/server/0772-Optimise-nearby-player-lookups.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ index 742d4645a6d22d10bc2833e3b742a6bc653d473d..7dda99a5464816f1488fb110da587f12
287287
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, final DimensionType dimensionmanager, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.concurrent.Executor executor) { // Paper - Async-Anti-Xray - Pass executor
288288
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
289289
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
290-
index ded0c79bcf1f78c6858270c6787aa5baced856b6..96fe666d55ec98724ae67704026013ab1288fa99 100644
290+
index 6dba117b4f5dc6c4e078a32037a4026b45bf2176..515e58e3db223fbdc01ca87607aca234c7010d51 100644
291291
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
292292
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
293-
@@ -262,7 +262,7 @@ public final class NaturalSpawner {
293+
@@ -259,7 +259,7 @@ public final class NaturalSpawner {
294294
blockposition_mutableblockposition.set(l, i, i1);
295295
double d0 = (double) l + 0.5D;
296296
double d1 = (double) i1 + 0.5D;
@@ -299,7 +299,7 @@ index ded0c79bcf1f78c6858270c6787aa5baced856b6..96fe666d55ec98724ae67704026013ab
299299

300300
if (entityhuman != null) {
301301
double d2 = entityhuman.distanceToSqr(d0, (double) i, d1);
302-
@@ -335,7 +335,7 @@ public final class NaturalSpawner {
302+
@@ -332,7 +332,7 @@ public final class NaturalSpawner {
303303
}
304304

305305
private static boolean isRightDistanceToPlayerAndSpawnPoint(ServerLevel world, ChunkAccess chunk, BlockPos.MutableBlockPos pos, double squaredDistance) {

patches/server/0817-Allow-delegation-to-vanilla-chunk-gen.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] Allow delegation to vanilla chunk gen
55

66

77
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
8-
index e0e7fb4cc5516d8712f384fb5cb4d22c5bdceff5..077998f9a40b43d881d4fbfb8f21fb579855dc53 100644
8+
index 51f537069c195edf1b7a60f233997d3cc03d304a..f81638de69a0f6935291062484244bf62e3e8a9e 100644
99
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
1010
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
11-
@@ -2308,6 +2308,107 @@ public final class CraftServer implements Server {
11+
@@ -2313,6 +2313,107 @@ public final class CraftServer implements Server {
1212
return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), world); // Paper - Anti-Xray - Add parameters
1313
}
1414

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
3+
Date: Sat, 12 Feb 2022 12:40:50 -0700
4+
Subject: [PATCH] Add missing Validate calls to CraftServer#getSpawnLimit
5+
6+
Copies appropriate checks from CraftWorld#getSpawnLimit
7+
8+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
9+
index ff5c06e261945bbd7730662cdb79167f160c661e..f0629cac377b29246e990a01d60601270cbd77bd 100644
10+
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
11+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
12+
@@ -2153,6 +2153,8 @@ public final class CraftServer implements Server {
13+
@Override
14+
public int getSpawnLimit(SpawnCategory spawnCategory) {
15+
// Paper start
16+
+ Validate.notNull(spawnCategory, "SpawnCategory cannot be null");
17+
+ Validate.isTrue(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory." + spawnCategory + " does not have a spawn limit.");
18+
return this.getSpawnLimitUnsafe(spawnCategory);
19+
}
20+
public int getSpawnLimitUnsafe(final SpawnCategory spawnCategory) {

0 commit comments

Comments
 (0)