Properly invalidate clan ranks and names
- Invalidate clan ranks when player changes his clan - Invalidate player names when game state changes Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -33,6 +33,7 @@ import javax.inject.Inject;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.events.ClanChanged;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.SetMessage;
|
||||
@@ -76,30 +77,41 @@ public class PlayerIndicatorsPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
playerIndicatorsService.updateConfig(false);
|
||||
playerIndicatorsService.invalidatePlayerNames();
|
||||
playerIndicatorsService.updateConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
playerIndicatorsService.updateConfig(true);
|
||||
playerIndicatorsService.invalidatePlayerNames();
|
||||
playerIndicatorsService.invalidateClanRanksCache();
|
||||
client.setPlayerNameMask(0);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (event.getGroup().equals("playerindicators")
|
||||
|| event.getGroup().equals("runelite")
|
||||
|| event.getGroup().equals("minimap"))
|
||||
if (event.getGroup().equals("playerindicators"))
|
||||
{
|
||||
playerIndicatorsService.updateConfig(false);
|
||||
playerIndicatorsService.invalidatePlayerNames();
|
||||
playerIndicatorsService.updateConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||
public void onGameStateChanged(GameStateChanged event)
|
||||
{
|
||||
playerIndicatorsService.updateConfig(false);
|
||||
if (event.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
playerIndicatorsService.updateConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onClanChanged(ClanChanged event)
|
||||
{
|
||||
playerIndicatorsService.invalidateClanRanksCache();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -100,14 +100,8 @@ public class PlayerIndicatorsService
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void updateConfig(boolean reset)
|
||||
public void invalidatePlayerNames()
|
||||
{
|
||||
// Update mod icons
|
||||
if (modIconsLength == 0 && client.getGameState().compareTo(GameState.LOGIN_SCREEN) >= 0)
|
||||
{
|
||||
loadClanChatIcons();
|
||||
}
|
||||
|
||||
// Reset player names
|
||||
for (Player player : client.getPlayers())
|
||||
{
|
||||
@@ -117,36 +111,45 @@ public class PlayerIndicatorsService
|
||||
}
|
||||
}
|
||||
|
||||
// Reset clan rank cache
|
||||
if (reset)
|
||||
// Refresh chat box
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
public void invalidateClanRanksCache()
|
||||
{
|
||||
// Invalidate clan cache
|
||||
clanRanksCache.invalidateAll();
|
||||
}
|
||||
|
||||
public void updateConfig()
|
||||
{
|
||||
// Update mod icons
|
||||
if (modIconsLength == 0 && client.getGameState().compareTo(GameState.LOGGED_IN) >= 0)
|
||||
{
|
||||
clanRanksCache.invalidateAll();
|
||||
loadClanChatIcons();
|
||||
}
|
||||
|
||||
// Update mask
|
||||
int baseMask = 0;
|
||||
|
||||
if (!reset)
|
||||
if (config.drawFriendNames())
|
||||
{
|
||||
if (config.drawFriendNames())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_FRIEND_NAME;
|
||||
}
|
||||
baseMask |= PlayerNameMask.DRAW_FRIEND_NAME;
|
||||
}
|
||||
|
||||
if (config.drawClanMemberNames())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_CLAN_NAME;
|
||||
}
|
||||
if (config.drawClanMemberNames())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_CLAN_NAME;
|
||||
}
|
||||
|
||||
if (config.drawOwnName())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_OWN_NAME;
|
||||
}
|
||||
if (config.drawOwnName())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_OWN_NAME;
|
||||
}
|
||||
|
||||
if (config.drawNonOwnNames())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_ALL_EXCEPT_OWN_NAME;
|
||||
}
|
||||
if (config.drawNonOwnNames())
|
||||
{
|
||||
baseMask |= PlayerNameMask.DRAW_ALL_EXCEPT_OWN_NAME;
|
||||
}
|
||||
|
||||
client.setPlayerNameMask(baseMask);
|
||||
@@ -160,15 +163,6 @@ public class PlayerIndicatorsService
|
||||
|
||||
public void forEachPlayer(final BiConsumer<Player, Color> consumer)
|
||||
{
|
||||
if (!config.drawOwnName()
|
||||
&& !config.drawClanMemberNames()
|
||||
&& !config.drawFriendNames()
|
||||
&& !config.drawNonOwnNames()
|
||||
&& !config.drawTeamMemberNames())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player localPlayer = client.getLocalPlayer();
|
||||
|
||||
for (Player player : client.getPlayers())
|
||||
|
||||
Reference in New Issue
Block a user