Refactor PvpTools
This commit is contained in:
@@ -9,20 +9,26 @@
|
||||
|
||||
package net.runelite.client.plugins.pvptools;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
|
||||
public class CurrentPlayersJFrame extends JFrame
|
||||
{
|
||||
|
||||
public JList currentPlayersJList;
|
||||
public JList<Object> currentPlayersJList;
|
||||
|
||||
CurrentPlayersJFrame(Client client, PvpToolsPlugin pvpToolsPlugin, List<String> list)
|
||||
{
|
||||
@@ -35,7 +41,7 @@ public class CurrentPlayersJFrame extends JFrame
|
||||
JButton refreshJButton = new JButton("Refresh");
|
||||
refreshJButton.addActionListener(pvpToolsPlugin.currentPlayersActionListener);
|
||||
JButton copyJButton = new JButton("Copy List");
|
||||
currentPlayersJList = new JList(list.toArray());
|
||||
currentPlayersJList = new JList<>(list.toArray());
|
||||
ActionListener copyButtonActionListener = e ->
|
||||
{
|
||||
StringSelection stringSelection;
|
||||
|
||||
@@ -10,28 +10,25 @@
|
||||
package net.runelite.client.plugins.pvptools;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import net.runelite.api.ClanMember;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
|
||||
public class MissingPlayersJFrame extends JFrame
|
||||
{
|
||||
|
||||
public JList missingPlayersJList;
|
||||
public JList<Object> missingPlayersJList;
|
||||
|
||||
MissingPlayersJFrame(Client client, PvpToolsPlugin pvpToolsPlugin, List<String> list)
|
||||
{
|
||||
@@ -44,7 +41,7 @@ public class MissingPlayersJFrame extends JFrame
|
||||
JButton refreshJButton = new JButton("Refresh");
|
||||
refreshJButton.addActionListener(pvpToolsPlugin.playersButtonActionListener);
|
||||
JButton copyJButton = new JButton("Copy List");
|
||||
missingPlayersJList = new JList(list.toArray());
|
||||
missingPlayersJList = new JList<>(list.toArray());
|
||||
ActionListener copyButtonActionListener = e ->
|
||||
{
|
||||
StringSelection stringSelection;
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
package net.runelite.client.plugins.pvptools;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.security.Key;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
@@ -33,8 +31,7 @@ public interface PvpToolsConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "countOverHeads",
|
||||
name = "Count Enemy Overheads",
|
||||
description = "Counts the number of each protection prayer attackable targets not in your CC are currently" +
|
||||
" using",
|
||||
description = "Counts the number of each protection prayer attackable targets not in your CC are currently using",
|
||||
position = 4
|
||||
)
|
||||
default boolean countOverHeads()
|
||||
@@ -63,7 +60,7 @@ public interface PvpToolsConfig extends Config
|
||||
{
|
||||
return Keybind.NOT_SET;
|
||||
}
|
||||
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "renderSelfHotkey",
|
||||
name = "Render Self Hotkey",
|
||||
@@ -100,11 +97,11 @@ public interface PvpToolsConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "levelRangeAttackOptions",
|
||||
name = "Moves Other Attack Options",
|
||||
description = "Moves the attack option for people that are outside your level range",
|
||||
position = 10,
|
||||
group = "Right-Click Attack Options"
|
||||
keyName = "levelRangeAttackOptions",
|
||||
name = "Moves Other Attack Options",
|
||||
description = "Moves the attack option for people that are outside your level range",
|
||||
position = 10,
|
||||
group = "Right-Click Attack Options"
|
||||
)
|
||||
default boolean levelRangeAttackOptions()
|
||||
{
|
||||
@@ -125,18 +122,19 @@ public interface PvpToolsConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "missingPlayers",
|
||||
name = "Missing CC Players",
|
||||
description = "Adds a button to the PvP Tools panel that opens a window showing which CC members are not at" +
|
||||
" the current players location",
|
||||
description = "Adds a button to the PvP Tools panel that opens a window showing which CC members are not at the current players location",
|
||||
position = 15
|
||||
)
|
||||
default boolean missingPlayersEnabled() { return true; }
|
||||
default boolean missingPlayersEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "currentPlayers",
|
||||
name = "Current CC Players",
|
||||
description = "Adds a button to the PvP Tools panel that opens a window showing which CC members currently at" +
|
||||
" the players location",
|
||||
position = 16
|
||||
keyName = "currentPlayers",
|
||||
name = "Current CC Players",
|
||||
description = "Adds a button to the PvP Tools panel that opens a window showing which CC members currently at the players location",
|
||||
position = 16
|
||||
)
|
||||
default boolean currentPlayersEnabled()
|
||||
{
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
|
||||
package net.runelite.client.plugins.pvptools;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
@@ -40,7 +39,7 @@ public class PvpToolsOverlay extends Overlay
|
||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||
setPriority(OverlayPriority.HIGH);
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,21 +33,18 @@ public class PvpToolsPanel extends PluginPanel
|
||||
|
||||
private final JLabel loggedLabel = new JLabel();
|
||||
private final JRichTextPane emailLabel = new JRichTextPane();
|
||||
public JLabel numCC = new JLabel();
|
||||
public JLabel numOther = new JLabel();
|
||||
public JLabel numMageJLabel = new JLabel(" ");
|
||||
public JLabel numRangeJLabel = new JLabel(" ");
|
||||
public JLabel numMeleeJLabel = new JLabel(" ");
|
||||
public JLabel totalRiskLabel = new JLabel(" ");
|
||||
public JLabel riskProtectingItem = new JLabel(" ");
|
||||
public JLabel biggestItemLabel = new JLabel("Protected Item: ");
|
||||
public JButton missingPlayers = new JButton("Show missing CC members");
|
||||
public JButton currentPlayers = new JButton("Show current CC members");
|
||||
public JLabel numBrews = new JLabel();
|
||||
@Inject
|
||||
private JPanel pvpToolsPanel = new JPanel(new GridLayout(11, 1));
|
||||
JLabel numCC = new JLabel();
|
||||
JLabel numOther = new JLabel();
|
||||
JLabel numMageJLabel = new JLabel(" ");
|
||||
JLabel numRangeJLabel = new JLabel(" ");
|
||||
JLabel numMeleeJLabel = new JLabel(" ");
|
||||
JLabel totalRiskLabel = new JLabel(" ");
|
||||
JLabel riskProtectingItem = new JLabel(" ");
|
||||
JLabel biggestItemLabel = new JLabel("Protected Item: ");
|
||||
JButton missingPlayers = new JButton("Show missing CC members");
|
||||
JButton currentPlayers = new JButton("Show current CC members");
|
||||
private JLabel numBrews = new JLabel();
|
||||
private JPanel missingPlayersPanel = new JPanel();
|
||||
private JPanel currentPlayersPanel = new JPanel();
|
||||
|
||||
|
||||
public static String htmlLabel(String key, String value)
|
||||
@@ -62,7 +59,6 @@ public class PvpToolsPanel extends PluginPanel
|
||||
setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
|
||||
|
||||
|
||||
JPanel versionPanel = new JPanel();
|
||||
versionPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
versionPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
@@ -136,7 +132,7 @@ public class PvpToolsPanel extends PluginPanel
|
||||
|
||||
}
|
||||
|
||||
public void disablePlayerCount()
|
||||
void disablePlayerCount()
|
||||
{
|
||||
this.numOther.setText("Disabled");
|
||||
this.numCC.setText("Disabled");
|
||||
@@ -144,7 +140,7 @@ public class PvpToolsPanel extends PluginPanel
|
||||
this.numOther.repaint();
|
||||
}
|
||||
|
||||
public void disablePrayerCount()
|
||||
void disablePrayerCount()
|
||||
{
|
||||
this.numMageJLabel.setText("disabled");
|
||||
this.numRangeJLabel.setText("disabled");
|
||||
@@ -154,7 +150,7 @@ public class PvpToolsPanel extends PluginPanel
|
||||
this.numMeleeJLabel.repaint();
|
||||
}
|
||||
|
||||
public void disableRiskCalculator()
|
||||
void disableRiskCalculator()
|
||||
{
|
||||
this.totalRiskLabel.setText("disabled");
|
||||
this.riskProtectingItem.setText("disabled");
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.NavigableMap;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
@@ -45,13 +44,11 @@ import net.runelite.api.events.PlayerSpawned;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.game.AsyncBufferedImage;
|
||||
import net.runelite.client.game.ClanManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.plugins.clanchat.ClanChatPlugin;
|
||||
import static net.runelite.client.plugins.pvptools.PvpToolsPanel.htmlLabel;
|
||||
import net.runelite.client.ui.ClientToolbar;
|
||||
@@ -74,25 +71,30 @@ public class PvpToolsPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
PvpToolsOverlay pvpToolsOverlay;
|
||||
|
||||
boolean fallinHelperEnabled = false;
|
||||
private PvpToolsPanel panel;
|
||||
private MissingPlayersJFrame missingPlayersJFrame;
|
||||
private CurrentPlayersJFrame currentPlayersJFrame;
|
||||
private NavigationButton navButton;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private boolean attackHotKeyPressed;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private boolean hideAll;
|
||||
@Inject
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
private PvpToolsPlugin uhPvpToolsPlugin = this;
|
||||
|
||||
/**
|
||||
@@ -144,15 +146,6 @@ public class PvpToolsPlugin extends Plugin
|
||||
@Inject
|
||||
private PvpToolsConfig config;
|
||||
|
||||
@Inject
|
||||
private PluginManager pluginManager;
|
||||
|
||||
@Inject
|
||||
private ClanManager clanManager;
|
||||
|
||||
|
||||
private ClanChatPlugin clanChatPlugin;
|
||||
|
||||
/**
|
||||
* The HotKeyListener for the hot key assigned in the config that triggers the Fall In Helper feature
|
||||
*/
|
||||
@@ -163,7 +156,7 @@ public class PvpToolsPlugin extends Plugin
|
||||
toggleFallinHelper();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private final HotkeyListener renderselfHotkeyListener = new HotkeyListener(() -> config.renderSelf())
|
||||
{
|
||||
public void hotkeyPressed()
|
||||
@@ -174,23 +167,11 @@ public class PvpToolsPlugin extends Plugin
|
||||
|
||||
private int[] overheadCount = new int[]{0, 0, 0};
|
||||
|
||||
private Comparator<Item> itemPriceComparator = new Comparator<Item>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Item o1, Item o2)
|
||||
{
|
||||
return (itemManager.getItemPrice(itemManager.getItemComposition(o1.getId()).getPrice())
|
||||
- itemManager.getItemPrice(itemManager.getItemComposition(o2.getId()).getPrice()));
|
||||
}
|
||||
};
|
||||
|
||||
private String mtarget;
|
||||
|
||||
public List getMissingMembers()
|
||||
private List<String> getMissingMembers()
|
||||
{
|
||||
CopyOnWriteArrayList<Player> ccMembers = ClanChatPlugin.getClanMembers();
|
||||
ArrayList missingMembers = new ArrayList();
|
||||
for (ClanMember clanMember:client.getClanMembers())
|
||||
ArrayList<String> missingMembers = new ArrayList<>();
|
||||
for (ClanMember clanMember : client.getClanMembers())
|
||||
{
|
||||
if (!Objects.isNull(clanMember))
|
||||
{
|
||||
@@ -206,16 +187,13 @@ public class PvpToolsPlugin extends Plugin
|
||||
}
|
||||
|
||||
return missingMembers;
|
||||
|
||||
//Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername)
|
||||
//.toArray()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List getCurrentMembers()
|
||||
private List<String> getCurrentMembers()
|
||||
{
|
||||
CopyOnWriteArrayList<Player> ccMembers = ClanChatPlugin.getClanMembers();
|
||||
ArrayList currentMembers = new ArrayList();
|
||||
for (ClanMember clanMember:client.getClanMembers())
|
||||
ArrayList<String> currentMembers = new ArrayList<>();
|
||||
for (ClanMember clanMember : client.getClanMembers())
|
||||
{
|
||||
if (!Objects.isNull(clanMember))
|
||||
{
|
||||
@@ -231,13 +209,9 @@ public class PvpToolsPlugin extends Plugin
|
||||
}
|
||||
|
||||
return currentMembers;
|
||||
|
||||
//Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername)
|
||||
//.toArray()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Provides
|
||||
PvpToolsConfig config(ConfigManager configManager)
|
||||
{
|
||||
@@ -247,7 +221,6 @@ public class PvpToolsPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
|
||||
overlayManager.add(pvpToolsOverlay);
|
||||
|
||||
keyManager.registerKeyListener(fallinHotkeyListener);
|
||||
@@ -399,79 +372,56 @@ public class PvpToolsPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
|
||||
{
|
||||
if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions())
|
||||
if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions())
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN)
|
||||
return;
|
||||
}
|
||||
Player[] players = client.getCachedPlayers();
|
||||
Player player = null;
|
||||
int identifier = menuEntryAdded.getIdentifier();
|
||||
if (identifier >= 0 && identifier < players.length)
|
||||
{
|
||||
player = players[identifier];
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (attackHotKeyPressed && config.attackOptionsClan() || config.attackOptionsFriend() ||
|
||||
config.levelRangeAttackOptions())
|
||||
{
|
||||
if (config.attackOptionsFriend() && player.isFriend())
|
||||
{
|
||||
return;
|
||||
moveEntry();
|
||||
}
|
||||
Player[] players = client.getCachedPlayers();
|
||||
Player player = null;
|
||||
int identifier = menuEntryAdded.getIdentifier();
|
||||
if (identifier >= 0 && identifier < players.length)
|
||||
if (config.attackOptionsClan() && player.isClanMember())
|
||||
{
|
||||
player = players[identifier];
|
||||
moveEntry();
|
||||
}
|
||||
if (player == null)
|
||||
if (config.levelRangeAttackOptions() && !PvPUtil.isAttackable(client, player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
final String option = Text.removeTags(menuEntryAdded.getOption()).toLowerCase();
|
||||
final String mtarget = Text.removeTags(menuEntryAdded.getTarget()).toLowerCase();
|
||||
if (attackHotKeyPressed && config.attackOptionsClan() || config.attackOptionsFriend() ||
|
||||
config.levelRangeAttackOptions())
|
||||
{
|
||||
if (config.attackOptionsFriend() && player.isFriend())
|
||||
{
|
||||
moveEntry(mtarget);
|
||||
}
|
||||
if (config.attackOptionsClan() && player.isClanMember())
|
||||
{
|
||||
moveEntry(mtarget);
|
||||
}
|
||||
if (config.levelRangeAttackOptions() && !PvPUtil.isAttackable(client, player))
|
||||
{
|
||||
moveEntry(mtarget);
|
||||
}
|
||||
moveEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveEntry(String mtarget)
|
||||
private void moveEntry()
|
||||
{
|
||||
this.mtarget = mtarget;
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
|
||||
|
||||
// strip out existing <col...
|
||||
String target = lastEntry.getTarget();
|
||||
int idx = target.indexOf('>');
|
||||
if (idx != -1)
|
||||
{
|
||||
target = target.substring(idx + 1);
|
||||
}
|
||||
/*System.out.println("Contents : " + lastEntry.getTarget());
|
||||
System.out.println("Contents : " + lastEntry.getIdentifier());
|
||||
System.out.println("Contents : " + lastEntry.getOption());
|
||||
System.out.println("length : " + menuEntries.length);*/
|
||||
if (menuEntries[menuEntries.length - 1] != null)
|
||||
{
|
||||
//System.out.println(menuEntries.length + ": " + menuEntries[menuEntries.length-1]);
|
||||
}
|
||||
if (lastEntry.getOption().contains("attack".toLowerCase()))
|
||||
{
|
||||
ArrayUtils.shift(menuEntries, 1);
|
||||
//ArrayUtils.add(menuEntries, menuEntries.length - 2);
|
||||
//menuEntries = ArrayUtils.remove(menuEntries, menuEntries.length - 1);
|
||||
//menuEntrySwapperPlugin.swap("attack", option, mtarget, false);
|
||||
}
|
||||
if (lastEntry.getOption().equals("Attack"))
|
||||
{
|
||||
ArrayUtils.shift(menuEntries, 1);
|
||||
|
||||
//menuEntries = ArrayUtils.sremove(menuEntries, menuEntries.length - 1);
|
||||
//menuEntrySwapperPlugin.swap("attack", option, mtarget, false);
|
||||
}
|
||||
|
||||
client.setMenuEntries(menuEntries);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user