Fix style errors

This commit is contained in:
bjornenalfa
2019-03-10 17:18:25 +01:00
parent e249cd96a3
commit 2ac184685f
2 changed files with 222 additions and 172 deletions

View File

@@ -33,7 +33,9 @@ import javax.inject.Inject;
import net.runelite.api.*; import net.runelite.api.*;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE;
import net.runelite.client.ui.overlay.OverlayMenuEntry; import net.runelite.client.ui.overlay.OverlayMenuEntry;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.OverlayPriority;
@@ -42,133 +44,155 @@ import net.runelite.client.ui.overlay.components.PanelComponent;
public class RaidsPartyOverlay extends Overlay public class RaidsPartyOverlay extends Overlay
{ {
public static final String PARTY_OVERLAY_RESET = "Reset missing"; public static final String PARTY_OVERLAY_RESET = "Reset missing";
public static final String PARTY_OVERLAY_REFRESH = "Refresh party"; public static final String PARTY_OVERLAY_REFRESH = "Refresh party";
@Inject @Inject
private Client client; private Client client;
@Inject @Inject
private RaidsPlugin plugin; private RaidsPlugin plugin;
private final PanelComponent panel = new PanelComponent(); private final PanelComponent panel = new PanelComponent();
@Inject @Inject
private RaidsPartyOverlay(RaidsPlugin plugin) private RaidsPartyOverlay(RaidsPlugin plugin)
{ {
super(plugin); super(plugin);
setPosition(OverlayPosition.TOP_RIGHT); setPosition(OverlayPosition.TOP_RIGHT);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Raids party overlay")); getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Raids party overlay"));
getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY, PARTY_OVERLAY_RESET, "Raids party overlay")); getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY, PARTY_OVERLAY_RESET, "Raids party overlay"));
getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY, PARTY_OVERLAY_REFRESH, "Raids party overlay")); getMenuEntries().add(new OverlayMenuEntry(MenuAction.RUNELITE_OVERLAY, PARTY_OVERLAY_REFRESH, "Raids party overlay"));
} }
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (!plugin.isInRaidChambers()) if (!plugin.isInRaidChambers())
{ {
return null; return null;
} }
if (client.getClanChatCount() == 0) { if (client.getClanChatCount() == 0)
// Player left clan chat {
return null; // Player left clan chat
} return null;
}
boolean inLobby = client.getVar(VarPlayer.IN_RAID_PARTY) != -1; // -1 if raid started boolean inLobby = client.getVar(VarPlayer.IN_RAID_PARTY) != -1; // -1 if raid started
int partySize = client.getVar(Varbits.RAID_PARTY_SIZE); int partySize = client.getVar(Varbits.RAID_PARTY_SIZE);
int playerCount = client.getPlayers().size(); int playerCount = client.getPlayers().size();
String partyCountString; String partyCountString;
Color countColor = Color.WHITE; Color countColor = Color.WHITE;
if (inLobby) { if (inLobby)
partyCountString = String.format("%d/%d", playerCount, partySize); {
// While we are in the lobby compare to players visible on the screen partyCountString = String.format("%d/%d", playerCount, partySize);
if (partySize <= playerCount) { // While we are in the lobby compare to players visible on the screen
countColor = Color.GREEN; if (partySize <= playerCount)
} else { {
countColor = Color.RED; countColor = Color.GREEN;
} }
} else { else
// If raid has started then we compare the current party size to what it was when we started {
partyCountString = String.format("%d/%d", partySize, plugin.getStartPlayerCount()); countColor = Color.RED;
if (plugin.getMissingPartyMembers().size() > 0) { }
countColor = Color.RED; // Somebody is missing }
} else
} {
// If raid has started then we compare the current party size to what it was when we started
partyCountString = String.format("%d/%d", partySize, plugin.getStartPlayerCount());
if (plugin.getMissingPartyMembers().size() > 0)
{
countColor = Color.RED; // Somebody is missing
}
}
panel.getChildren().clear(); panel.getChildren().clear();
// Show amount of people currently in raid vs total in the party // Show amount of people currently in raid vs total in the party
panel.getChildren().add(LineComponent.builder() panel.getChildren().add(LineComponent.builder()
.left("Party size:") .left("Party size:")
.right(partyCountString) .right(partyCountString)
.rightColor(countColor) .rightColor(countColor)
.build()); .build());
if (inLobby) { if (inLobby)
int world = client.getWorld(); {
int wrongWorldClanMembers = 0; int world = client.getWorld();
int clanMemberCount = 0; int wrongWorldClanMembers = 0;
for (ClanMember clanMember : client.getClanMembers()) { int clanMemberCount = 0;
if (clanMember != null) { for (ClanMember clanMember : client.getClanMembers())
if (clanMember.getWorld() != world) { {
wrongWorldClanMembers++; if (clanMember != null)
} else { {
clanMemberCount++; if (clanMember.getWorld() != world)
} {
} wrongWorldClanMembers++;
} }
else
{
clanMemberCount++;
}
}
}
// Show amount of people on the right world but not at the raids area // Show amount of people on the right world but not at the raids area
Color notInPartyColor = Color.GREEN; Color notInPartyColor = Color.GREEN;
int notInParty = clanMemberCount - partySize; int notInParty = clanMemberCount - partySize;
if (notInParty > 0) { if (notInParty > 0)
notInPartyColor = Color.WHITE; {
} notInPartyColor = Color.WHITE;
}
panel.getChildren().add(LineComponent.builder() panel.getChildren().add(LineComponent.builder()
.left("Not at raids:") .left("Not at raids:")
.right(String.valueOf(notInParty)) .right(String.valueOf(notInParty))
.rightColor(notInPartyColor) .rightColor(notInPartyColor)
.build()); .build());
// Show amount of clan members that are not in the right world. // Show amount of clan members that are not in the right world.
Color wrongWorldColor; Color wrongWorldColor;
if (wrongWorldClanMembers == 0) { if (wrongWorldClanMembers == 0)
wrongWorldColor = Color.GREEN; {
} else { wrongWorldColor = Color.GREEN;
wrongWorldColor = Color.WHITE; }
} else
{
wrongWorldColor = Color.WHITE;
}
panel.getChildren().add(LineComponent.builder() panel.getChildren().add(LineComponent.builder()
.left("Wrong world:") .left("Wrong world:")
.right(String.valueOf(wrongWorldClanMembers)) .right(String.valueOf(wrongWorldClanMembers))
.rightColor(wrongWorldColor) .rightColor(wrongWorldColor)
.build()); .build());
} else { }
Set<String> missingPartyMembers = plugin.getMissingPartyMembers(); else
if (missingPartyMembers.size() > 0) { {
panel.getChildren().add(LineComponent.builder() Set<String> missingPartyMembers = plugin.getMissingPartyMembers();
.left("Missing players:") if (missingPartyMembers.size() > 0)
.build()); {
panel.getChildren().add(LineComponent.builder()
.left("Missing players:")
.build());
for (String member : missingPartyMembers) { for (String member : missingPartyMembers)
panel.getChildren().add(LineComponent.builder() {
.left(member) panel.getChildren().add(LineComponent.builder()
.leftColor(Color.RED) .left(member)
.build()); .leftColor(Color.RED)
} .build());
} }
} }
}
return panel.render(graphics); return panel.render(graphics);
} }
} }

View File

@@ -27,12 +27,14 @@ package net.runelite.client.plugins.raids;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*; import net.runelite.api.*;
@@ -63,9 +65,9 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
@PluginDescriptor( @PluginDescriptor(
name = "Chambers Of Xeric", name = "Chambers Of Xeric",
description = "Show helpful information for the Chambers of Xeric raid", description = "Show helpful information for the Chambers of Xeric raid",
tags = {"combat", "raid", "overlay", "pve", "pvm", "bosses"} tags = {"combat", "raid", "overlay", "pve", "pvm", "bosses"}
) )
@Slf4j @Slf4j
public class RaidsPlugin extends Plugin public class RaidsPlugin extends Plugin
@@ -157,7 +159,8 @@ public class RaidsPlugin extends Plugin
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
if (config.partyDisplay()) { if (config.partyDisplay())
{
overlayManager.add(partyOverlay); overlayManager.add(partyOverlay);
} }
updateLists(); updateLists();
@@ -168,7 +171,8 @@ public class RaidsPlugin extends Plugin
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
if (config.partyDisplay()) { if (config.partyDisplay())
{
overlayManager.remove(partyOverlay); overlayManager.remove(partyOverlay);
} }
infoBoxManager.removeInfoBox(timer); infoBoxManager.removeInfoBox(timer);
@@ -191,10 +195,14 @@ public class RaidsPlugin extends Plugin
return; return;
} }
if (event.getKey().equals("partyDisplay")) { if (event.getKey().equals("partyDisplay"))
if (config.partyDisplay()) { {
if (config.partyDisplay())
{
overlayManager.add(partyOverlay); overlayManager.add(partyOverlay);
} else { }
else
{
overlayManager.remove(partyOverlay); overlayManager.remove(partyOverlay);
} }
} }
@@ -207,7 +215,8 @@ public class RaidsPlugin extends Plugin
public void onVarbitChanged(VarbitChanged event) public void onVarbitChanged(VarbitChanged event)
{ {
checkRaidPresence(false); checkRaidPresence(false);
if (config.partyDisplay()) { if (config.partyDisplay())
{
updatePartyMembers(false); updatePartyMembers(false);
} }
} }
@@ -221,22 +230,24 @@ public class RaidsPlugin extends Plugin
if (message.startsWith(RAID_START_MESSAGE)) if (message.startsWith(RAID_START_MESSAGE))
{ {
if (config.raidsTimer()) { if (config.raidsTimer())
{
timer = new RaidsTimer(spriteManager.getSprite(TAB_QUESTS_BROWN_RAIDING_PARTY, 0), this, Instant.now()); timer = new RaidsTimer(spriteManager.getSprite(TAB_QUESTS_BROWN_RAIDING_PARTY, 0), this, Instant.now());
infoBoxManager.addInfoBox(timer); infoBoxManager.addInfoBox(timer);
} }
if (config.partyDisplay()) { if (config.partyDisplay())
// Base this on visible players since party size shows people outside the lobby {
// and they did not get to come on the raid // Base this on visible players since party size shows people outside the lobby
List<Player> players = client.getPlayers(); // and they did not get to come on the raid
startPlayerCount = players.size(); List<Player> players = client.getPlayers();
startPlayerCount = players.size();
partyMembers.clear(); partyMembers.clear();
startingPartyMembers.clear(); startingPartyMembers.clear();
missingPartyMembers.clear(); missingPartyMembers.clear();
startingPartyMembers.addAll(Lists.transform(players, Player::getName)); startingPartyMembers.addAll(Lists.transform(players, Player::getName));
partyMembers.addAll(startingPartyMembers); partyMembers.addAll(startingPartyMembers);
} }
} }
@@ -261,26 +272,26 @@ public class RaidsPlugin extends Plugin
double percentage = personalPoints / (totalPoints / 100.0); double percentage = personalPoints / (totalPoints / 100.0);
String chatMessage = new ChatMessageBuilder() String chatMessage = new ChatMessageBuilder()
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append("Total points: ") .append("Total points: ")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append(POINTS_FORMAT.format(totalPoints)) .append(POINTS_FORMAT.format(totalPoints))
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append(", Personal points: ") .append(", Personal points: ")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append(POINTS_FORMAT.format(personalPoints)) .append(POINTS_FORMAT.format(personalPoints))
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append(" (") .append(" (")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append(DECIMAL_FORMAT.format(percentage)) .append(DECIMAL_FORMAT.format(percentage))
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append("%)") .append("%)")
.build(); .build();
chatMessageManager.queue(QueuedMessage.builder() chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.CLANCHAT_INFO) .type(ChatMessageType.CLANCHAT_INFO)
.runeLiteFormattedMessage(chatMessage) .runeLiteFormattedMessage(chatMessage)
.build()); .build());
} }
} }
} }
@@ -293,48 +304,59 @@ public class RaidsPlugin extends Plugin
if (entry.getMenuAction() == MenuAction.RUNELITE_OVERLAY && if (entry.getMenuAction() == MenuAction.RUNELITE_OVERLAY &&
entry.getTarget().equals("Raids party overlay")) entry.getTarget().equals("Raids party overlay"))
{ {
switch (entry.getOption()) { switch (entry.getOption())
{
case RaidsPartyOverlay.PARTY_OVERLAY_RESET: case RaidsPartyOverlay.PARTY_OVERLAY_RESET:
startingPartyMembers.clear(); startingPartyMembers.clear();
updatePartyMembers(true);
missingPartyMembers.clear();
break;
case RaidsPartyOverlay.PARTY_OVERLAY_REFRESH:
updatePartyMembers(true); updatePartyMembers(true);
missingPartyMembers.clear();
break; break;
case RaidsPartyOverlay.PARTY_OVERLAY_REFRESH:
updatePartyMembers(true);
break;
default: default:
break; break;
} }
} }
} }
private void updatePartyMembers(boolean force) { private void updatePartyMembers(boolean force)
{
int partySize = client.getVar(Varbits.RAID_PARTY_SIZE); int partySize = client.getVar(Varbits.RAID_PARTY_SIZE);
if (partySize <= 0) { if (partySize <= 0)
{
return; return;
} }
if (startingPartyMembers.size() == partySize && !force) { if (startingPartyMembers.size() == partySize && !force)
{
// Skip update if the part is as big as when we started // Skip update if the part is as big as when we started
missingPartyMembers.clear(); // Clear missing members in case someone came back missingPartyMembers.clear(); // Clear missing members in case someone came back
return; return;
} }
// Only update while in raid // Only update while in raid
if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1 || force) { if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1 || force)
{
Widget[] widgets; Widget[] widgets;
try { try
{
widgets = client.getWidget(WidgetInfo.RAIDING_PARTY).getStaticChildren()[2].getStaticChildren()[3].getDynamicChildren(); widgets = client.getWidget(WidgetInfo.RAIDING_PARTY).getStaticChildren()[2].getStaticChildren()[3].getDynamicChildren();
} catch (NullPointerException e) { }
catch (NullPointerException e)
{
return; // Raid widget not loaded return; // Raid widget not loaded
} }
partyMembers.clear(); partyMembers.clear();
for (int i = 0; i < widgets.length; i++) { for (int i = 0; i < widgets.length; i++)
if (widgets[i] != null) { {
if (widgets[i] != null)
{
// Party members names can be found as a color tagged string in every fourth(ish) of these children // Party members names can be found as a color tagged string in every fourth(ish) of these children
String name = widgets[i].getName(); String name = widgets[i].getName();
if (name.length() > 1) { if (name.length() > 1)
{
// Clean away tag // Clean away tag
partyMembers.add(name.substring(name.indexOf('>') + 1, name.indexOf('<', 1))); partyMembers.add(name.substring(name.indexOf('>') + 1, name.indexOf('<', 1)));
} }
@@ -342,14 +364,18 @@ public class RaidsPlugin extends Plugin
} }
// If we don't have any starting members, update starting members // If we don't have any starting members, update starting members
if (startingPartyMembers.size() == 0 || force) { if (startingPartyMembers.size() == 0 || force)
{
missingPartyMembers.clear(); missingPartyMembers.clear();
startingPartyMembers.clear(); startingPartyMembers.clear();
startingPartyMembers.addAll(partyMembers); startingPartyMembers.addAll(partyMembers);
} else { }
else
{
// Check if anyone left // Check if anyone left
if (startingPartyMembers.size() > partyMembers.size()) { if (startingPartyMembers.size() > partyMembers.size())
{
missingPartyMembers.clear(); missingPartyMembers.clear();
missingPartyMembers.addAll(startingPartyMembers); missingPartyMembers.addAll(startingPartyMembers);
missingPartyMembers.removeAll(partyMembers); missingPartyMembers.removeAll(partyMembers);
@@ -420,14 +446,14 @@ public class RaidsPlugin extends Plugin
final String raidData = "[" + layout + "]: " + rooms; final String raidData = "[" + layout + "]: " + rooms;
chatMessageManager.queue(QueuedMessage.builder() chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.CLANCHAT_INFO) .type(ChatMessageType.CLANCHAT_INFO)
.runeLiteFormattedMessage(new ChatMessageBuilder() .runeLiteFormattedMessage(new ChatMessageBuilder()
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append("Layout: ") .append("Layout: ")
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append(raidData) .append(raidData)
.build()) .build())
.build()); .build());
} }
private void updateInfoBoxState() private void updateInfoBoxState()