player-indicators: break out decorating code into own methods

This commit is contained in:
Lotto
2020-03-01 21:35:37 +01:00
committed by Adam
parent b85675f624
commit e7171ee386

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.playerindicators;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Value;
import net.runelite.api.ClanMemberRank; import net.runelite.api.ClanMemberRank;
import static net.runelite.api.ClanMemberRank.UNRANKED; import static net.runelite.api.ClanMemberRank.UNRANKED;
import net.runelite.api.Client; import net.runelite.api.Client;
@@ -115,7 +116,6 @@ public class PlayerIndicatorsPlugin extends Plugin
|| type == PLAYER_EIGTH_OPTION.getId() || type == PLAYER_EIGTH_OPTION.getId()
|| type == RUNELITE.getId()) || type == RUNELITE.getId())
{ {
final Player localPlayer = client.getLocalPlayer();
Player[] players = client.getCachedPlayers(); Player[] players = client.getCachedPlayers();
Player player = null; Player player = null;
@@ -129,6 +129,27 @@ public class PlayerIndicatorsPlugin extends Plugin
return; return;
} }
Decorations decorations = getDecorations(player);
if (decorations == null)
{
return;
}
MenuEntry[] menuEntries = client.getMenuEntries();
MenuEntry entry = menuEntries[menuEntries.length - 1];
String oldTarget = entry.getTarget();
String newTarget = decorateTarget(oldTarget, decorations);
entry.setTarget(newTarget);
client.setMenuEntries(menuEntries);
}
}
private Decorations getDecorations(Player player)
{
int image = -1; int image = -1;
Color color = null; Color color = null;
@@ -146,7 +167,8 @@ public class PlayerIndicatorsPlugin extends Plugin
image = clanManager.getIconNumber(rank); image = clanManager.getIconNumber(rank);
} }
} }
else if (config.highlightTeamMembers() && player.getTeam() > 0 && localPlayer.getTeam() == player.getTeam()) else if (config.highlightTeamMembers()
&& player.getTeam() > 0 && client.getLocalPlayer().getTeam() == player.getTeam())
{ {
color = config.getTeamMemberColor(); color = config.getTeamMemberColor();
} }
@@ -155,31 +177,42 @@ public class PlayerIndicatorsPlugin extends Plugin
color = config.getNonClanMemberColor(); color = config.getNonClanMemberColor();
} }
if (image != -1 || color != null) if (image == -1 && color == null)
{ {
MenuEntry[] menuEntries = client.getMenuEntries(); return null;
MenuEntry lastEntry = menuEntries[menuEntries.length - 1]; }
if (color != null && config.colorPlayerMenu()) return new Decorations(image, color);
}
private String decorateTarget(String oldTarget, Decorations decorations)
{
String newTarget = oldTarget;
if (decorations.getColor() != null && config.colorPlayerMenu())
{ {
// strip out existing <col... // strip out existing <col...
String target = lastEntry.getTarget(); int idx = oldTarget.indexOf('>');
int idx = target.indexOf('>');
if (idx != -1) if (idx != -1)
{ {
target = target.substring(idx + 1); newTarget = oldTarget.substring(idx + 1);
} }
lastEntry.setTarget(ColorUtil.prependColorTag(target, color)); newTarget = ColorUtil.prependColorTag(newTarget, decorations.getColor());
} }
if (image != -1 && config.showClanRanks()) if (decorations.getImage() != -1 && config.showClanRanks())
{ {
lastEntry.setTarget("<img=" + image + ">" + lastEntry.getTarget()); newTarget = "<img=" + decorations.getImage() + ">" + newTarget;
} }
client.setMenuEntries(menuEntries); return newTarget;
}
} }
@Value
private static class Decorations
{
private final int image;
private final Color color;
} }
} }