From 30caec4d945d16c270508356eb7b09c0baf60bfe Mon Sep 17 00:00:00 2001 From: willies952002 Date: Tue, 31 Jul 2018 00:27:45 -0400 Subject: [PATCH] World EntityHuman Lookup Optimizations (#1291) Fixes #1290 --- ...rld-EntityHuman-Lookup-Optimizations.patch | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Spigot-Server-Patches/0325-World-EntityHuman-Lookup-Optimizations.patch diff --git a/Spigot-Server-Patches/0325-World-EntityHuman-Lookup-Optimizations.patch b/Spigot-Server-Patches/0325-World-EntityHuman-Lookup-Optimizations.patch new file mode 100644 index 000000000..5f3bcf44c --- /dev/null +++ b/Spigot-Server-Patches/0325-World-EntityHuman-Lookup-Optimizations.patch @@ -0,0 +1,82 @@ +From ca8a816fa3bfdbceda39eb992b4e29cca55bea8d Mon Sep 17 00:00:00 2001 +From: willies952002 +Date: Mon, 30 Jul 2018 02:42:49 -0400 +Subject: [PATCH] World EntityHuman Lookup Optimizations + + +diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java +index ece187129..b76135cb0 100644 +--- a/src/main/java/net/minecraft/server/World.java ++++ b/src/main/java/net/minecraft/server/World.java +@@ -79,6 +79,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + private final List c = Lists.newArrayList(); + private final Set tileEntityListUnload = Sets.newHashSet(); // Paper + public final List players = Lists.newArrayList(); ++ public final Map playersByName = Maps.newHashMap(); // Paper - World EntityHuman Lookup Optimizations + public final List k = Lists.newArrayList(); + protected final IntHashMap entitiesById = new IntHashMap(); + private final long G = 16777215L; +@@ -1060,6 +1061,8 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + EntityHuman entityhuman = (EntityHuman) entity; + + this.players.add(entityhuman); ++ this.playersByName.put(entityhuman.getName(), entityhuman); ++ // Paper end + this.everyoneSleeping(); + } + +@@ -1101,6 +1104,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + entity.die(); + if (entity instanceof EntityHuman) { + this.players.remove(entity); ++ this.playersByName.remove(entity.getName()); // Paper - World EntityHuman Lookup Optimizations + // Spigot start + for ( Object o : worldMaps.d ) + { +@@ -1131,6 +1135,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + entity.die(); + if (entity instanceof EntityHuman) { + this.players.remove(entity); ++ this.playersByName.remove(entity.getName()); // Paper - World EntityHuman Lookup Optimizations + this.everyoneSleeping(); + } + +@@ -2659,6 +2664,8 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + + @Nullable + public EntityHuman a(String s) { ++ // Paper start - World EntityHuman Lookup Optimizations ++ /* + for (int i = 0; i < this.players.size(); ++i) { + EntityHuman entityhuman = (EntityHuman) this.players.get(i); + +@@ -2668,10 +2675,15 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + } + + return null; ++ */ ++ return this.playersByName.get(s); ++ // Paper end + } + + @Nullable + public EntityHuman b(UUID uuid) { ++ // Paper start - World EntityHuman Lookup Optimizations ++ /* + for (int i = 0; i < this.players.size(); ++i) { + EntityHuman entityhuman = (EntityHuman) this.players.get(i); + +@@ -2681,6 +2693,10 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose + } + + return null; ++ */ ++ Entity entity = ((WorldServer)this).entitiesByUUID.get(uuid); ++ return entity instanceof EntityHuman ? (EntityHuman) entity : null; ++ // Paper end + } + + public void checkSession() throws ExceptionWorldConflict { +-- +2.18.0 +