aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0312-World-EntityHuman-Lookup-Optimizations.patch
blob: 796ed803a97049707cf83184bdb30cb11a27585a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From df9635bc942ea00aedd136fdea9d06027e38b337 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
index 5d60b36678..3acea908c2 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -76,6 +76,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
     private final List<TileEntity> c = Lists.newArrayList();
     private final Set<TileEntity> tileEntityListUnload = com.google.common.collect.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 F = 16777215L;
@@ -1030,6 +1031,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
                 EntityHuman entityhuman = (EntityHuman) entity;
 
                 this.players.add(entityhuman);
+                this.playersByName.put(entityhuman.getName(), entityhuman);
+                // Paper end
                 this.everyoneSleeping();
             }
 
@@ -1072,6 +1075,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
         entity.die();
         if (entity instanceof EntityHuman) {
             this.players.remove(entity);
+            this.playersByName.remove(entity.getName()); // Paper - World EntityHuman Lookup Optimizations
             // Spigot start
             for ( WorldPersistentData worldData : worldMaps.worldMap.values() )
             {
@@ -1105,6 +1109,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
         entity.die();
         if (entity instanceof EntityHuman) {
             this.players.remove(entity);
+            this.playersByName.remove(entity.getName()); // Paper - World EntityHuman Lookup Optimizations
             this.everyoneSleeping();
         }
 
@@ -2667,6 +2672,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
 
     @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);
 
@@ -2676,10 +2683,15 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
         }
 
         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);
 
@@ -2689,6 +2701,10 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
         }
 
         return null;
+        */
+        Entity entity = ((WorldServer)this).entitiesByUUID.get(uuid);
+        return entity instanceof EntityHuman ? (EntityHuman) entity : null;
+        // Paper end
     }
 
     public void checkSession() throws ExceptionWorldConflict {
-- 
2.21.0