From 7671e61cf3bc58ea3ae421569b3146969df6b076 Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Thu, 25 Apr 2019 21:50:59 +0100 Subject: [PATCH] Removes the hotkey & attack option hiding Removes the hotkey and makes attack option hiding much more certain --- .../plugins/pvptools/PvpToolsConfig.java | 282 ++-- .../plugins/pvptools/PvpToolsPlugin.java | 1361 ++++++++--------- 2 files changed, 803 insertions(+), 840 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsConfig.java index a6a1392763..e8e53d6b6a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsConfig.java @@ -1,147 +1,135 @@ -/* - * Copyright (c) 2019. PKLite - All Rights Reserved - * Unauthorized modification, distribution, or possession of this source file, via any medium is strictly prohibited. - * Proprietary and confidential. Refer to PKLite License file for more information on - * full terms of this copyright and to determine what constitutes authorized use. - * Written by PKLite(ST0NEWALL, others) , 2019 - * - */ - -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; -import net.runelite.client.config.Keybind; - -@ConfigGroup("pvptools") -public interface PvpToolsConfig extends Config -{ - @ConfigItem( - keyName = "countPlayers", - name = "Count Players", - description = "When in PvP zones, counts the attackable players in and not in player's CC", - position = 3 - ) - default boolean countPlayers() - { - return true; - } - - @ConfigItem( - keyName = "countOverHeads", - name = "Count Enemy Overheads", - description = "Counts the number of each protection prayer attackable targets not in your CC are currently" + - " using", - position = 4 - ) - default boolean countOverHeads() - { - return true; - } - - @ConfigItem( - keyName = "fallInHelper", - name = "Fall In Helper", - description = "Hides all non-friendly player entities other than the one that is attacking you.", - position = 5 - ) - default boolean fallInHelper() - { - return true; - } - - @ConfigItem( - keyName = "hotkey", - name = "Fall In Hotkey", - description = "Turns the fall in helper on or off when you press this hotkey", - position = 6 - ) - default Keybind hotkey() - { - return Keybind.NOT_SET; - } - - @ConfigItem( - keyName = "attackOptionsClan", - name = "Move CC Attack Option", - description = "Moves the attack option for people in the same CC", - position = 7, - group = "Right-Click Attack Options" - ) - default boolean attackOptionsClan() - { - return false; - } - - @ConfigItem( - keyName = "attackOptionsFriend", - name = "Move Friend Attack Options", - description = "Moves the attack option for people on your friends list", - position = 8, - group = "Right-Click Attack Options" - ) - default boolean attackOptionsFriend() - { - return false; - } - - @ConfigItem( - keyName = "attackOptionsHotkey", - name = "Attack Option Hotkey", - description = "Enables a hotkey for attack options to disable or enable hiding quickly", - position = 10, - group = "Right-Click Attack Options" - ) - default Keybind attackOptionsHotkey() - { - return Keybind.CTRL; - } - - @ConfigItem( - keyName = "levelRangeAttackOptions", - name = "Moves Other Attack Options", - description = "Moves the attack option for people that are outside your level range", - position = 9, - group = "Right-Click Attack Options" - ) - default boolean levelRangeAttackOptions() - { - return false; - } - - @ConfigItem( - keyName = "riskCalculator", - name = "Risk Calculator", - description = "Enables a panel in the PvP Tools Panel that shows the players current risk", - position = 13 - ) - default boolean riskCalculatorEnabled() - { - return true; - } - - @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", - position = 14 - ) - 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 = 15 - ) - default boolean currentPlayersEnabled() - { - return true; - } - -} +/* + * Copyright (c) 2019. PKLite - All Rights Reserved + * Unauthorized modification, distribution, or possession of this source file, via any medium is strictly prohibited. + * Proprietary and confidential. Refer to PKLite License file for more information on + * full terms of this copyright and to determine what constitutes authorized use. + * Written by PKLite(ST0NEWALL, others) , 2019 + * + */ + +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; +import net.runelite.client.config.Keybind; + +@ConfigGroup("pvptools") +public interface PvpToolsConfig extends Config +{ + @ConfigItem( + keyName = "countPlayers", + name = "Count Players", + description = "When in PvP zones, counts the attackable players in and not in player's CC", + position = 3 + ) + default boolean countPlayers() + { + return true; + } + + @ConfigItem( + keyName = "countOverHeads", + name = "Count Enemy Overheads", + description = "Counts the number of each protection prayer attackable targets not in your CC are currently" + + " using", + position = 4 + ) + default boolean countOverHeads() + { + return true; + } + + @ConfigItem( + keyName = "fallInHelper", + name = "Fall In Helper", + description = "Hides all non-friendly player entities other than the one that is attacking you.", + position = 5 + ) + default boolean fallInHelper() + { + return true; + } + + @ConfigItem( + keyName = "hotkey", + name = "Fall In Hotkey", + description = "Turns the fall in helper on or off when you press this hotkey", + position = 6 + ) + default Keybind hotkey() + { + return Keybind.NOT_SET; + } + + @ConfigItem( + keyName = "attackOptionsClan", + name = "Move CC Attack Option", + description = "Moves the attack option for people in the same CC", + position = 7, + group = "Right-Click Attack Options" + ) + default boolean attackOptionsClan() + { + return false; + } + + @ConfigItem( + keyName = "attackOptionsFriend", + name = "Move Friend Attack Options", + description = "Moves the attack option for people on your friends list", + position = 8, + group = "Right-Click Attack Options" + ) + default boolean attackOptionsFriend() + { + return false; + } + + @ConfigItem( + keyName = "levelRangeAttackOptions", + name = "Moves Other Attack Options", + description = "Moves the attack option for people that are outside your level range", + position = 9, + group = "Right-Click Attack Options" + ) + default boolean levelRangeAttackOptions() + { + return false; + } + + @ConfigItem( + keyName = "riskCalculator", + name = "Risk Calculator", + description = "Enables a panel in the PvP Tools Panel that shows the players current risk", + position = 13 + ) + default boolean riskCalculatorEnabled() + { + return true; + } + + @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", + position = 14 + ) + 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 = 15 + ) + default boolean currentPlayersEnabled() + { + return true; + } + +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsPlugin.java index 42f8e4395f..838ba3c25a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pvptools/PvpToolsPlugin.java @@ -1,693 +1,668 @@ -/* - * Copyright (c) 2019. PKLite - All Rights Reserved - * Unauthorized modification, distribution, or possession of this source file, via any medium is strictly prohibited. - * Proprietary and confidential. Refer to PKLite License file for more information on - * full terms of this copyright and to determine what constitutes authorized use. - * Written by PKLite(ST0NEWALL, others) , 2019 - * - */ - -package net.runelite.client.plugins.pvptools; - -import com.google.inject.Provides; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.image.BufferedImage; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -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; -import lombok.Getter; -import lombok.Setter; -import net.runelite.api.ClanMember; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.InventoryID; -import net.runelite.api.Item; -import net.runelite.api.ItemComposition; -import net.runelite.api.MenuEntry; -import net.runelite.api.Player; -import net.runelite.api.SkullIcon; -import net.runelite.api.events.ConfigChanged; -import net.runelite.api.events.FocusChanged; -import net.runelite.api.events.GameStateChanged; -import net.runelite.api.events.ItemContainerChanged; -import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.PlayerDespawned; -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.PluginManager; -import net.runelite.client.plugins.PluginType; -import net.runelite.client.plugins.clanchat.ClanChatPlugin; -import static net.runelite.client.plugins.pvptools.PvpToolsPanel.htmlLabel; -import net.runelite.client.ui.ClientToolbar; -import net.runelite.client.ui.NavigationButton; -import net.runelite.client.ui.overlay.OverlayManager; -import net.runelite.client.util.HotkeyListener; -import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.PvPUtil; -import static net.runelite.client.util.StackFormatter.quantityToRSDecimalStack; -import net.runelite.client.util.Text; -import org.apache.commons.lang3.ArrayUtils; - -@PluginDescriptor( - name = "PvP Tools", - description = "Enable the PvP Tools panel", - tags = {"panel", "pvp", "pk", "pklite"}, - type = PluginType.PVP -) -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; - - /** - * ActionListener for the missing cc members and refresh buttons - */ - final ActionListener playersButtonActionListener = new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - if (missingPlayersJFrame != null) - { - missingPlayersJFrame.dispose(); - missingPlayersJFrame = null; - missingPlayersJFrame = new MissingPlayersJFrame(client, uhPvpToolsPlugin, getMissingMembers()); - } - else - { - missingPlayersJFrame = new MissingPlayersJFrame(client, uhPvpToolsPlugin, getMissingMembers()); - } - } - }; - - final ActionListener currentPlayersActionListener = new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - if (currentPlayersJFrame != null) - { - currentPlayersJFrame.dispose(); - currentPlayersJFrame = null; - currentPlayersJFrame = new CurrentPlayersJFrame(client, uhPvpToolsPlugin, getCurrentMembers()); - } - else - { - currentPlayersJFrame = new CurrentPlayersJFrame(client, uhPvpToolsPlugin, getCurrentMembers()); - } - } - }; - - - @Inject - private ClientToolbar clientToolbar; - - @Inject - private KeyManager keyManager; - - @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 - */ - private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey()) - { - public void hotkeyPressed() - { - toggleFallinHelper(); - } - }; - - - private final HotkeyListener attackOptionsHotKeyListener = new HotkeyListener(() -> config.attackOptionsHotkey()) - { - long lastPress = 0; - - @Override - public void keyPressed(KeyEvent e) - { - attackHotKeyPressed = true; - } - - @Override - public void keyReleased(KeyEvent e) - { - attackHotKeyPressed = (System.currentTimeMillis() - lastPress) < 800; - lastPress = System.currentTimeMillis(); - } - }; - - private int[] overheadCount = new int[]{0, 0, 0}; - - private Comparator itemPriceComparator = new Comparator() - { - @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() - { - CopyOnWriteArrayList ccMembers = ClanChatPlugin.getClanMembers(); - ArrayList missingMembers = new ArrayList(); - for (ClanMember clanMember:client.getClanMembers()) - { - if (!Objects.isNull(clanMember)) - { - List arrayList = ccMembers.stream().map(player -> Text.removeTags(Text.standardize(player.getName()))).collect(Collectors.toList()); - if (!arrayList.contains(Text.removeTags(Text.standardize(clanMember.getUsername())))) - { - if (!missingMembers.contains(clanMember.getUsername())) - { - missingMembers.add("[W" + clanMember.getWorld() + "] - " + clanMember.getUsername()); - } - } - } - } - - return missingMembers; - - //Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername) - //.toArray()).collect(Collectors.toList()); - } - - public List getCurrentMembers() - { - CopyOnWriteArrayList ccMembers = ClanChatPlugin.getClanMembers(); - ArrayList currentMembers = new ArrayList(); - for (ClanMember clanMember:client.getClanMembers()) - { - if (!Objects.isNull(clanMember)) - { - List arrayList = ccMembers.stream().map(player -> Text.removeTags(Text.standardize(player.getName()))).collect(Collectors.toList()); - if (arrayList.contains(Text.removeTags(Text.standardize(clanMember.getUsername())))) - { - if (!currentMembers.contains(clanMember.getUsername())) - { - currentMembers.add(clanMember.getUsername()); - } - } - } - } - - return currentMembers; - - //Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername) - //.toArray()).collect(Collectors.toList()); - } - - - - @Provides - PvpToolsConfig config(ConfigManager configManager) - { - return configManager.getConfig(PvpToolsConfig.class); - } - - @Override - protected void startUp() throws Exception - { - - overlayManager.add(pvpToolsOverlay); - - keyManager.registerKeyListener(hotkeyListener); - final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "skull.png"); - - panel = new PvpToolsPanel(); - panel.init(); - - navButton = NavigationButton.builder() - .tooltip("PvP Tools") - .icon(icon) - .priority(5) - .panel(panel) - .build(); - - panel.missingPlayers.addActionListener(playersButtonActionListener); - panel.currentPlayers.addActionListener(currentPlayersActionListener); - clientToolbar.addNavigation(navButton); - - - keyManager.registerKeyListener(attackOptionsHotKeyListener); - - if (config.missingPlayersEnabled()) - { - panel.missingPlayers.setVisible(true); - } - - if (config.currentPlayersEnabled()) - { - panel.currentPlayers.setVisible(true); - } - } - - @Override - protected void shutDown() throws Exception - { - overlayManager.remove(pvpToolsOverlay); - keyManager.unregisterKeyListener(hotkeyListener); - keyManager.unregisterKeyListener(attackOptionsHotKeyListener); - clientToolbar.removeNavigation(navButton); - } - - @Subscribe - public void onConfigChanged(ConfigChanged configChanged) - { - if (configChanged.getGroup().equals("pvptools")) - { - switch (configChanged.getKey()) - { - case "countPlayers": - if (config.countPlayers()) - { - updatePlayers(); - } - if (!config.countPlayers()) - { - panel.disablePlayerCount(); - } - break; - case "countOverHeads": - if (config.countOverHeads()) - { - countOverHeads(); - } - if (!config.countOverHeads()) - { - panel.disablePrayerCount(); - } - break; - case "riskCalculator": - if (config.riskCalculatorEnabled()) - { - getCarriedWealth(); - } - if (!config.riskCalculatorEnabled()) - { - panel.disableRiskCalculator(); - } - break; - case "missingPlayers": - if (config.missingPlayersEnabled()) - { - panel.missingPlayers.setVisible(true); - } - break; - case "currentPlayers": - if (config.currentPlayersEnabled()) - { - panel.currentPlayers.setVisible(true); - } - break; - default: - break; - } - } - } - - @Subscribe - public void onItemContainerChanged(ItemContainerChanged event) - { - if (event.getItemContainer().equals(client.getItemContainer(InventoryID.INVENTORY)) && - config.riskCalculatorEnabled()) - { - getCarriedWealth(); - } - } - - @Subscribe - public void onGameStateChanged(GameStateChanged event) - { - if (event.getGameState().equals(GameState.LOGGED_IN) && config.riskCalculatorEnabled()) - { - getCarriedWealth(); - } - if (event.getGameState().equals(GameState.LOGGED_IN)) - { - if (config.countPlayers()) - { - updatePlayers(); - } - } - } - - @Subscribe - public void onPlayerSpawned(PlayerSpawned event) - { - if (config.countPlayers() && PvPUtil.isAttackable(client, event.getPlayer())) - { - updatePlayers(); - } - if (config.countOverHeads()) - { - countOverHeads(); - } - } - - @Subscribe - public void onPlayerDespawned(PlayerDespawned event) - { - if (config.countPlayers() && PvPUtil.isAttackable(client, event.getPlayer())) - { - updatePlayers(); - } - if (config.countOverHeads()) - { - countOverHeads(); - } - } - - @Subscribe - public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) - { - if (!attackHotKeyPressed) - { - if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions()) - { - 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; - } - 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); - } - } - } - } - } - - - private void moveEntry(String mtarget) - { - this.mtarget = mtarget; - MenuEntry[] menuEntries = client.getMenuEntries(); - MenuEntry lastEntry = menuEntries[menuEntries.length - 1]; - - // strip out existing '); - 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); - - } - - @Subscribe - public void onFocusChanged(FocusChanged focusChanged) - { - if (!focusChanged.isFocused()) - { - setAttackHotKeyPressed(false); - } - } - - /** - * Enables or disables the fall in helper feature - */ - private void toggleFallinHelper() - { - if (!fallinHelperEnabled) - { - client.setIsHidingEntities(true); - client.setPlayersHidden(true); - fallinHelperEnabled = true; - } - else - { - client.setIsHidingEntities(false); - client.setPlayersHidden(false); - fallinHelperEnabled = false; - } - - } - - /** - * Updates the PvP Tools panel with the numbers for enemy protection prayers - */ - private void updatePrayerNumbers() - { - panel.numMageJLabel.setText(htmlLabel("Enemies Praying Mage: ", String.valueOf(overheadCount[0]))); - panel.numRangeJLabel.setText(htmlLabel("Enemies Praying Range: ", String.valueOf(overheadCount[1]))); - panel.numMeleeJLabel.setText(htmlLabel("Enemies Praying Melee: ", String.valueOf(overheadCount[2]))); - panel.numMageJLabel.repaint(); - panel.numRangeJLabel.repaint(); - panel.numMeleeJLabel.repaint(); - } - - /** - * - */ - private void updatePlayers() - { - if (config.countPlayers()) - { - int cc = 0; - int other = 0; - for (Player p : client.getPlayers()) - { - if (Objects.nonNull(p)) - { - if (PvPUtil.isAttackable(client, p)) - { - if (p.isClanMember()) - { - cc++; - } - else - { - other++; - } - } - } - } - - panel.numOther.setText(htmlLabel("Other Player Count: ", String.valueOf(other))); - panel.numCC.setText(htmlLabel("Friendly Player Count: ", String.valueOf(cc))); - panel.numCC.repaint(); - panel.numOther.repaint(); - } - } - - private void countOverHeads() - { - overheadCount = new int[]{0, 0, 0}; - for (Player p : client.getPlayers()) - { - if (Objects.nonNull(p)) - { - if (PvPUtil.isAttackable(client, p)) - { - if (!p.isClanMember() && !(p.getOverheadIcon() == null)) - { - switch (p.getOverheadIcon()) - { - case MAGIC: - overheadCount[0]++; - break; - case RANGED: - overheadCount[1]++; - break; - case MELEE: - overheadCount[2]++; - break; - } - } - } - } - } - updatePrayerNumbers(); - } - - /** - * Calculates the player's risk based on Item Price of all items in their inventory and equipment - */ - private void getCarriedWealth() - { - if (!config.riskCalculatorEnabled()) - { - return; - } - if (client.getItemContainer(InventoryID.EQUIPMENT) == null) - { - return; - } - if (client.getItemContainer(InventoryID.INVENTORY).getItems() == null) - { - return; - } - Item[] items = ArrayUtils.addAll(Objects.requireNonNull(client.getItemContainer(InventoryID.EQUIPMENT)).getItems(), - Objects.requireNonNull(client.getItemContainer(InventoryID.INVENTORY)).getItems()); - TreeMap priceMap = new TreeMap<>(Comparator.comparingInt(Integer::intValue)); - int wealth = 0; - for (Item i : items) - { - int value = (itemManager.getItemPrice(i.getId()) * i.getQuantity()); - - final ItemComposition itemComposition = itemManager.getItemComposition(i.getId()); - if (!itemComposition.isTradeable() && value == 0) - { - value = itemComposition.getPrice() * i.getQuantity(); - priceMap.put(value, i); - } - else - { - value = itemManager.getItemPrice(i.getId()) * i.getQuantity(); - if (i.getId() > 0 && value > 0) - { - priceMap.put(value, i); - } - } - wealth += value; - } - panel.totalRiskLabel.setText(htmlLabel("Total risk: ", quantityToRSDecimalStack(wealth))); - panel.totalRiskLabel.repaint(); - - int itemLimit = 0; - if (client.getLocalPlayer().getSkullIcon() != null) - { - if (client.getLocalPlayer().getSkullIcon() == SkullIcon.SKULL) - { - itemLimit = 1; - } - } - if (client.getLocalPlayer().getSkullIcon() == null) - { - itemLimit = 4; - } - - AsyncBufferedImage itemImage = null; - - NavigableMap descendingMap = priceMap.descendingMap(); - - for (int i = 0; i < itemLimit; i++) - { - if (i == 0) - { - if (!descendingMap.isEmpty()) - { - itemImage = itemManager.getImage(descendingMap.pollFirstEntry().getValue().getId()); - } - } - else - { - if (!descendingMap.isEmpty()) - { - itemManager.getItemComposition(priceMap.descendingMap().pollFirstEntry().getValue().getId()) - .getName(); - } - } - } - panel.riskProtectingItem.setText(htmlLabel("Risk Protecting Item: ", - quantityToRSDecimalStack(descendingMap.keySet().stream().mapToInt(Integer::intValue).sum()))); - panel.riskProtectingItem.repaint(); - - panel.biggestItemLabel.setText("Most Valuable Item: "); - if (itemImage != null) - { - itemImage.addTo(panel.biggestItemLabel); - } - panel.biggestItemLabel.repaint(); - } - -} +/* + * Copyright (c) 2019. PKLite - All Rights Reserved + * Unauthorized modification, distribution, or possession of this source file, via any medium is strictly prohibited. + * Proprietary and confidential. Refer to PKLite License file for more information on + * full terms of this copyright and to determine what constitutes authorized use. + * Written by PKLite(ST0NEWALL, others) , 2019 + * + */ + +package net.runelite.client.plugins.pvptools; + +import com.google.inject.Provides; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +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; +import lombok.Getter; +import lombok.Setter; +import net.runelite.api.ClanMember; +import net.runelite.api.Client; +import net.runelite.api.GameState; +import net.runelite.api.InventoryID; +import net.runelite.api.Item; +import net.runelite.api.ItemComposition; +import net.runelite.api.MenuEntry; +import net.runelite.api.Player; +import net.runelite.api.SkullIcon; +import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.FocusChanged; +import net.runelite.api.events.GameStateChanged; +import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.MenuEntryAdded; +import net.runelite.api.events.PlayerDespawned; +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.PluginManager; +import net.runelite.client.plugins.PluginType; +import net.runelite.client.plugins.clanchat.ClanChatPlugin; +import static net.runelite.client.plugins.pvptools.PvpToolsPanel.htmlLabel; +import net.runelite.client.ui.ClientToolbar; +import net.runelite.client.ui.NavigationButton; +import net.runelite.client.ui.overlay.OverlayManager; +import net.runelite.client.util.HotkeyListener; +import net.runelite.client.util.ImageUtil; +import net.runelite.client.util.PvPUtil; +import static net.runelite.client.util.StackFormatter.quantityToRSDecimalStack; +import net.runelite.client.util.Text; +import org.apache.commons.lang3.ArrayUtils; + +@PluginDescriptor( + name = "PvP Tools", + description = "Enable the PvP Tools panel", + tags = {"panel", "pvp", "pk", "pklite"}, + type = PluginType.PVP +) +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; + + /** + * ActionListener for the missing cc members and refresh buttons + */ + final ActionListener playersButtonActionListener = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (missingPlayersJFrame != null) + { + missingPlayersJFrame.dispose(); + missingPlayersJFrame = null; + missingPlayersJFrame = new MissingPlayersJFrame(client, uhPvpToolsPlugin, getMissingMembers()); + } + else + { + missingPlayersJFrame = new MissingPlayersJFrame(client, uhPvpToolsPlugin, getMissingMembers()); + } + } + }; + + final ActionListener currentPlayersActionListener = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (currentPlayersJFrame != null) + { + currentPlayersJFrame.dispose(); + currentPlayersJFrame = null; + currentPlayersJFrame = new CurrentPlayersJFrame(client, uhPvpToolsPlugin, getCurrentMembers()); + } + else + { + currentPlayersJFrame = new CurrentPlayersJFrame(client, uhPvpToolsPlugin, getCurrentMembers()); + } + } + }; + + + @Inject + private ClientToolbar clientToolbar; + + @Inject + private KeyManager keyManager; + + @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 + */ + private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey()) + { + public void hotkeyPressed() + { + toggleFallinHelper(); + } + }; + + private int[] overheadCount = new int[]{0, 0, 0}; + + private Comparator itemPriceComparator = new Comparator() + { + @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() + { + CopyOnWriteArrayList ccMembers = ClanChatPlugin.getClanMembers(); + ArrayList missingMembers = new ArrayList(); + for (ClanMember clanMember:client.getClanMembers()) + { + if (!Objects.isNull(clanMember)) + { + List arrayList = ccMembers.stream().map(player -> Text.removeTags(Text.standardize(player.getName()))).collect(Collectors.toList()); + if (!arrayList.contains(Text.removeTags(Text.standardize(clanMember.getUsername())))) + { + if (!missingMembers.contains(clanMember.getUsername())) + { + missingMembers.add("[W" + clanMember.getWorld() + "] - " + clanMember.getUsername()); + } + } + } + } + + return missingMembers; + + //Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername) + //.toArray()).collect(Collectors.toList()); + } + + public List getCurrentMembers() + { + CopyOnWriteArrayList ccMembers = ClanChatPlugin.getClanMembers(); + ArrayList currentMembers = new ArrayList(); + for (ClanMember clanMember:client.getClanMembers()) + { + if (!Objects.isNull(clanMember)) + { + List arrayList = ccMembers.stream().map(player -> Text.removeTags(Text.standardize(player.getName()))).collect(Collectors.toList()); + if (arrayList.contains(Text.removeTags(Text.standardize(clanMember.getUsername())))) + { + if (!currentMembers.contains(clanMember.getUsername())) + { + currentMembers.add(clanMember.getUsername()); + } + } + } + } + + return currentMembers; + + //Arrays.stream(Arrays.stream(client.getClanMembers()).filter(Objects::nonNull).map(ClanMember::getUsername) + //.toArray()).collect(Collectors.toList()); + } + + + + @Provides + PvpToolsConfig config(ConfigManager configManager) + { + return configManager.getConfig(PvpToolsConfig.class); + } + + @Override + protected void startUp() throws Exception + { + + overlayManager.add(pvpToolsOverlay); + + keyManager.registerKeyListener(hotkeyListener); + final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "skull.png"); + + panel = new PvpToolsPanel(); + panel.init(); + + navButton = NavigationButton.builder() + .tooltip("PvP Tools") + .icon(icon) + .priority(5) + .panel(panel) + .build(); + + panel.missingPlayers.addActionListener(playersButtonActionListener); + panel.currentPlayers.addActionListener(currentPlayersActionListener); + clientToolbar.addNavigation(navButton); + + + if (config.missingPlayersEnabled()) + { + panel.missingPlayers.setVisible(true); + } + + if (config.currentPlayersEnabled()) + { + panel.currentPlayers.setVisible(true); + } + } + + @Override + protected void shutDown() throws Exception + { + overlayManager.remove(pvpToolsOverlay); + keyManager.unregisterKeyListener(hotkeyListener); + clientToolbar.removeNavigation(navButton); + } + + @Subscribe + public void onConfigChanged(ConfigChanged configChanged) + { + if (configChanged.getGroup().equals("pvptools")) + { + switch (configChanged.getKey()) + { + case "countPlayers": + if (config.countPlayers()) + { + updatePlayers(); + } + if (!config.countPlayers()) + { + panel.disablePlayerCount(); + } + break; + case "countOverHeads": + if (config.countOverHeads()) + { + countOverHeads(); + } + if (!config.countOverHeads()) + { + panel.disablePrayerCount(); + } + break; + case "riskCalculator": + if (config.riskCalculatorEnabled()) + { + getCarriedWealth(); + } + if (!config.riskCalculatorEnabled()) + { + panel.disableRiskCalculator(); + } + break; + case "missingPlayers": + if (config.missingPlayersEnabled()) + { + panel.missingPlayers.setVisible(true); + } + break; + case "currentPlayers": + if (config.currentPlayersEnabled()) + { + panel.currentPlayers.setVisible(true); + } + break; + default: + break; + } + } + } + + @Subscribe + public void onItemContainerChanged(ItemContainerChanged event) + { + if (event.getItemContainer().equals(client.getItemContainer(InventoryID.INVENTORY)) && + config.riskCalculatorEnabled()) + { + getCarriedWealth(); + } + } + + @Subscribe + public void onGameStateChanged(GameStateChanged event) + { + if (event.getGameState().equals(GameState.LOGGED_IN) && config.riskCalculatorEnabled()) + { + getCarriedWealth(); + } + if (event.getGameState().equals(GameState.LOGGED_IN)) + { + if (config.countPlayers()) + { + updatePlayers(); + } + } + } + + @Subscribe + public void onPlayerSpawned(PlayerSpawned event) + { + if (config.countPlayers() && PvPUtil.isAttackable(client, event.getPlayer())) + { + updatePlayers(); + } + if (config.countOverHeads()) + { + countOverHeads(); + } + } + + @Subscribe + public void onPlayerDespawned(PlayerDespawned event) + { + if (config.countPlayers() && PvPUtil.isAttackable(client, event.getPlayer())) + { + updatePlayers(); + } + if (config.countOverHeads()) + { + countOverHeads(); + } + } + + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) + { + if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions()) + { + 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; + } + 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); + } + } + } + } + + private void moveEntry(String mtarget) + { + this.mtarget = mtarget; + MenuEntry[] menuEntries = client.getMenuEntries(); + MenuEntry lastEntry = menuEntries[menuEntries.length - 1]; + + // strip out existing '); + 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); + + } + + @Subscribe + public void onFocusChanged(FocusChanged focusChanged) + { + if (!focusChanged.isFocused()) + { + setAttackHotKeyPressed(false); + } + } + + /** + * Enables or disables the fall in helper feature + */ + private void toggleFallinHelper() + { + if (!fallinHelperEnabled) + { + client.setIsHidingEntities(true); + client.setPlayersHidden(true); + fallinHelperEnabled = true; + } + else + { + client.setIsHidingEntities(false); + client.setPlayersHidden(false); + fallinHelperEnabled = false; + } + + } + + /** + * Updates the PvP Tools panel with the numbers for enemy protection prayers + */ + private void updatePrayerNumbers() + { + panel.numMageJLabel.setText(htmlLabel("Enemies Praying Mage: ", String.valueOf(overheadCount[0]))); + panel.numRangeJLabel.setText(htmlLabel("Enemies Praying Range: ", String.valueOf(overheadCount[1]))); + panel.numMeleeJLabel.setText(htmlLabel("Enemies Praying Melee: ", String.valueOf(overheadCount[2]))); + panel.numMageJLabel.repaint(); + panel.numRangeJLabel.repaint(); + panel.numMeleeJLabel.repaint(); + } + + /** + * + */ + private void updatePlayers() + { + if (config.countPlayers()) + { + int cc = 0; + int other = 0; + for (Player p : client.getPlayers()) + { + if (Objects.nonNull(p)) + { + if (PvPUtil.isAttackable(client, p)) + { + if (p.isClanMember()) + { + cc++; + } + else + { + other++; + } + } + } + } + + panel.numOther.setText(htmlLabel("Other Player Count: ", String.valueOf(other))); + panel.numCC.setText(htmlLabel("Friendly Player Count: ", String.valueOf(cc))); + panel.numCC.repaint(); + panel.numOther.repaint(); + } + } + + private void countOverHeads() + { + overheadCount = new int[]{0, 0, 0}; + for (Player p : client.getPlayers()) + { + if (Objects.nonNull(p)) + { + if (PvPUtil.isAttackable(client, p)) + { + if (!p.isClanMember() && !(p.getOverheadIcon() == null)) + { + switch (p.getOverheadIcon()) + { + case MAGIC: + overheadCount[0]++; + break; + case RANGED: + overheadCount[1]++; + break; + case MELEE: + overheadCount[2]++; + break; + } + } + } + } + } + updatePrayerNumbers(); + } + + /** + * Calculates the player's risk based on Item Price of all items in their inventory and equipment + */ + private void getCarriedWealth() + { + if (!config.riskCalculatorEnabled()) + { + return; + } + if (client.getItemContainer(InventoryID.EQUIPMENT) == null) + { + return; + } + if (client.getItemContainer(InventoryID.INVENTORY).getItems() == null) + { + return; + } + Item[] items = ArrayUtils.addAll(Objects.requireNonNull(client.getItemContainer(InventoryID.EQUIPMENT)).getItems(), + Objects.requireNonNull(client.getItemContainer(InventoryID.INVENTORY)).getItems()); + TreeMap priceMap = new TreeMap<>(Comparator.comparingInt(Integer::intValue)); + int wealth = 0; + for (Item i : items) + { + int value = (itemManager.getItemPrice(i.getId()) * i.getQuantity()); + + final ItemComposition itemComposition = itemManager.getItemComposition(i.getId()); + if (!itemComposition.isTradeable() && value == 0) + { + value = itemComposition.getPrice() * i.getQuantity(); + priceMap.put(value, i); + } + else + { + value = itemManager.getItemPrice(i.getId()) * i.getQuantity(); + if (i.getId() > 0 && value > 0) + { + priceMap.put(value, i); + } + } + wealth += value; + } + panel.totalRiskLabel.setText(htmlLabel("Total risk: ", quantityToRSDecimalStack(wealth))); + panel.totalRiskLabel.repaint(); + + int itemLimit = 0; + if (client.getLocalPlayer().getSkullIcon() != null) + { + if (client.getLocalPlayer().getSkullIcon() == SkullIcon.SKULL) + { + itemLimit = 1; + } + } + if (client.getLocalPlayer().getSkullIcon() == null) + { + itemLimit = 4; + } + + AsyncBufferedImage itemImage = null; + + NavigableMap descendingMap = priceMap.descendingMap(); + + for (int i = 0; i < itemLimit; i++) + { + if (i == 0) + { + if (!descendingMap.isEmpty()) + { + itemImage = itemManager.getImage(descendingMap.pollFirstEntry().getValue().getId()); + } + } + else + { + if (!descendingMap.isEmpty()) + { + itemManager.getItemComposition(priceMap.descendingMap().pollFirstEntry().getValue().getId()) + .getName(); + } + } + } + panel.riskProtectingItem.setText(htmlLabel("Risk Protecting Item: ", + quantityToRSDecimalStack(descendingMap.keySet().stream().mapToInt(Integer::intValue).sum()))); + panel.riskProtectingItem.repaint(); + + panel.biggestItemLabel.setText("Most Valuable Item: "); + if (itemImage != null) + { + itemImage.addTo(panel.biggestItemLabel); + } + panel.biggestItemLabel.repaint(); + } + +} \ No newline at end of file