Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 4d4802c

Browse files
committed
Optimize loop performance
1 parent c459f52 commit 4d4802c

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/java/net/opmasterleo/combat/listener/EntityDamageByEntityListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ private Player findLatestAttacker() {
159159

160160
Player latestAttacker = null;
161161
long latestTimestamp = 0;
162-
162+
final Map<UUID, Long> attackTimestampsLocal = attackTimestamps;
163163
for (Map.Entry<UUID, Player> entry : projectileOwners.entrySet()) {
164164
UUID playerId = entry.getKey();
165-
Long timestamp = attackTimestamps.get(playerId);
165+
Long timestamp = attackTimestampsLocal.get(playerId);
166166
if (timestamp != null && timestamp > latestTimestamp) {
167167
latestTimestamp = timestamp;
168168
latestAttacker = entry.getValue();

src/main/java/net/opmasterleo/combat/manager/GlowManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ private void schedulePeriodicSync() {
9292
if (!enabled || !glowingConfigEnabled) {
9393
return;
9494
}
95+
final Map<UUID, Combat.CombatRecord> combatRecordsLocal = plugin.getCombatRecords();
9596
List<Player> playersToSync = new ArrayList<>();
96-
for (UUID uuid : plugin.getCombatRecords().keySet()) {
97+
for (UUID uuid : combatRecordsLocal.keySet()) {
9798
Player p = Bukkit.getPlayer(uuid);
9899
if (p != null && p.isOnline()) {
99100
playersToSync.add(p);
@@ -111,14 +112,16 @@ private void schedulePeriodicSync() {
111112
long now = System.currentTimeMillis();
112113
List<Player> playersNeedingGlow = new ArrayList<>();
113114
List<UUID> opponentIds = new ArrayList<>();
114-
for (Map.Entry<UUID, GlowState> entry : glowingPlayers.entrySet()) {
115+
final Map<UUID, GlowState> glowingPlayersLocal = glowingPlayers;
116+
final Map<UUID, Long> lastPacketLocal = lastPacketSent;
117+
for (Map.Entry<UUID, GlowState> entry : glowingPlayersLocal.entrySet()) {
115118
UUID uuid = entry.getKey();
116119
GlowState state = entry.getValue();
117120
if (state == null || !state.isGlowing) continue;
118121
Player p = Bukkit.getPlayer(uuid);
119122
if (p == null || !p.isOnline()) continue;
120123

121-
Long last = lastPacketSent.get(uuid);
124+
Long last = lastPacketLocal.get(uuid);
122125
if (last == null || now - last >= 500L) {
123126
playersNeedingGlow.add(p);
124127
opponentIds.add(state.opponentId);

0 commit comments

Comments
 (0)