From c5e45cdd1991ea4afb82da70fc11ca2c59f070b6 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 397915a553..29877418c9 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; @@ -1061,6 +1062,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(); } @@ -1103,6 +1106,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 ) { @@ -1133,6 +1137,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(); } @@ -2661,6 +2666,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); @@ -2670,10 +2677,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); @@ -2683,6 +2695,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