Refactor TickCounter

This commit is contained in:
Scott Burns
2019-05-16 01:17:49 +02:00
parent 82e76a5ccb
commit f29a72ad34
4 changed files with 148 additions and 110 deletions

View File

@@ -51,7 +51,7 @@ public class SafeSpotPlugin extends Plugin
@Getter
private ArrayList<Tile> safeSpotList;
@Getter
private boolean safeSpotsRenderable = false;

View File

@@ -1,77 +1,82 @@
package net.runelite.client.plugins.tickcounter;
import java.awt.Color;
import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import java.awt.*;
@ConfigGroup("tickcounter")
public interface TickCounterConfig extends Config {
@ConfigItem(
keyName = "resetInstance",
name = "Reset on new instances",
description = "",
position = 1
)
default boolean instance()
{
return true;
}
@Alpha
@ConfigItem(
keyName = "selfColor",
name = "Your color",
description = "",
position = 4
)
default Color selfColor()
{
return Color.green;
}
@Alpha
@ConfigItem(
keyName = "totalColor",
name = "Total color",
description = "",
position = 6
)
default Color totalColor()
{
return Color.RED;
}
@Alpha
@ConfigItem(
keyName = "otherColor",
name = "Other players color",
description = "",
position = 5
)
default Color otherColor()
{
return Color.white;
}
@Alpha
@ConfigItem(
keyName = "bgColor",
name = "Background color",
description = "",
position = 3
)
default Color bgColor()
{
return new Color(70, 61, 50, 156);
}
@Alpha
@ConfigItem(
keyName = "titleColor",
name = "Title color",
description = "",
position = 2
)
default Color titleColor()
{
return Color.white;
}
public interface TickCounterConfig extends Config
{
@ConfigItem(
keyName = "resetInstance",
name = "Reset on new instances",
description = "",
position = 1
)
default boolean instance()
{
return true;
}
@Alpha
@ConfigItem(
keyName = "selfColor",
name = "Your color",
description = "",
position = 4
)
default Color selfColor()
{
return Color.green;
}
@Alpha
@ConfigItem(
keyName = "totalColor",
name = "Total color",
description = "",
position = 6
)
default Color totalColor()
{
return Color.RED;
}
@Alpha
@ConfigItem(
keyName = "otherColor",
name = "Other players color",
description = "",
position = 5
)
default Color otherColor()
{
return Color.white;
}
@Alpha
@ConfigItem(
keyName = "bgColor",
name = "Background color",
description = "",
position = 3
)
default Color bgColor()
{
return new Color(70, 61, 50, 156);
}
@Alpha
@ConfigItem(
keyName = "titleColor",
name = "Title color",
description = "",
position = 2
)
default Color titleColor()
{
return Color.white;
}
}

View File

@@ -1,15 +1,12 @@
package net.runelite.client.plugins.tickcounter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
@@ -18,7 +15,8 @@ import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
public class TickCounterOverlay extends Overlay {
public class TickCounterOverlay extends Overlay
{
private TickCounterPlugin plugin;
private TickCounterConfig config;
@@ -26,7 +24,8 @@ public class TickCounterOverlay extends Overlay {
private PanelComponent panelComponent = new PanelComponent();
@Inject
public TickCounterOverlay(TickCounterPlugin plugin,Client client,TickCounterConfig config) {
public TickCounterOverlay(TickCounterPlugin plugin, Client client, TickCounterConfig config)
{
super(plugin);
setPosition(OverlayPosition.DYNAMIC);
setPosition(OverlayPosition.DETACHED);
@@ -37,27 +36,31 @@ public class TickCounterOverlay extends Overlay {
}
@Override
public Dimension render(Graphics2D g) {
public Dimension render(Graphics2D g)
{
List<LayoutableRenderableEntity> elems = panelComponent.getChildren();
elems.clear();
panelComponent.setBackgroundColor(config.bgColor());
elems.add(TitleComponent.builder().text("Combat counter").color(config.titleColor()).build());
List<Entry<String, Integer>> list = new ArrayList<>(plugin.activity.entrySet());
list.sort(new Comparator<Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
int value = -Integer.compare(o1.getValue(), o2.getValue());
if (value == 0)
value = o1.getKey().compareTo(o2.getKey());
return value;
list.sort((o1, o2) -> {
int value = -Integer.compare(o1.getValue(), o2.getValue());
if (value == 0)
{
value = o1.getKey().compareTo(o2.getKey());
}
return value;
});
int total = 0;
for (Entry<String, Integer> e : list) {
for (Entry<String, Integer> e : list)
{
total += e.getValue();
if(e.getKey().equals(client.getLocalPlayer().getName())){
if (e.getKey().equals(client.getLocalPlayer().getName()))
{
elems.add(LineComponent.builder().leftColor(config.selfColor()).rightColor(config.selfColor()).left(e.getKey()).right(e.getValue().toString()).build());
}else{
}
else
{
elems.add(LineComponent.builder().left(e.getKey()).right(e.getValue().toString()).leftColor(config.otherColor()).rightColor(config.otherColor()).build());
}

View File

@@ -1,13 +1,11 @@
package net.runelite.client.plugins.tickcounter;
import com.google.inject.Provides;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import com.google.inject.Provides;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.Player;
@@ -23,53 +21,66 @@ import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor(name = "Tick Counter",
description = "Counts combat activity for nearby players",
enabledByDefault = false,
type = PluginType.PVP
description = "Counts combat activity for nearby players",
enabledByDefault = false,
type = PluginType.PVP
)
public class TickCounterPlugin extends Plugin {
public class TickCounterPlugin extends Plugin
{
@Inject
private OverlayManager overlayManager;
@Inject
private TickCounterConfig config;
@Inject
private Client client;
@Provides
TickCounterConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(TickCounterConfig.class);
}
@Inject
private TickCounterOverlay overlay;
Map<String, Integer> activity = new HashMap<>();
private List<Player> blowpiping = new ArrayList<>();
boolean instanced = false;
boolean prevInstance = false;
private boolean instanced = false;
private boolean prevInstance = false;
@Override
protected void startUp() throws Exception {
protected void startUp() throws Exception
{
overlayManager.add(overlay);
}
@Override
protected void shutDown() throws Exception {
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
activity.clear();
}
@Subscribe
public void onAnimationChanged(AnimationChanged e) {
public void onAnimationChanged(AnimationChanged e)
{
if (!(e.getActor() instanceof Player))
{
return;
}
Player p = (Player) e.getActor();
int weapon = -1;
if (p.getPlayerComposition() != null)
{
weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON);
}
int delta = 0;
switch (p.getAnimation()) {
switch (p.getAnimation())
{
case 7617: // rune knife
case 8194: // dragon knife
case 8291: // dragon knife spec
@@ -89,9 +100,13 @@ public class TickCounterPlugin extends Plugin {
break;
case 426: // bow shoot
if (weapon == 20997) // twisted bow
{
delta = 5;
}
else // shortbow
{
delta = 3;
}
break;
case 376: // dds poke
case 377: // dds slash
@@ -119,7 +134,8 @@ public class TickCounterPlugin extends Plugin {
delta = 4;
break;
case 393: // staff bash
if (weapon == 13652) { // claw scratch
if (weapon == 13652)
{ // claw scratch
delta = 4;
break;
}
@@ -135,9 +151,13 @@ public class TickCounterPlugin extends Plugin {
break;
case 401:
if (weapon == 13576) // dwh bop
{
delta = 6;
}
else // used by pickaxe and axe
{
delta = 5;
}
break;
case 1378:
case 7045:
@@ -158,37 +178,47 @@ public class TickCounterPlugin extends Plugin {
case 1203: // chally spec
delta = 7;
break;
case -1:
blowpiping.remove(p);
break;
case -1:
blowpiping.remove(p);
break;
}
if (delta > 0) {
if (delta > 0)
{
String name = p.getName();
this.activity.put(name, this.activity.getOrDefault(name, 0) + delta);
}
}
@Subscribe
public void onClientTick(ClientTick e) {
public void onClientTick(ClientTick e)
{
/*
* Hack for blowpipe since the AnimationChanged event doesn't fire when using a
* blowpipe because of its speed. If blowpipe animation restarts, then add 2
*/
for (Player p : blowpiping) {
for (Player p : blowpiping)
{
Actor rsp = p;
if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1) {
if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1)
{
String name = p.getName();
int activity = this.activity.getOrDefault(name, 0).intValue();
int activity = this.activity.getOrDefault(name, 0);
this.activity.put(name, activity + 2);
}
}
}
@Subscribe
public void onGameTick(GameTick tick){
if(!config.instance())return;
public void onGameTick(GameTick tick)
{
if (!config.instance())
{
return;
}
prevInstance = instanced;
instanced = client.isInInstancedRegion();
if(!prevInstance && instanced){
if (!prevInstance && instanced)
{
activity.clear();
}
}