From b9124ef873ee7c71051abb3cb6723695276a014d Mon Sep 17 00:00:00 2001 From: NEZNAMY Date: Mon, 9 Sep 2024 18:03:33 +0200 Subject: [PATCH] [Performance] Micro optimization on Bukkit in Team packet --- .../platforms/bukkit/scoreboard/packet/TeamPacketData.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bukkit/src/main/java/me/neznamy/tab/platforms/bukkit/scoreboard/packet/TeamPacketData.java b/bukkit/src/main/java/me/neznamy/tab/platforms/bukkit/scoreboard/packet/TeamPacketData.java index 19ea344f4..e7a3132a7 100644 --- a/bukkit/src/main/java/me/neznamy/tab/platforms/bukkit/scoreboard/packet/TeamPacketData.java +++ b/bukkit/src/main/java/me/neznamy/tab/platforms/bukkit/scoreboard/packet/TeamPacketData.java @@ -43,7 +43,6 @@ public class TeamPacketData { private final Field TeamPacket_NAME; private final Field TeamPacket_ACTION; private final Field TeamPacket_PLAYERS; - private final Method ScoreboardTeam_getPlayerNameSet; private final Method ScoreboardTeam_setPrefix; private final Method ScoreboardTeam_setSuffix; private Method ScoreboardTeam_setColor; @@ -82,7 +81,6 @@ public TeamPacketData() throws ReflectiveOperationException { TeamPacket_ACTION = intFields.get(0); } TeamPacket_PLAYERS = ReflectionUtils.getOnlyField(TeamPacketClass, Collection.class); - ScoreboardTeam_getPlayerNameSet = ReflectionUtils.getOnlyMethod(scoreboardTeam, Collection.class); chatFormats = (Enum[]) enumChatFormatClass.getMethod("values").invoke(null); ScoreboardTeam_setAllowFriendlyFire = ReflectionUtils.getMethod( scoreboardTeam, @@ -167,9 +165,10 @@ private void loadCollision(@NonNull Class scoreboardTeam) { @SneakyThrows public Object registerTeam(@NonNull Team team, @NotNull ProtocolVersion clientVersion) { updateTeamData(team, clientVersion); - ((Collection) ScoreboardTeam_getPlayerNameSet.invoke(team.getPlatformTeam())).addAll(team.getPlayers()); if (BukkitReflection.getMinorVersion() >= STATIC_CONSTRUCTOR_VERSION) { - return TeamPacketConstructor_ofBoolean.invoke(null, team.getPlatformTeam(), true); + Object packet = TeamPacketConstructor_ofBoolean.invoke(null, team.getPlatformTeam(), true); + TeamPacket_PLAYERS.set(packet, team.getPlayers()); + return packet; } else { return newTeamPacket.newInstance(team.getPlatformTeam(), TeamAction.CREATE); }