Makes the player count overlay only show up in PvP areas (#691)

* Makes the player counter overlay only show up in wilderness, pvp worlds,
or clan wars

Signed-off-by: PKLite <stonewall@pklite.xyz>

* Include deadman mode worlds

Signed-off-by: PKLite <stonewall@pklite.xyz>
This commit is contained in:
pklite
2019-06-21 23:24:00 -04:00
committed by Kyleeld
parent d0a43f0a98
commit b33852f28a
2 changed files with 35 additions and 11 deletions

View File

@@ -113,4 +113,14 @@ public enum WorldType
{
return worldTypes.stream().anyMatch(PVP_WORLD_TYPES::contains);
}
/**
* Checks to see if a collection of WorlTypes is a Deadman Mode World
* @param worldTypes The List of world types for a world
* @return true if it is deadman, false otherwise
*/
public static boolean isDeadmanWorld(final Collection<WorldType> worldTypes)
{
return worldTypes.stream().anyMatch(EnumSet.of(DEADMAN, DEADMAN_TOURNAMENT, SEASONAL_DEADMAN)::contains);
}
}

View File

@@ -16,6 +16,9 @@ import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.Arrays;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
@@ -23,18 +26,23 @@ import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.table.TableComponent;
import net.runelite.client.ui.overlay.components.table.TableElement;
import net.runelite.client.ui.overlay.components.table.TableRow;
import org.apache.commons.lang3.ArrayUtils;
public class PlayerCountOverlay extends Overlay
{
private static int[] CLAN_WARS_REGIONS = {9520, 13135, 13134, 13133, 13131, 13130, 13387, 13386};
private final PvpToolsPlugin pvpToolsPlugin;
private final PvpToolsConfig config;
private final Client client;
@Inject
public PlayerCountOverlay(PvpToolsPlugin pvpToolsPlugin, PvpToolsConfig pvpToolsConfig)
public PlayerCountOverlay(PvpToolsPlugin pvpToolsPlugin, PvpToolsConfig pvpToolsConfig, Client client)
{
this.pvpToolsPlugin = pvpToolsPlugin;
this.config = pvpToolsConfig;
this.client = client;
setLayer(OverlayLayer.ABOVE_WIDGETS);
setPriority(OverlayPriority.HIGHEST);
setPosition(OverlayPosition.TOP_LEFT);
@@ -46,17 +54,23 @@ public class PlayerCountOverlay extends Overlay
{
if (config.countPlayers())
{
TableComponent tableComponent = new TableComponent();
TableElement[] firstRowElements = {
if ((client.getVar(Varbits.IN_WILDERNESS) == 1) || WorldType.isPvpWorld(client.getWorldType())
|| ArrayUtils.contains(CLAN_WARS_REGIONS, client.getMapRegions()[0]) ||
WorldType.isDeadmanWorld(client.getWorldType()))
{
// Make this stop showing up when its not relevant
TableComponent tableComponent = new TableComponent();
TableElement[] firstRowElements = {
TableElement.builder().content("Friendly").color(Color.GREEN).build(),
TableElement.builder().content(String.valueOf(pvpToolsPlugin.getFriendlyPlayerCount())).build()};
TableRow firstRow = TableRow.builder().elements(Arrays.asList(firstRowElements)).build();
TableElement[] secondRowElements = {
TableElement.builder().content("Enemy").color(Color.RED).build(),
TableElement.builder().content(String.valueOf(pvpToolsPlugin.getEnemyPlayerCount())).build()};
TableRow secondRow = TableRow.builder().elements(Arrays.asList(secondRowElements)).build();
tableComponent.addRows(firstRow, secondRow);
return tableComponent.render(graphics);
TableElement.builder().content(String.valueOf(pvpToolsPlugin.getFriendlyPlayerCount())).build()};
TableRow firstRow = TableRow.builder().elements(Arrays.asList(firstRowElements)).build();
TableElement[] secondRowElements = {
TableElement.builder().content("Enemy").color(Color.RED).build(),
TableElement.builder().content(String.valueOf(pvpToolsPlugin.getEnemyPlayerCount())).build()};
TableRow secondRow = TableRow.builder().elements(Arrays.asList(secondRowElements)).build();
tableComponent.addRows(firstRow, secondRow);
return tableComponent.render(graphics);
}
}
return null;
}