Micro optimisations

This commit is contained in:
fullwall 2023-10-15 21:57:13 +08:00
parent ad89e9aa83
commit 9d9b3c4349
3 changed files with 37 additions and 9 deletions

View File

@ -131,6 +131,9 @@ public class ProtocolLibListener implements Listener {
return;
boolean changed = false;
GameProfile playerProfile = null;
WrappedGameProfile wgp = null;
WrappedChatComponent playerName = null;
for (int i = 0; i < list.size(); i++) {
PlayerInfoData npcInfo = list.get(i);
if (npcInfo == null)
@ -139,19 +142,22 @@ public class ProtocolLibListener implements Listener {
if (trait == null || !trait.isMirroring(event.getPlayer()))
continue;
GameProfile playerProfile = NMS.getProfile(event.getPlayer());
if (playerProfile == null) {
playerProfile = NMS.getProfile(event.getPlayer());
wgp = WrappedGameProfile.fromPlayer(event.getPlayer());
playerName = WrappedChatComponent.fromText(event.getPlayer().getDisplayName());
}
if (trait.mirrorName()) {
list.set(i,
new PlayerInfoData(
WrappedGameProfile.fromPlayer(event.getPlayer())
.withId(npcInfo.getProfile().getId()),
npcInfo.getLatency(), npcInfo.getGameMode(),
WrappedChatComponent.fromText(event.getPlayer().getDisplayName())));
list.set(i, new PlayerInfoData(wgp.withId(npcInfo.getProfile().getId()), npcInfo.getLatency(),
npcInfo.getGameMode(), playerName));
continue;
}
Collection<Property> textures = playerProfile.getProperties().get("textures");
if (textures == null || textures.size() == 0)
continue;
npcInfo.getProfile().getProperties().clear();
for (String key : playerProfile.getProperties().keySet()) {
npcInfo.getProfile().getProperties().putAll(key,
@ -162,6 +168,7 @@ public class ProtocolLibListener implements Listener {
}
changed = true;
}
if (changed) {
event.getPacket().getPlayerInfoDataLists().write(0, list);
}

View File

@ -1179,14 +1179,17 @@ public class NMSImpl implements NMSBridge {
ClientboundPlayerInfoUpdatePacket packet = (ClientboundPlayerInfoUpdatePacket) raw;
List<ClientboundPlayerInfoUpdatePacket.Entry> list = Lists.newArrayList(packet.entries());
boolean changed = false;
GameProfile playerProfile = null;
for (int i = 0; i < list.size(); i++) {
ClientboundPlayerInfoUpdatePacket.Entry npcInfo = list.get(i);
if (npcInfo == null)
continue;
MirrorTrait trait = mirrorTraits.apply(npcInfo.profileId());
if (trait == null || !trait.isMirroring(player)) {
continue;
}
if (Setting.DISABLE_TABLIST.asBoolean() != npcInfo.listed()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), npcInfo.profile(),
@ -1195,7 +1198,11 @@ public class NMSImpl implements NMSBridge {
npcInfo.chatSession()));
changed = true;
}
GameProfile playerProfile = NMS.getProfile(player);
if (playerProfile == null) {
playerProfile = NMS.getProfile(player);
}
if (trait.mirrorName()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), playerProfile,
@ -1204,15 +1211,19 @@ public class NMSImpl implements NMSBridge {
changed = true;
continue;
}
Collection<Property> textures = playerProfile.getProperties().get("textures");
if (textures == null || textures.size() == 0)
continue;
npcInfo.profile().getProperties().clear();
for (String key : playerProfile.getProperties().keySet()) {
npcInfo.profile().getProperties().putAll(key, playerProfile.getProperties().get(key));
}
changed = true;
}
if (changed) {
try {
PLAYER_INFO_ENTRIES_LIST.invoke(packet, list);

View File

@ -1155,6 +1155,7 @@ public class NMSImpl implements NMSBridge {
ClientboundPlayerInfoUpdatePacket packet = (ClientboundPlayerInfoUpdatePacket) raw;
List<ClientboundPlayerInfoUpdatePacket.Entry> list = Lists.newArrayList(packet.entries());
boolean changed = false;
GameProfile playerProfile = null;
for (int i = 0; i < list.size(); i++) {
ClientboundPlayerInfoUpdatePacket.Entry npcInfo = list.get(i);
if (npcInfo == null)
@ -1164,6 +1165,7 @@ public class NMSImpl implements NMSBridge {
if (trait == null || !trait.isMirroring(player)) {
continue;
}
if (Setting.DISABLE_TABLIST.asBoolean() != npcInfo.listed()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), npcInfo.profile(),
@ -1172,7 +1174,11 @@ public class NMSImpl implements NMSBridge {
npcInfo.chatSession()));
changed = true;
}
GameProfile playerProfile = NMS.getProfile(player);
if (playerProfile == null) {
playerProfile = NMS.getProfile(player);
}
if (trait.mirrorName()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), playerProfile,
@ -1181,15 +1187,19 @@ public class NMSImpl implements NMSBridge {
changed = true;
continue;
}
Collection<Property> textures = playerProfile.getProperties().get("textures");
if (textures == null || textures.size() == 0)
continue;
npcInfo.profile().getProperties().clear();
for (String key : playerProfile.getProperties().keySet()) {
npcInfo.profile().getProperties().putAll(key, playerProfile.getProperties().get(key));
}
changed = true;
}
if (changed) {
try {
PLAYER_INFO_ENTRIES_LIST.invoke(packet, list);