From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sat, 11 Jan 2020 21:50:56 -0800 Subject: [PATCH] Optimise IEntityAccess#getPlayerByUUID Use the world entity map instead of iterating over all players diff --git a/src/main/java/net/minecraft/server/IEntityAccess.java b/src/main/java/net/minecraft/server/IEntityAccess.java index b6cf294e785b36b8bc800f26dbb8cfcb2119eae1..1cb8ba7cd28cdb8a660c2d78d35e86cd5cf08a8f 100644 --- a/src/main/java/net/minecraft/server/IEntityAccess.java +++ b/src/main/java/net/minecraft/server/IEntityAccess.java @@ -243,6 +243,12 @@ public interface IEntityAccess { @Nullable default EntityHuman b(UUID uuid) { + // Paper start - allow WorldServer to override + return this.getPlayerByUUID(uuid); + } + @Nullable + default EntityHuman getPlayerByUUID(UUID uuid) { + // Paper end for (int i = 0; i < this.getPlayers().size(); ++i) { EntityHuman entityhuman = (EntityHuman) this.getPlayers().get(i); diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index d45fb3b7303d4019a02a97baa5672e7a855af359..476d241f85718ee878610c99a9ae5324aff67865 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -173,6 +173,15 @@ public class WorldServer extends World implements GeneratorAccessSeed { } // Paper end + // Paper start - optimise getPlayerByUUID + @Nullable + @Override + public EntityHuman getPlayerByUUID(UUID uuid) { + Entity player = this.entitiesByUUID.get(uuid); + return (player instanceof EntityHuman) ? (EntityHuman)player : null; + } + // Paper end + // Add env and gen to constructor, WorldData -> WorldDataServer public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey resourcekey, DimensionManager dimensionmanager, WorldLoadListener worldloadlistener, ChunkGenerator chunkgenerator, boolean flag, long i, List list, boolean flag1, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) { super(iworlddataserver, resourcekey, dimensionmanager, minecraftserver::getMethodProfiler, false, flag, i, gen, env, executor); // Paper pass executor