Update left click hide attack options (#505)
This commit is contained in:
@@ -3,6 +3,7 @@ package net.runelite.client.plugins.clanmanmode;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -36,6 +37,10 @@ import org.apache.commons.lang3.ArrayUtils;
|
|||||||
|
|
||||||
public class ClanManModePlugin extends Plugin
|
public class ClanManModePlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String WALK_HERE = "WALK HERE";
|
||||||
|
private static final String CANCEL = "CANCEL";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@@ -57,6 +62,13 @@ public class ClanManModePlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ClanManager clanManager;
|
private ClanManager clanManager;
|
||||||
|
|
||||||
|
private static final String ATTACK_OPTIONS_ATTACK = "ATTACK";
|
||||||
|
public static final HashSet<String> ATTACK_OPTIONS_KEYWORDS = new HashSet<>();
|
||||||
|
static
|
||||||
|
{
|
||||||
|
ATTACK_OPTIONS_KEYWORDS.add(ATTACK_OPTIONS_ATTACK);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ClanManModeConfig provideConfig(ConfigManager configManager)
|
ClanManModeConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -125,11 +137,41 @@ public class ClanManModePlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onMenuEntryAdded(MenuEntryAdded event)
|
public void onMenuEntryAdded(MenuEntryAdded event)
|
||||||
{
|
{
|
||||||
if (!config.hideAtkOpt())
|
|
||||||
|
if (client.getGameState() != GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
|
||||||
|
Player[] players = client.getCachedPlayers();
|
||||||
|
Player player = null;
|
||||||
|
int identifier = event.getIdentifier();
|
||||||
|
|
||||||
|
if (identifier >= 0 && identifier < players.length)
|
||||||
|
{
|
||||||
|
player = players[identifier];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String pOptionToReplace = Text.removeTags(event.getOption()).toUpperCase();
|
||||||
|
|
||||||
|
//If the option is already to walk there, or cancel we don't need to swap it with anything
|
||||||
|
if (pOptionToReplace.equals(CANCEL) || pOptionToReplace.equals(WALK_HERE))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.hideAtkOpt()
|
||||||
|
&& ATTACK_OPTIONS_KEYWORDS.contains(pOptionToReplace)
|
||||||
|
&& (player.isFriend() || player.isClanMember()))
|
||||||
|
{
|
||||||
|
swap(pOptionToReplace);
|
||||||
|
}
|
||||||
|
else if (!config.hideAtkOpt())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -156,4 +198,46 @@ public class ClanManModePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps menu entries if the entries could be found. This places Walk Here where the top level menu option was.
|
||||||
|
* @param pOptionToReplace The String containing the Menu Option that needs to be replaced. IE: "Attack", "Chop Down".
|
||||||
|
*/
|
||||||
|
private void swap(String pOptionToReplace)
|
||||||
|
{
|
||||||
|
MenuEntry[] entries = client.getMenuEntries();
|
||||||
|
Integer walkHereEntry = searchIndex(entries, WALK_HERE);
|
||||||
|
Integer entryToReplace = searchIndex(entries, pOptionToReplace);
|
||||||
|
|
||||||
|
if (walkHereEntry != null
|
||||||
|
&& entryToReplace != null)
|
||||||
|
{
|
||||||
|
MenuEntry walkHereMenuEntry = entries[walkHereEntry];
|
||||||
|
entries[walkHereEntry] = entries[entryToReplace];
|
||||||
|
entries[entryToReplace] = walkHereMenuEntry;
|
||||||
|
client.setMenuEntries(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the index of the menu that contains the verbiage we are looking for.
|
||||||
|
* @param pMenuEntries The list of {@link MenuEntry}s.
|
||||||
|
* @param pMenuEntryToSearchFor The Option in the menu to search for.
|
||||||
|
* @return The index location or null if it was not found.
|
||||||
|
*/
|
||||||
|
private Integer searchIndex(MenuEntry[] pMenuEntries, String pMenuEntryToSearchFor)
|
||||||
|
{
|
||||||
|
Integer indexLocation = 0;
|
||||||
|
|
||||||
|
for (MenuEntry menuEntry : pMenuEntries)
|
||||||
|
{
|
||||||
|
String entryOption = Text.removeTags(menuEntry.getOption()).toUpperCase();
|
||||||
|
|
||||||
|
if (entryOption.equals(pMenuEntryToSearchFor))
|
||||||
|
{
|
||||||
|
return indexLocation;
|
||||||
|
}
|
||||||
|
indexLocation++;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -99,6 +100,15 @@ public class PvpToolsPlugin extends Plugin
|
|||||||
|
|
||||||
private PvpToolsPlugin uhPvpToolsPlugin = this;
|
private PvpToolsPlugin uhPvpToolsPlugin = this;
|
||||||
|
|
||||||
|
private static final String WALK_HERE = "WALK HERE";
|
||||||
|
private static final String CANCEL = "CANCEL";
|
||||||
|
private static final String ATTACK_OPTIONS_ATTACK = "ATTACK";
|
||||||
|
public static final HashSet<String> ATTACK_OPTIONS_KEYWORDS = new HashSet<>();
|
||||||
|
static
|
||||||
|
{
|
||||||
|
ATTACK_OPTIONS_KEYWORDS.add(ATTACK_OPTIONS_ATTACK);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActionListener for the missing cc members and refresh buttons
|
* ActionListener for the missing cc members and refresh buttons
|
||||||
*/
|
*/
|
||||||
@@ -376,10 +386,18 @@ public class PvpToolsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions())
|
if (config.attackOptionsFriend() || config.attackOptionsClan() || config.levelRangeAttackOptions())
|
||||||
{
|
{
|
||||||
|
final String pOptionToReplace = Text.removeTags(menuEntryAdded.getOption()).toUpperCase();
|
||||||
|
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
if (client.getGameState() != GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pOptionToReplace.equals(CANCEL) || pOptionToReplace.equals(WALK_HERE))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Player[] players = client.getCachedPlayers();
|
Player[] players = client.getCachedPlayers();
|
||||||
Player player = null;
|
Player player = null;
|
||||||
int identifier = menuEntryAdded.getIdentifier();
|
int identifier = menuEntryAdded.getIdentifier();
|
||||||
@@ -391,46 +409,27 @@ public class PvpToolsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (attackHotKeyPressed && config.attackOptionsClan() || config.attackOptionsFriend() ||
|
if (attackHotKeyPressed && config.attackOptionsClan() || config.attackOptionsFriend() ||
|
||||||
config.levelRangeAttackOptions())
|
config.levelRangeAttackOptions())
|
||||||
{
|
{
|
||||||
if (config.attackOptionsFriend() && player.isFriend())
|
if (config.attackOptionsFriend() && player.isFriend())
|
||||||
{
|
{
|
||||||
moveEntry();
|
swap(pOptionToReplace);
|
||||||
}
|
}
|
||||||
if (config.attackOptionsClan() && player.isClanMember())
|
if (config.attackOptionsClan() && player.isClanMember())
|
||||||
{
|
{
|
||||||
moveEntry();
|
swap(pOptionToReplace);
|
||||||
}
|
}
|
||||||
if (config.levelRangeAttackOptions() && !PvPUtil.isAttackable(client, player))
|
if (config.levelRangeAttackOptions() && !PvPUtil.isAttackable(client, player))
|
||||||
{
|
{
|
||||||
moveEntry();
|
swap(pOptionToReplace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveEntry()
|
|
||||||
{
|
|
||||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
|
||||||
MenuEntry lastEntry = 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); TODO: Make sure to use menuutil when uncommenting this
|
|
||||||
}
|
|
||||||
if (lastEntry.getOption().equals("Attack"))
|
|
||||||
{
|
|
||||||
ArrayUtils.shift(menuEntries, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setMenuEntries(menuEntries);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onFocusChanged(FocusChanged focusChanged)
|
public void onFocusChanged(FocusChanged focusChanged)
|
||||||
{
|
{
|
||||||
@@ -628,4 +627,47 @@ public class PvpToolsPlugin extends Plugin
|
|||||||
panel.biggestItemLabel.repaint();
|
panel.biggestItemLabel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps menu entries if the entries could be found. This places Walk Here where the top level menu option was.
|
||||||
|
* @param pOptionToReplace The String containing the Menu Option that needs to be replaced. IE: "Attack", "Chop Down".
|
||||||
|
*/
|
||||||
|
private void swap(String pOptionToReplace)
|
||||||
|
{
|
||||||
|
MenuEntry[] entries = client.getMenuEntries();
|
||||||
|
Integer walkHereEntry = searchIndex(entries, WALK_HERE);
|
||||||
|
Integer entryToReplace = searchIndex(entries, pOptionToReplace);
|
||||||
|
|
||||||
|
if (walkHereEntry != null
|
||||||
|
&& entryToReplace != null)
|
||||||
|
{
|
||||||
|
MenuEntry walkHereMenuEntry = entries[walkHereEntry];
|
||||||
|
entries[walkHereEntry] = entries[entryToReplace];
|
||||||
|
entries[entryToReplace] = walkHereMenuEntry;
|
||||||
|
client.setMenuEntries(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the index of the menu that contains the verbiage we are looking for.
|
||||||
|
* @param pMenuEntries The list of {@link MenuEntry}s.
|
||||||
|
* @param pMenuEntryToSearchFor The Option in the menu to search for.
|
||||||
|
* @return The index location or null if it was not found.
|
||||||
|
*/
|
||||||
|
private Integer searchIndex(MenuEntry[] pMenuEntries, String pMenuEntryToSearchFor)
|
||||||
|
{
|
||||||
|
Integer indexLocation = 0;
|
||||||
|
|
||||||
|
for (MenuEntry menuEntry : pMenuEntries)
|
||||||
|
{
|
||||||
|
String entryOption = Text.removeTags(menuEntry.getOption()).toUpperCase();
|
||||||
|
|
||||||
|
if (entryOption.equals(pMenuEntryToSearchFor))
|
||||||
|
{
|
||||||
|
return indexLocation;
|
||||||
|
}
|
||||||
|
indexLocation++;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user