Fix some API and commands usage of inactive chunks (#2457)
* /paper entity will no longer report entities in inactive chunks * World#getEntityCount and World#getChunkCount will report only in active chunks
This commit is contained in:
@@ -7,7 +7,7 @@ Provides counts without the ineffeciency of using .getEntities().size()
|
||||
which creates copy of the collections.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
index 9b8fb80a4..b07e3fe26 100644
|
||||
index 13f2dbdd6..2087a38a2 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -0,0 +0,0 @@ public class CraftWorld implements World {
|
||||
@@ -15,9 +15,14 @@ index 9b8fb80a4..b07e3fe26 100644
|
||||
private int ambientSpawn = -1;
|
||||
|
||||
+ // Paper start - Provide fast information methods
|
||||
+ // TODO review these changes
|
||||
+ public int getEntityCount() {
|
||||
+ return world.entitiesById.size();
|
||||
+ int ret = 0;
|
||||
+ for (net.minecraft.server.Entity entity : world.entitiesById.values()) {
|
||||
+ if (entity.isChunkLoaded()) {
|
||||
+ ++ret;
|
||||
+ }
|
||||
+ }
|
||||
+ return ret;
|
||||
+ }
|
||||
+ public int getTileEntityCount() {
|
||||
+ // We don't use the full world tile entity list, so we must iterate chunks
|
||||
@@ -36,7 +41,15 @@ index 9b8fb80a4..b07e3fe26 100644
|
||||
+ return world.tileEntityListTick.size();
|
||||
+ }
|
||||
+ public int getChunkCount() {
|
||||
+ return world.getChunkProvider().playerChunkMap.visibleChunks.size();
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ for (PlayerChunk chunkHolder : world.getChunkProvider().playerChunkMap.visibleChunks.values()) {
|
||||
+ if (chunkHolder.getChunk() != null) {
|
||||
+ ++ret;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+ }
|
||||
+ public int getPlayerCount() {
|
||||
+ return world.players.size();
|
||||
|
||||
Reference in New Issue
Block a user