Current Chunk for Entity and Block Entities, counts by entity type
This enables us a fast reference to the entities current chunk instead of having to look it up by hashmap lookups. We also store counts by type to further enable other performance optimizations in later patches.
This commit is contained in:
32
Spigot-API-Patches/Entity-getChunk-API.patch
Normal file
32
Spigot-API-Patches/Entity-getChunk-API.patch
Normal file
@@ -0,0 +1,32 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Wed, 4 Jul 2018 02:25:48 -0400
|
||||
Subject: [PATCH] Entity#getChunk API
|
||||
|
||||
Get the chunk the entity is currently registered to
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
|
||||
index 3ae4de7a..e2a2b78c 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Entity.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Entity.java
|
||||
@@ -0,0 +0,0 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
+import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.EntityEffect;
|
||||
import org.bukkit.Nameable;
|
||||
@@ -0,0 +0,0 @@ public interface Entity extends Metadatable, CommandSender, Nameable {
|
||||
* @return True if entity spawned from a mob spawner
|
||||
*/
|
||||
boolean fromMobSpawner();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the latest chunk an entity is currently or was in.
|
||||
+ *
|
||||
+ * @return The current, or most recent chunk if the entity is invalid (which may load the chunk)
|
||||
+ */
|
||||
+ Chunk getChunk();
|
||||
// Paper end
|
||||
}
|
||||
--
|
||||
@@ -2296,6 +2296,47 @@ index 00000000..5edaba12
|
||||
+ super.stopTiming();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/co/aikar/util/Counter.java b/src/main/java/co/aikar/util/Counter.java
|
||||
new file mode 100644
|
||||
index 00000000..23ac07f2
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/co/aikar/util/Counter.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package co.aikar.util;
|
||||
+
|
||||
+import com.google.common.collect.ForwardingMap;
|
||||
+
|
||||
+import java.util.HashMap;
|
||||
+import java.util.Map;
|
||||
+
|
||||
+public class Counter <T> extends ForwardingMap<T, Long> {
|
||||
+ private final Map<T, Long> counts = new HashMap<>();
|
||||
+
|
||||
+ public long decrement(T key) {
|
||||
+ return increment(key, -1);
|
||||
+ }
|
||||
+ public long increment(T key) {
|
||||
+ return increment(key, 1);
|
||||
+ }
|
||||
+ public long decrement(T key, long amount) {
|
||||
+ return decrement(key, -amount);
|
||||
+ }
|
||||
+ public long increment(T key, long amount) {
|
||||
+ Long count = this.getCount(key);
|
||||
+ count += amount;
|
||||
+ this.counts.put(key, count);
|
||||
+ return count;
|
||||
+ }
|
||||
+
|
||||
+ public long getCount(T key) {
|
||||
+ return this.counts.getOrDefault(key, 0L);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected Map<T, Long> delegate() {
|
||||
+ return this.counts;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/co/aikar/util/JSONUtil.java b/src/main/java/co/aikar/util/JSONUtil.java
|
||||
new file mode 100644
|
||||
index 00000000..96274975
|
||||
@@ -3032,7 +3073,7 @@ index 00000000..fd452bce
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
|
||||
index 08a9739f..347d2189 100644
|
||||
index 7ca5be84..86c78098 100644
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
@@ -3610,7 +3651,7 @@ index 80c6a72e..759c4617 100644
|
||||
eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
|
||||
} else {
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
index d7d5ac7b..a657fce5 100644
|
||||
index e43db9da..ca9c7796 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
Reference in New Issue
Block a user