entityhider: add wildcard support (#1202)
* Add wildcard support to entity hider * standardize npc name
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import java.util.List;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
@@ -68,10 +69,10 @@ public abstract class EntityHiderBridgeMixin implements RSClient
|
||||
public static boolean hideDeadNPCs;
|
||||
|
||||
@Inject
|
||||
public static String hideNPCsNames;
|
||||
public static List<String> hideNPCsNames;
|
||||
|
||||
@Inject
|
||||
public static String hideNPCsOnDeath;
|
||||
public static List<String> hideNPCsOnDeath;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
@@ -138,14 +139,14 @@ public abstract class EntityHiderBridgeMixin implements RSClient
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setNPCsNames(String NPCs)
|
||||
public void setNPCsNames(List<String> NPCs)
|
||||
{
|
||||
hideNPCsNames = NPCs;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setNPCsHiddenOnDeath(String NPCs)
|
||||
public void setNPCsHiddenOnDeath(List<String> NPCs)
|
||||
{
|
||||
hideNPCsOnDeath = NPCs;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import net.runelite.api.mixins.Copy;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
@@ -40,6 +43,12 @@ import net.runelite.rs.api.RSScene;
|
||||
@Mixin(RSScene.class)
|
||||
public abstract class EntityHiderMixin implements RSScene
|
||||
{
|
||||
@Inject
|
||||
private static final Pattern WILDCARD_PATTERN = Pattern.compile("(?i)[^*]+|(\\*)");
|
||||
|
||||
@Inject
|
||||
private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>");
|
||||
|
||||
@Shadow("client")
|
||||
private static RSClient client;
|
||||
|
||||
@@ -68,10 +77,10 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
private static boolean hideNPCs;
|
||||
|
||||
@Shadow("hideNPCsNames")
|
||||
private static String hideNPCsNames;
|
||||
private static List<String> hideNPCsNames;
|
||||
|
||||
@Shadow("hideNPCsOnDeath")
|
||||
private static String hideNPCsOnDeath;
|
||||
private static List<String> hideNPCsOnDeath;
|
||||
|
||||
@Shadow("hideNPCs2D")
|
||||
private static boolean hideNPCs2D;
|
||||
@@ -160,8 +169,6 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
else if (renderable instanceof RSNPC)
|
||||
{
|
||||
RSNPC npc = (RSNPC) renderable;
|
||||
String[] names = hideNPCsNames.split(",");
|
||||
String[] removeOnDeath = hideNPCsOnDeath.split(",");
|
||||
|
||||
if (!hideAttackers)
|
||||
{
|
||||
@@ -176,22 +183,22 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String name : names)
|
||||
for (String name : hideNPCsNames)
|
||||
{
|
||||
if (name != null && !name.equals(""))
|
||||
{
|
||||
if (npc.getName() != null && npc.getName().startsWith(name))
|
||||
if (npc.getName() != null && matches(name, npc.getName()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : removeOnDeath)
|
||||
for (String name : hideNPCsOnDeath)
|
||||
{
|
||||
if (name != null && !name.equals(""))
|
||||
{
|
||||
if (npc.getName() != null && npc.getName().startsWith(name) && npc.getHealthRatio() == 0)
|
||||
if (npc.getName() != null && matches(name, npc.getName()) && npc.getHealthRatio() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -207,4 +214,34 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Inject
|
||||
static private boolean matches(String pattern, String text)
|
||||
{
|
||||
String standardized = TAG_REGEXP.matcher(text)
|
||||
.replaceAll("")
|
||||
.replace('\u00A0', ' ')
|
||||
.toLowerCase();
|
||||
|
||||
final Matcher matcher = WILDCARD_PATTERN.matcher(pattern.toLowerCase());
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append("(?i)");
|
||||
while (matcher.find())
|
||||
{
|
||||
if (matcher.group(1) != null)
|
||||
{
|
||||
matcher.appendReplacement(buffer, ".*");
|
||||
}
|
||||
else
|
||||
{
|
||||
matcher.appendReplacement(buffer, "\\\\Q" + matcher.group(0) + "\\\\E");
|
||||
}
|
||||
}
|
||||
|
||||
matcher.appendTail(buffer);
|
||||
final String replaced = buffer.toString();
|
||||
|
||||
return standardized.matches(replaced);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user