- properly fix IllegalArgumentException in /paper mobcaps command

- fix IllegalArgumentException in `/paper playermobcaps` command
- add missing Validate calls to CraftServer#getSpawnLimit(SpawnCategory)
This commit is contained in:
Jason Penilla 2022-02-12 12:44:54 -07:00
parent e6898ff61e
commit a8f2d67491
No known key found for this signature in database
GPG Key ID: 0E75A301420E48F8
4 changed files with 66 additions and 13 deletions

View File

@ -10,7 +10,7 @@ Also has a hover text on each mob category listing what entity types are
in said category in said category
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f2b7dd452 100644 index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..be1da6ebf8c1468182cbb92a16e4866bfb2ecfc3 100644
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java --- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java +++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -3,6 +3,7 @@ package com.destroystokyo.paper; @@ -3,6 +3,7 @@ package com.destroystokyo.paper;
@ -213,7 +213,7 @@ index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f
+ sender.sendMessage(Component.join(JoinConfiguration.noSeparators(), Component.text("Mobcaps for player: "), Component.text(player.getName(), NamedTextColor.GREEN))); + sender.sendMessage(Component.join(JoinConfiguration.noSeparators(), Component.text("Mobcaps for player: "), Component.text(player.getName(), NamedTextColor.GREEN)));
+ sender.sendMessage(this.buildMobcapsComponent( + sender.sendMessage(this.buildMobcapsComponent(
+ category -> level.chunkSource.chunkMap.getMobCountNear(serverPlayer, category), + category -> level.chunkSource.chunkMap.getMobCountNear(serverPlayer, category),
+ category -> level.getWorld().getSpawnLimit(org.bukkit.craftbukkit.util.CraftSpawnCategory.toBukkit(category)) + category -> level.getWorld().getSpawnLimitUnsafe(org.bukkit.craftbukkit.util.CraftSpawnCategory.toBukkit(category))
+ )); + ));
+ } + }
+ +
@ -272,19 +272,16 @@ index f436ab35798c9b6e6cb2eb60d2c02cbf9b742e69..8934c9f2d578932aae43ea3da7894f2f
List<org.bukkit.World> worlds; List<org.bukkit.World> worlds;
if (args.length < 2 || args[1].equals("*")) { if (args.length < 2 || args[1].equals("*")) {
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index 8e63d93a574f2c37094770099ea8e1f45cde3db5..ded0c79bcf1f78c6858270c6787aa5baced856b6 100644 index 8e63d93a574f2c37094770099ea8e1f45cde3db5..6dba117b4f5dc6c4e078a32037a4026b45bf2176 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -191,6 +191,19 @@ public final class NaturalSpawner { @@ -191,6 +191,16 @@ public final class NaturalSpawner {
world.getProfiler().pop(); world.getProfiler().pop();
} }
+ // Paper start + // Paper start
+ public static int globalLimitForCategory(final ServerLevel level, final MobCategory category, final int spawnableChunkCount) { + public static int globalLimitForCategory(final ServerLevel level, final MobCategory category, final int spawnableChunkCount) {
+ if (category == MobCategory.MISC) { + final int categoryLimit = level.getWorld().getSpawnLimitUnsafe(CraftSpawnCategory.toBukkit(category));
+ return -1;
+ }
+ final int categoryLimit = level.getWorld().getSpawnLimit(CraftSpawnCategory.toBukkit(category));
+ if (categoryLimit < 1) { + if (categoryLimit < 1) {
+ return categoryLimit; + return categoryLimit;
+ } + }
@ -295,6 +292,42 @@ index 8e63d93a574f2c37094770099ea8e1f45cde3db5..ded0c79bcf1f78c6858270c6787aa5ba
// Paper start - add parameters and int ret type // Paper start - add parameters and int ret type
public static void spawnCategoryForChunk(MobCategory group, ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnPredicate checker, NaturalSpawner.AfterSpawnCallback runner) { public static void spawnCategoryForChunk(MobCategory group, ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnPredicate checker, NaturalSpawner.AfterSpawnCallback runner) {
spawnCategoryForChunk(group, world, chunk, checker, runner, Integer.MAX_VALUE, null); spawnCategoryForChunk(group, world, chunk, checker, runner, Integer.MAX_VALUE, null);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index e0e7fb4cc5516d8712f384fb5cb4d22c5bdceff5..51f537069c195edf1b7a60f233997d3cc03d304a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2145,6 +2145,11 @@ public final class CraftServer implements Server {
@Override
public int getSpawnLimit(SpawnCategory spawnCategory) {
+ // Paper start
+ return this.getSpawnLimitUnsafe(spawnCategory);
+ }
+ public int getSpawnLimitUnsafe(final SpawnCategory spawnCategory) {
+ // Paper end
return this.spawnCategoryLimit.getOrDefault(spawnCategory, -1);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 004af6a256e76389234723e0f79634f5a8e26c23..9dd77d989fa6e33ce55525b88fb21a863e156810 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1707,9 +1707,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Validate.notNull(spawnCategory, "SpawnCategory cannot be null");
Validate.isTrue(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory." + spawnCategory + " are not supported.");
+ // Paper start
+ return this.getSpawnLimitUnsafe(spawnCategory);
+ }
+ public final int getSpawnLimitUnsafe(final SpawnCategory spawnCategory) {
int limit = this.spawnCategoryLimit.getOrDefault(spawnCategory, -1);
if (limit < 0) {
- limit = this.server.getSpawnLimit(spawnCategory);
+ limit = this.server.getSpawnLimitUnsafe(spawnCategory);
+ // Paper end
}
return limit;
}
diff --git a/src/test/java/io/papermc/paper/PaperCommandTest.java b/src/test/java/io/papermc/paper/PaperCommandTest.java diff --git a/src/test/java/io/papermc/paper/PaperCommandTest.java b/src/test/java/io/papermc/paper/PaperCommandTest.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..4b5b368ef17bdb90f50e6ccc1f814cf93c7c0590 index 0000000000000000000000000000000000000000..4b5b368ef17bdb90f50e6ccc1f814cf93c7c0590

View File

@ -287,10 +287,10 @@ index 742d4645a6d22d10bc2833e3b742a6bc653d473d..7dda99a5464816f1488fb110da587f12
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 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
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index ded0c79bcf1f78c6858270c6787aa5baced856b6..96fe666d55ec98724ae67704026013ab1288fa99 100644 index 6dba117b4f5dc6c4e078a32037a4026b45bf2176..515e58e3db223fbdc01ca87607aca234c7010d51 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -262,7 +262,7 @@ public final class NaturalSpawner { @@ -259,7 +259,7 @@ public final class NaturalSpawner {
blockposition_mutableblockposition.set(l, i, i1); blockposition_mutableblockposition.set(l, i, i1);
double d0 = (double) l + 0.5D; double d0 = (double) l + 0.5D;
double d1 = (double) i1 + 0.5D; double d1 = (double) i1 + 0.5D;
@ -299,7 +299,7 @@ index ded0c79bcf1f78c6858270c6787aa5baced856b6..96fe666d55ec98724ae67704026013ab
if (entityhuman != null) { if (entityhuman != null) {
double d2 = entityhuman.distanceToSqr(d0, (double) i, d1); double d2 = entityhuman.distanceToSqr(d0, (double) i, d1);
@@ -335,7 +335,7 @@ public final class NaturalSpawner { @@ -332,7 +332,7 @@ public final class NaturalSpawner {
} }
private static boolean isRightDistanceToPlayerAndSpawnPoint(ServerLevel world, ChunkAccess chunk, BlockPos.MutableBlockPos pos, double squaredDistance) { private static boolean isRightDistanceToPlayerAndSpawnPoint(ServerLevel world, ChunkAccess chunk, BlockPos.MutableBlockPos pos, double squaredDistance) {

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Allow delegation to vanilla chunk gen
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index e0e7fb4cc5516d8712f384fb5cb4d22c5bdceff5..077998f9a40b43d881d4fbfb8f21fb579855dc53 100644 index 51f537069c195edf1b7a60f233997d3cc03d304a..f81638de69a0f6935291062484244bf62e3e8a9e 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2308,6 +2308,107 @@ public final class CraftServer implements Server { @@ -2313,6 +2313,107 @@ public final class CraftServer implements Server {
return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), world); // Paper - Anti-Xray - Add parameters return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), world); // Paper - Anti-Xray - Add parameters
} }

View File

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