Indicate ticking status in entity list command (#2856)

This commit is contained in:
Spottedleaf 2020-03-18 05:38:24 -07:00
parent e106f34e74
commit 86437303b3
3 changed files with 52 additions and 19 deletions

View file

@ -6,20 +6,20 @@ Subject: [PATCH] Add MinecraftKey Information to Objects
Stores the reference to the objects respective MinecraftKey Stores the reference to the objects respective MinecraftKey
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 db899937be..eecf27370b 100644 index 3392ed13f..d2c325050 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
@@ -0,0 +0,0 @@ public class PaperCommand extends Command { @@ -0,0 +0,0 @@ public class PaperCommand extends Command {
if (!e.isChunkLoaded()) {
return; Collection<Entity> entities = world.entitiesById.values();
} entities.forEach(e -> {
- MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch - MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch
+ MinecraftKey key = e.getMinecraftKey(); + MinecraftKey key = e.getMinecraftKey();
MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap())); MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ()); ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ());
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 8789191fe6..7899fd6d88 100644 index 8789191fe..7899fd6d8 100644
--- a/src/main/java/net/minecraft/server/Entity.java --- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java
@@ -0,0 +0,0 @@ import org.bukkit.event.player.PlayerTeleportEvent; @@ -0,0 +0,0 @@ import org.bukkit.event.player.PlayerTeleportEvent;
@ -65,7 +65,7 @@ index 8789191fe6..7899fd6d88 100644
protected abstract void a(NBTTagCompound nbttagcompound); protected abstract void a(NBTTagCompound nbttagcompound);
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
index cbf0c2f25d..79f8549660 100644 index cbf0c2f25..79f854966 100644
--- a/src/main/java/net/minecraft/server/EntityTypes.java --- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java +++ b/src/main/java/net/minecraft/server/EntityTypes.java
@@ -0,0 +0,0 @@ public class EntityTypes<T extends Entity> { @@ -0,0 +0,0 @@ public class EntityTypes<T extends Entity> {
@ -78,7 +78,7 @@ index cbf0c2f25d..79f8549660 100644
} }
diff --git a/src/main/java/net/minecraft/server/KeyedObject.java b/src/main/java/net/minecraft/server/KeyedObject.java diff --git a/src/main/java/net/minecraft/server/KeyedObject.java b/src/main/java/net/minecraft/server/KeyedObject.java
new file mode 100644 new file mode 100644
index 0000000000..743142d030 index 000000000..743142d03
--- /dev/null --- /dev/null
+++ b/src/main/java/net/minecraft/server/KeyedObject.java +++ b/src/main/java/net/minecraft/server/KeyedObject.java
@@ -0,0 +0,0 @@ @@ -0,0 +0,0 @@
@ -92,7 +92,7 @@ index 0000000000..743142d030
+ } + }
+} +}
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index 40752f7617..9071bb7ece 100644 index 40752f761..9071bb7ec 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java --- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java +++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -0,0 +0,0 @@ import org.bukkit.inventory.InventoryHolder; @@ -0,0 +0,0 @@ import org.bukkit.inventory.InventoryHolder;

View file

@ -11,12 +11,12 @@ This will ensure that dead entities are skipped from iteration since
they shouldn't of been in the list in the first place. they shouldn't of been in the list in the first place.
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 eecf27370..d704fc79c 100644 index d2c325050..ec7c9ad4b 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
@@ -0,0 +0,0 @@ public class PaperCommand extends Command { @@ -0,0 +0,0 @@ public class PaperCommand extends Command {
return; Collection<Entity> entities = world.entitiesById.values();
} entities.forEach(e -> {
MinecraftKey key = e.getMinecraftKey(); MinecraftKey key = e.getMinecraftKey();
+ if (e.shouldBeRemoved) return; // Paper + if (e.shouldBeRemoved) return; // Paper

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Paper config files
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
new file mode 100644 new file mode 100644
index 000000000..db899937b index 000000000..41c79650b
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java +++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -0,0 +0,0 @@ @@ -0,0 +0,0 @@
@ -185,30 +185,34 @@ index 000000000..db899937b
+ } + }
+ WorldServer world = ((CraftWorld) Bukkit.getWorld(worldName)).getHandle(); + WorldServer world = ((CraftWorld) Bukkit.getWorld(worldName)).getHandle();
+ +
+ Map<MinecraftKey, Integer> nonEntityTicking = Maps.newHashMap();
+ ChunkProviderServer chunkProviderServer = world.getChunkProvider();
+
+ Collection<Entity> entities = world.entitiesById.values(); + Collection<Entity> entities = world.entitiesById.values();
+ entities.forEach(e -> { + entities.forEach(e -> {
+ if (!e.isChunkLoaded()) {
+ return;
+ }
+ MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch + MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch
+ +
+ MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap())); + MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
+ ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ()); + ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ());
+ info.left++; + info.left++;
+ info.right.put(chunk, info.right.getOrDefault(chunk, 0) + 1); + info.right.put(chunk, info.right.getOrDefault(chunk, 0) + 1);
+ if (!chunkProviderServer.isInEntityTickingChunk(e)) {
+ nonEntityTicking.merge(key, Integer.valueOf(1), Integer::sum);
+ }
+ }); + });
+ +
+ if (names.size() == 1) { + if (names.size() == 1) {
+ MinecraftKey name = names.iterator().next(); + MinecraftKey name = names.iterator().next();
+ Pair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.get(name); + Pair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.get(name);
+ int nonTicking = nonEntityTicking.getOrDefault(name, Integer.valueOf(0)).intValue();
+ if (info == null) { + if (info == null) {
+ sender.sendMessage(ChatColor.RED + "No entities found."); + sender.sendMessage(ChatColor.RED + "No entities found.");
+ return; + return;
+ } + }
+ sender.sendMessage("Entity: " + name + " Total: " + info.getLeft()); + sender.sendMessage("Entity: " + name + " Total Ticking: " + (info.getLeft() - nonTicking) + ", Total Non-Ticking: " + nonTicking);
+ info.getRight().entrySet().stream() + info.getRight().entrySet().stream()
+ .sorted((a, b) -> !a.getValue().equals(b.getValue()) ? b.getValue() - a.getValue() : a.getKey().toString().compareTo(b.getKey().toString())) + .sorted((a, b) -> !a.getValue().equals(b.getValue()) ? b.getValue() - a.getValue() : a.getKey().toString().compareTo(b.getKey().toString()))
+ .limit(10).forEach(e -> sender.sendMessage(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z)); + .limit(10).forEach(e -> sender.sendMessage(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z + (chunkProviderServer.isEntityTickingChunk(e.getKey()) ? " (Ticking)" : " (Non-Ticking)")));
+ } else { + } else {
+ List<Pair<MinecraftKey, Integer>> info = list.entrySet().stream() + List<Pair<MinecraftKey, Integer>> info = list.entrySet().stream()
+ .filter(e -> names.contains(e.getKey())) + .filter(e -> names.contains(e.getKey()))
@ -222,8 +226,13 @@ index 000000000..db899937b
+ } + }
+ +
+ int count = info.stream().mapToInt(Pair::getRight).sum(); + int count = info.stream().mapToInt(Pair::getRight).sum();
+ sender.sendMessage("Total: " + count); + int nonTickingCount = nonEntityTicking.values().stream().mapToInt(Integer::intValue).sum();
+ info.forEach(e -> sender.sendMessage(" " + e.getValue() + ": " + e.getKey())); + sender.sendMessage("Total Ticking: " + (count - nonTickingCount) + ", Total Non-Ticking: " + nonTickingCount);
+ info.forEach(e -> {
+ int nonTicking = nonEntityTicking.getOrDefault(e.getKey(), Integer.valueOf(0)).intValue();
+ sender.sendMessage(" " + (e.getValue() - nonTicking) + " (" + nonTicking + ") " + ": " + e.getKey());
+ });
+ sender.sendMessage("* First number is ticking entities, second number is non-ticking entities");
+ } + }
+ break; + break;
+ } + }
@ -520,6 +529,30 @@ index 000000000..a73865739
+ return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path)); + return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path));
+ } + }
+} +}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 41eac3588..32c496fa8 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
}
}
- @Override
- public boolean a(Entity entity) {
+ public final boolean isInEntityTickingChunk(Entity entity) { return this.a(entity); } // Paper - OBFHELPER
+ @Override public boolean a(Entity entity) {
long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4);
return this.a(i, PlayerChunk::b);
}
- @Override
- public boolean a(ChunkCoordIntPair chunkcoordintpair) {
+ public final boolean isEntityTickingChunk(ChunkCoordIntPair chunkcoordintpair) { return this.a(chunkcoordintpair); } // Paper - OBFHELPER
+ @Override public boolean a(ChunkCoordIntPair chunkcoordintpair) {
return this.a(chunkcoordintpair.pair(), PlayerChunk::b);
}
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
index 136d1b50f..9eed98e37 100644 index 136d1b50f..9eed98e37 100644
--- a/src/main/java/net/minecraft/server/DedicatedServer.java --- a/src/main/java/net/minecraft/server/DedicatedServer.java