combatcounter: Don't access map more than needed

This commit is contained in:
sdburns1998
2019-07-07 03:19:53 +02:00
parent 706e9fbf13
commit 64d9a260a0
2 changed files with 10 additions and 9 deletions

View File

@@ -96,17 +96,18 @@ class CombatOverlay extends Overlay
return null; return null;
} }
for (String name : map.keySet()) for (Map.Entry<String, Long> counter : map.entrySet())
{ {
String name = counter.getKey();
if (client.getLocalPlayer().getName().contains(name)) if (client.getLocalPlayer().getName().contains(name))
{ {
tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getSelfColor()), ColorUtil.prependColorTag(Long.toString(map.get(name)), plugin.getSelfColor())); tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getSelfColor()), ColorUtil.prependColorTag(Long.toString(counter.getValue()), plugin.getSelfColor()));
} }
else else
{ {
tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getOtherColor()), ColorUtil.prependColorTag(Long.toString(map.get(name)), plugin.getOtherColor())); tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getOtherColor()), ColorUtil.prependColorTag(Long.toString(counter.getValue()), plugin.getOtherColor()));
} }
total += map.get(name); total += counter.getValue();
} }
if (!map.containsKey(local.getName())) if (!map.containsKey(local.getName()))

View File

@@ -97,16 +97,16 @@ class DamageOverlay extends Overlay
return null; return null;
} }
for (String name : map.keySet()) for (Map.Entry<String, Double> damage : map.entrySet())
{ {
String val = String.format("%.1f", map.get(name)); String val = String.format("%.1f", damage.getValue());
if (client.getLocalPlayer().getName().contains(name)) if (client.getLocalPlayer().getName().contains(damage.getKey()))
{ {
tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getSelfColor()), ColorUtil.prependColorTag(val, plugin.getSelfColor())); tableComponent.addRow(ColorUtil.prependColorTag(damage.getKey(), plugin.getSelfColor()), ColorUtil.prependColorTag(val, plugin.getSelfColor()));
} }
else else
{ {
tableComponent.addRow(ColorUtil.prependColorTag(name, plugin.getOtherColor()), ColorUtil.prependColorTag(val, plugin.getOtherColor())); tableComponent.addRow(ColorUtil.prependColorTag(damage.getKey(), plugin.getOtherColor()), ColorUtil.prependColorTag(val, plugin.getOtherColor()));
} }
} }