plugins: Fix menu concurrency issues (#1444)
* Cleanup comparables a bit * Make shift walker add entries on client tick * Make climb up + down add entries on clienttick * remove try catch
This commit is contained in:
@@ -24,19 +24,18 @@
|
||||
*/
|
||||
package net.runelite.api;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.util.Text;
|
||||
|
||||
/**
|
||||
* A menu entry in a right-click menu.
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MenuEntry
|
||||
{
|
||||
/**
|
||||
@@ -49,6 +48,7 @@ public class MenuEntry
|
||||
* If the option does not apply to any target, this field
|
||||
* will be set to empty string.
|
||||
*/
|
||||
@Setter(AccessLevel.NONE)
|
||||
private String target;
|
||||
/**
|
||||
* An identifier value for the target of the action.
|
||||
@@ -56,6 +56,7 @@ public class MenuEntry
|
||||
private int identifier;
|
||||
/**
|
||||
* The action the entry will trigger.
|
||||
* {@link net.runelite.api.MenuOpcode}
|
||||
*/
|
||||
private int opcode;
|
||||
/**
|
||||
@@ -74,6 +75,17 @@ public class MenuEntry
|
||||
*/
|
||||
private boolean forceLeftClick;
|
||||
|
||||
public MenuEntry(String option, String target, int identifier, int opcode, int param0, int param1, boolean forceLeftClick)
|
||||
{
|
||||
this.option = option;
|
||||
this.target = target;
|
||||
this.identifier = identifier;
|
||||
this.opcode = opcode;
|
||||
this.param0 = param0;
|
||||
this.param1 = param1;
|
||||
this.forceLeftClick = forceLeftClick;
|
||||
}
|
||||
|
||||
public static MenuEntry copy(MenuEntry src)
|
||||
{
|
||||
return new MenuEntry(
|
||||
@@ -87,17 +99,22 @@ public class MenuEntry
|
||||
);
|
||||
}
|
||||
|
||||
private static final Matcher TAG_REGEXP = Pattern.compile("<[^>]*>").matcher("");
|
||||
|
||||
@Getter(lazy = true)
|
||||
private final String standardizedOption = standardize(option);
|
||||
@Getter(lazy = true)
|
||||
private final String standardizedTarget = standardize(LEVEL_MATCHER.reset(target).replaceAll(""));
|
||||
|
||||
public String standardize(String string)
|
||||
public void setTarget(String target)
|
||||
{
|
||||
return TAG_REGEXP.reset(string).replaceAll("").replace('\u00A0', ' ').trim().toLowerCase();
|
||||
this.target = target;
|
||||
this.standardizedTarget = null;
|
||||
}
|
||||
|
||||
private static final Matcher LEVEL_MATCHER = Pattern.compile("\\(level-[0-9]*\\)").matcher("");
|
||||
@Getter(AccessLevel.NONE)
|
||||
private String standardizedTarget;
|
||||
|
||||
public String getStandardizedTarget()
|
||||
{
|
||||
if (standardizedTarget == null)
|
||||
{
|
||||
standardizedTarget = Text.standardize(target, true);
|
||||
}
|
||||
|
||||
return standardizedTarget;
|
||||
}
|
||||
}
|
||||
|
||||
108
runelite-api/src/main/java/net/runelite/api/util/Text.java
Normal file
108
runelite-api/src/main/java/net/runelite/api/util/Text.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package net.runelite.api.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class Text
|
||||
{
|
||||
private static final StringBuilder SB = new StringBuilder(32);
|
||||
/**
|
||||
* Removes all tags from the given string.
|
||||
*
|
||||
* @param str The string to remove tags from.
|
||||
* @return The given string with all tags removed from it.
|
||||
*
|
||||
* I know this is a monstrosity, but old frankenstein here
|
||||
* is twice as fast as the old regex method was.
|
||||
* Seems worth it to me
|
||||
*/
|
||||
public static String removeTags(String str, boolean removeLevel)
|
||||
{
|
||||
int strLen = str.length();
|
||||
if (removeLevel)
|
||||
{
|
||||
if (str.charAt(strLen - 1) == ')')
|
||||
{
|
||||
int levelStart = StringUtils.lastIndexOf(str, '(');
|
||||
// if it's not in the string the while will act like a if
|
||||
while (--levelStart >= 0)
|
||||
{
|
||||
if (str.charAt(levelStart) != ' ')
|
||||
{
|
||||
strLen = levelStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int open, close;
|
||||
if ((open = StringUtils.indexOf(str, '<')) == -1
|
||||
|| (close = StringUtils.indexOf(str, '>', open)) == -1)
|
||||
{
|
||||
return strLen == str.length() ? str : StringUtils.left(str, strLen);
|
||||
}
|
||||
|
||||
// If the string starts with a < we can maybe take a shortcut if this
|
||||
// is the only tag in the string (take the substring after it)
|
||||
if (open == 0)
|
||||
{
|
||||
if ((open = close + 1) >= strLen)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if ((open = StringUtils.indexOf(str, '<', open)) == -1
|
||||
|| (StringUtils.indexOf(str, '>', open)) == -1)
|
||||
{
|
||||
return StringUtils.substring(str, close + 1);
|
||||
}
|
||||
|
||||
// Whoops, at least we know the last value so we can go back to where we were
|
||||
// before :)
|
||||
open = 0;
|
||||
}
|
||||
|
||||
SB.setLength(0);
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
while (open != i)
|
||||
{
|
||||
SB.append(str.charAt(i++));
|
||||
}
|
||||
|
||||
i = close + 1;
|
||||
}
|
||||
while ((open = StringUtils.indexOf(str, '<', close)) != -1
|
||||
&& (close = StringUtils.indexOf(str, '>', open)) != -1
|
||||
&& i < strLen);
|
||||
|
||||
while (i < strLen)
|
||||
{
|
||||
SB.append(str.charAt(i++));
|
||||
}
|
||||
|
||||
return SB.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to removing all tags, replaces nbsp with space, trims string and lowercases it
|
||||
*
|
||||
* @param str The string to standardize
|
||||
* @return The given `str` that is standardized
|
||||
*/
|
||||
public static String standardize(String str, boolean removeLevel)
|
||||
{
|
||||
if (StringUtils.isBlank(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return removeTags(str, removeLevel).replace('\u00A0', ' ').trim().toLowerCase();
|
||||
}
|
||||
|
||||
public static String standardize(String str)
|
||||
{
|
||||
return standardize(str, false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user