Paper/Spigot-Server-Patches/0325-World-EntityHuman-Lookup-Optimizations.patch

83 lines
3.4 KiB
Diff
Raw Normal View History

2018-07-31 23:44:46 +02:00
From c9e6dd33ed8c202f81aaddcfe777e9e7bfcaba3b Mon Sep 17 00:00:00 2001
From: willies952002 <admin@domnian.com>
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
2018-07-31 23:44:46 +02:00
index 60a2729ad..c2b9d60f8 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<TileEntity> c = Lists.newArrayList();
private final Set<TileEntity> tileEntityListUnload = Sets.newHashSet(); // Paper
public final List<EntityHuman> players = Lists.newArrayList();
+ public final Map<String, EntityHuman> playersByName = Maps.newHashMap(); // Paper - World EntityHuman Lookup Optimizations
public final List<Entity> k = Lists.newArrayList();
protected final IntHashMap<Entity> 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();
}
2018-07-31 23:44:46 +02:00
@@ -1102,6 +1105,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 )
{
2018-07-31 23:44:46 +02:00
@@ -1132,6 +1136,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();
}
2018-07-31 23:44:46 +02:00
@@ -2660,6 +2665,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);
2018-07-31 23:44:46 +02:00
@@ -2669,10 +2676,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);
2018-07-31 23:44:46 +02:00
@@ -2682,6 +2694,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 {
--
2018-07-31 23:44:46 +02:00
2.17.1