0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 20:56:14 +00:00
spigot/CraftBukkit-Patches/0067-Use-Map-for-getPlayer-String-lookup.patch
2024-10-23 02:15:00 +11:00

73 lines
4.0 KiB
Diff

From a8cf458eaffc54c0ecc7c8e3243ef350496715e8 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Mon, 13 Jul 2015 19:05:15 +1000
Subject: [PATCH] Use Map for getPlayer(String) lookup.
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 61fa728269..81a8d17993 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -159,6 +159,7 @@ public abstract class PlayerList {
// CraftBukkit start
private CraftServer cserver;
+ private final Map<String,EntityPlayer> playersByName = new java.util.HashMap<>();
public PlayerList(MinecraftServer minecraftserver, LayeredRegistryAccess<RegistryLayer> layeredregistryaccess, WorldNBTStorage worldnbtstorage, int i) {
this.cserver = minecraftserver.server = new CraftServer((DedicatedServer) minecraftserver, this);
@@ -284,6 +285,7 @@ public abstract class PlayerList {
// entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); // CraftBukkit - replaced with loop below
this.players.add(entityplayer);
+ this.playersByName.put(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT), entityplayer); // Spigot
this.playersByUUID.put(entityplayer.getUUID(), entityplayer);
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below
@@ -492,6 +494,7 @@ public abstract class PlayerList {
worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER);
entityplayer.getAdvancements().stopListening();
this.players.remove(entityplayer);
+ this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
this.server.getCustomBossEvents().onPlayerDisconnect(entityplayer);
UUID uuid = entityplayer.getUUID();
EntityPlayer entityplayer1 = (EntityPlayer) this.playersByUUID.get(uuid);
@@ -645,6 +648,7 @@ public abstract class PlayerList {
public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag, Entity.RemovalReason entity_removalreason, RespawnReason reason, Location location) {
entityplayer.stopRiding(); // CraftBukkit
this.players.remove(entityplayer);
+ this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
entityplayer.serverLevel().removePlayerImmediately(entityplayer, entity_removalreason);
/* CraftBukkit start
TeleportTransition teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING);
@@ -720,6 +724,7 @@ public abstract class PlayerList {
if (!entityplayer.connection.isDisconnected()) {
worldserver.addRespawnedPlayer(entityplayer1);
this.players.add(entityplayer1);
+ this.playersByName.put(entityplayer1.getScoreboardName().toLowerCase(java.util.Locale.ROOT), entityplayer1); // Spigot
this.playersByUUID.put(entityplayer1.getUUID(), entityplayer1);
}
// entityplayer1.initInventoryMenu();
@@ -946,17 +951,7 @@ public abstract class PlayerList {
@Nullable
public EntityPlayer getPlayerByName(String s) {
- int i = this.players.size();
-
- for (int j = 0; j < i; ++j) {
- EntityPlayer entityplayer = (EntityPlayer) this.players.get(j);
-
- if (entityplayer.getGameProfile().getName().equalsIgnoreCase(s)) {
- return entityplayer;
- }
- }
-
- return null;
+ return this.playersByName.get(s.toLowerCase(java.util.Locale.ROOT)); // Spigot
}
public void broadcast(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, ResourceKey<World> resourcekey, Packet<?> packet) {
--
2.47.0