Refactor TickCounter
This commit is contained in:
@@ -51,7 +51,7 @@ public class SafeSpotPlugin extends Plugin
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private ArrayList<Tile> safeSpotList;
|
private ArrayList<Tile> safeSpotList;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private boolean safeSpotsRenderable = false;
|
private boolean safeSpotsRenderable = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,77 +1,82 @@
|
|||||||
package net.runelite.client.plugins.tickcounter;
|
package net.runelite.client.plugins.tickcounter;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import net.runelite.client.config.Alpha;
|
import net.runelite.client.config.Alpha;
|
||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
@ConfigGroup("tickcounter")
|
@ConfigGroup("tickcounter")
|
||||||
public interface TickCounterConfig extends Config {
|
public interface TickCounterConfig extends Config
|
||||||
@ConfigItem(
|
{
|
||||||
keyName = "resetInstance",
|
@ConfigItem(
|
||||||
name = "Reset on new instances",
|
keyName = "resetInstance",
|
||||||
description = "",
|
name = "Reset on new instances",
|
||||||
position = 1
|
description = "",
|
||||||
)
|
position = 1
|
||||||
default boolean instance()
|
)
|
||||||
{
|
default boolean instance()
|
||||||
return true;
|
{
|
||||||
}
|
return true;
|
||||||
@Alpha
|
}
|
||||||
@ConfigItem(
|
|
||||||
keyName = "selfColor",
|
@Alpha
|
||||||
name = "Your color",
|
@ConfigItem(
|
||||||
description = "",
|
keyName = "selfColor",
|
||||||
position = 4
|
name = "Your color",
|
||||||
)
|
description = "",
|
||||||
default Color selfColor()
|
position = 4
|
||||||
{
|
)
|
||||||
return Color.green;
|
default Color selfColor()
|
||||||
}
|
{
|
||||||
@Alpha
|
return Color.green;
|
||||||
@ConfigItem(
|
}
|
||||||
keyName = "totalColor",
|
|
||||||
name = "Total color",
|
@Alpha
|
||||||
description = "",
|
@ConfigItem(
|
||||||
position = 6
|
keyName = "totalColor",
|
||||||
)
|
name = "Total color",
|
||||||
default Color totalColor()
|
description = "",
|
||||||
{
|
position = 6
|
||||||
return Color.RED;
|
)
|
||||||
}
|
default Color totalColor()
|
||||||
@Alpha
|
{
|
||||||
@ConfigItem(
|
return Color.RED;
|
||||||
keyName = "otherColor",
|
}
|
||||||
name = "Other players color",
|
|
||||||
description = "",
|
@Alpha
|
||||||
position = 5
|
@ConfigItem(
|
||||||
)
|
keyName = "otherColor",
|
||||||
default Color otherColor()
|
name = "Other players color",
|
||||||
{
|
description = "",
|
||||||
return Color.white;
|
position = 5
|
||||||
}
|
)
|
||||||
@Alpha
|
default Color otherColor()
|
||||||
@ConfigItem(
|
{
|
||||||
keyName = "bgColor",
|
return Color.white;
|
||||||
name = "Background color",
|
}
|
||||||
description = "",
|
|
||||||
position = 3
|
@Alpha
|
||||||
)
|
@ConfigItem(
|
||||||
default Color bgColor()
|
keyName = "bgColor",
|
||||||
{
|
name = "Background color",
|
||||||
return new Color(70, 61, 50, 156);
|
description = "",
|
||||||
}
|
position = 3
|
||||||
@Alpha
|
)
|
||||||
@ConfigItem(
|
default Color bgColor()
|
||||||
keyName = "titleColor",
|
{
|
||||||
name = "Title color",
|
return new Color(70, 61, 50, 156);
|
||||||
description = "",
|
}
|
||||||
position = 2
|
|
||||||
)
|
@Alpha
|
||||||
default Color titleColor()
|
@ConfigItem(
|
||||||
{
|
keyName = "titleColor",
|
||||||
return Color.white;
|
name = "Title color",
|
||||||
}
|
description = "",
|
||||||
|
position = 2
|
||||||
|
)
|
||||||
|
default Color titleColor()
|
||||||
|
{
|
||||||
|
return Color.white;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package net.runelite.client.plugins.tickcounter;
|
package net.runelite.client.plugins.tickcounter;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
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.PanelComponent;
|
||||||
import net.runelite.client.ui.overlay.components.TitleComponent;
|
import net.runelite.client.ui.overlay.components.TitleComponent;
|
||||||
|
|
||||||
public class TickCounterOverlay extends Overlay {
|
public class TickCounterOverlay extends Overlay
|
||||||
|
{
|
||||||
|
|
||||||
private TickCounterPlugin plugin;
|
private TickCounterPlugin plugin;
|
||||||
private TickCounterConfig config;
|
private TickCounterConfig config;
|
||||||
@@ -26,7 +24,8 @@ public class TickCounterOverlay extends Overlay {
|
|||||||
private PanelComponent panelComponent = new PanelComponent();
|
private PanelComponent panelComponent = new PanelComponent();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TickCounterOverlay(TickCounterPlugin plugin,Client client,TickCounterConfig config) {
|
public TickCounterOverlay(TickCounterPlugin plugin, Client client, TickCounterConfig config)
|
||||||
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setPosition(OverlayPosition.DETACHED);
|
setPosition(OverlayPosition.DETACHED);
|
||||||
@@ -37,27 +36,31 @@ public class TickCounterOverlay extends Overlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D g) {
|
public Dimension render(Graphics2D g)
|
||||||
|
{
|
||||||
List<LayoutableRenderableEntity> elems = panelComponent.getChildren();
|
List<LayoutableRenderableEntity> elems = panelComponent.getChildren();
|
||||||
elems.clear();
|
elems.clear();
|
||||||
panelComponent.setBackgroundColor(config.bgColor());
|
panelComponent.setBackgroundColor(config.bgColor());
|
||||||
elems.add(TitleComponent.builder().text("Combat counter").color(config.titleColor()).build());
|
elems.add(TitleComponent.builder().text("Combat counter").color(config.titleColor()).build());
|
||||||
List<Entry<String, Integer>> list = new ArrayList<>(plugin.activity.entrySet());
|
List<Entry<String, Integer>> list = new ArrayList<>(plugin.activity.entrySet());
|
||||||
list.sort(new Comparator<Entry<String, Integer>>() {
|
list.sort((o1, o2) -> {
|
||||||
@Override
|
int value = -Integer.compare(o1.getValue(), o2.getValue());
|
||||||
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
|
if (value == 0)
|
||||||
int value = -Integer.compare(o1.getValue(), o2.getValue());
|
{
|
||||||
if (value == 0)
|
value = o1.getKey().compareTo(o2.getKey());
|
||||||
value = o1.getKey().compareTo(o2.getKey());
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
return value;
|
||||||
});
|
});
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (Entry<String, Integer> e : list) {
|
for (Entry<String, Integer> e : list)
|
||||||
|
{
|
||||||
total += e.getValue();
|
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());
|
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());
|
elems.add(LineComponent.builder().left(e.getKey()).right(e.getValue().toString()).leftColor(config.otherColor()).rightColor(config.otherColor()).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package net.runelite.client.plugins.tickcounter;
|
package net.runelite.client.plugins.tickcounter;
|
||||||
|
|
||||||
|
import com.google.inject.Provides;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import net.runelite.api.Actor;
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
@@ -23,53 +21,66 @@ import net.runelite.client.plugins.PluginType;
|
|||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
|
|
||||||
@PluginDescriptor(name = "Tick Counter",
|
@PluginDescriptor(name = "Tick Counter",
|
||||||
description = "Counts combat activity for nearby players",
|
description = "Counts combat activity for nearby players",
|
||||||
enabledByDefault = false,
|
enabledByDefault = false,
|
||||||
type = PluginType.PVP
|
type = PluginType.PVP
|
||||||
)
|
)
|
||||||
public class TickCounterPlugin extends Plugin {
|
public class TickCounterPlugin extends Plugin
|
||||||
|
{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private TickCounterConfig config;
|
private TickCounterConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
TickCounterConfig provideConfig(ConfigManager configManager)
|
TickCounterConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(TickCounterConfig.class);
|
return configManager.getConfig(TickCounterConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private TickCounterOverlay overlay;
|
private TickCounterOverlay overlay;
|
||||||
|
|
||||||
Map<String, Integer> activity = new HashMap<>();
|
Map<String, Integer> activity = new HashMap<>();
|
||||||
|
|
||||||
private List<Player> blowpiping = new ArrayList<>();
|
private List<Player> blowpiping = new ArrayList<>();
|
||||||
boolean instanced = false;
|
private boolean instanced = false;
|
||||||
boolean prevInstance = false;
|
private boolean prevInstance = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception {
|
protected void startUp() throws Exception
|
||||||
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception {
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
activity.clear();
|
activity.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAnimationChanged(AnimationChanged e) {
|
public void onAnimationChanged(AnimationChanged e)
|
||||||
|
{
|
||||||
if (!(e.getActor() instanceof Player))
|
if (!(e.getActor() instanceof Player))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Player p = (Player) e.getActor();
|
Player p = (Player) e.getActor();
|
||||||
int weapon = -1;
|
int weapon = -1;
|
||||||
if (p.getPlayerComposition() != null)
|
if (p.getPlayerComposition() != null)
|
||||||
|
{
|
||||||
weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON);
|
weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON);
|
||||||
|
}
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
switch (p.getAnimation()) {
|
switch (p.getAnimation())
|
||||||
|
{
|
||||||
case 7617: // rune knife
|
case 7617: // rune knife
|
||||||
case 8194: // dragon knife
|
case 8194: // dragon knife
|
||||||
case 8291: // dragon knife spec
|
case 8291: // dragon knife spec
|
||||||
@@ -89,9 +100,13 @@ public class TickCounterPlugin extends Plugin {
|
|||||||
break;
|
break;
|
||||||
case 426: // bow shoot
|
case 426: // bow shoot
|
||||||
if (weapon == 20997) // twisted bow
|
if (weapon == 20997) // twisted bow
|
||||||
|
{
|
||||||
delta = 5;
|
delta = 5;
|
||||||
|
}
|
||||||
else // shortbow
|
else // shortbow
|
||||||
|
{
|
||||||
delta = 3;
|
delta = 3;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 376: // dds poke
|
case 376: // dds poke
|
||||||
case 377: // dds slash
|
case 377: // dds slash
|
||||||
@@ -119,7 +134,8 @@ public class TickCounterPlugin extends Plugin {
|
|||||||
delta = 4;
|
delta = 4;
|
||||||
break;
|
break;
|
||||||
case 393: // staff bash
|
case 393: // staff bash
|
||||||
if (weapon == 13652) { // claw scratch
|
if (weapon == 13652)
|
||||||
|
{ // claw scratch
|
||||||
delta = 4;
|
delta = 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -135,9 +151,13 @@ public class TickCounterPlugin extends Plugin {
|
|||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
if (weapon == 13576) // dwh bop
|
if (weapon == 13576) // dwh bop
|
||||||
|
{
|
||||||
delta = 6;
|
delta = 6;
|
||||||
|
}
|
||||||
else // used by pickaxe and axe
|
else // used by pickaxe and axe
|
||||||
|
{
|
||||||
delta = 5;
|
delta = 5;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1378:
|
case 1378:
|
||||||
case 7045:
|
case 7045:
|
||||||
@@ -158,37 +178,47 @@ public class TickCounterPlugin extends Plugin {
|
|||||||
case 1203: // chally spec
|
case 1203: // chally spec
|
||||||
delta = 7;
|
delta = 7;
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
blowpiping.remove(p);
|
blowpiping.remove(p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (delta > 0) {
|
if (delta > 0)
|
||||||
|
{
|
||||||
String name = p.getName();
|
String name = p.getName();
|
||||||
this.activity.put(name, this.activity.getOrDefault(name, 0) + delta);
|
this.activity.put(name, this.activity.getOrDefault(name, 0) + delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onClientTick(ClientTick e) {
|
public void onClientTick(ClientTick e)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Hack for blowpipe since the AnimationChanged event doesn't fire when using a
|
* 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
|
* blowpipe because of its speed. If blowpipe animation restarts, then add 2
|
||||||
*/
|
*/
|
||||||
for (Player p : blowpiping) {
|
for (Player p : blowpiping)
|
||||||
|
{
|
||||||
Actor rsp = p;
|
Actor rsp = p;
|
||||||
if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1) {
|
if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1)
|
||||||
|
{
|
||||||
String name = p.getName();
|
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);
|
this.activity.put(name, activity + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick tick){
|
public void onGameTick(GameTick tick)
|
||||||
if(!config.instance())return;
|
{
|
||||||
|
if (!config.instance())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
prevInstance = instanced;
|
prevInstance = instanced;
|
||||||
instanced = client.isInInstancedRegion();
|
instanced = client.isInInstancedRegion();
|
||||||
if(!prevInstance && instanced){
|
if (!prevInstance && instanced)
|
||||||
|
{
|
||||||
activity.clear();
|
activity.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user