entityhider: add wildcard support (#1202)
* Add wildcard support to entity hider * standardize npc name
This commit is contained in:
@@ -1452,16 +1452,16 @@ public interface Client extends GameShell
|
||||
/**
|
||||
* Sets which NPCs are hidden
|
||||
*
|
||||
* @param names the names of the npcs seperated by ','
|
||||
* @param names the names of the npcs
|
||||
*/
|
||||
void setNPCsNames(String names);
|
||||
void setNPCsNames(List<String> names);
|
||||
|
||||
/**
|
||||
* Sets which NPCs are hidden on death
|
||||
*
|
||||
* @param names the names of the npcs seperated by ','
|
||||
* @param names the names of the npcs
|
||||
*/
|
||||
void setNPCsHiddenOnDeath(String names);
|
||||
void setNPCsHiddenOnDeath(List<String> names);
|
||||
|
||||
/**
|
||||
* Sets whether 2D sprites (ie. overhead prayers) related to
|
||||
|
||||
@@ -132,10 +132,10 @@ public interface EntityHiderConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 10,
|
||||
keyName = "hideNPCsNames",
|
||||
name = "Hide NPCs Names",
|
||||
description = "Configures which NPCs to hide"
|
||||
position = 10,
|
||||
keyName = "hideNPCsNames",
|
||||
name = "Hide NPCs Names",
|
||||
description = "Configures which NPCs to hide"
|
||||
)
|
||||
default String hideNPCsNames()
|
||||
{
|
||||
@@ -143,7 +143,18 @@ public interface EntityHiderConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 10,
|
||||
position = 11,
|
||||
keyName = "hideDeadNPCs",
|
||||
name = "Hide Dead NPCs",
|
||||
description = "Configures whether or not NPCs that just died are hidden"
|
||||
)
|
||||
default boolean hideDeadNPCs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 12,
|
||||
keyName = "hideNPCsOnDeath",
|
||||
name = "Hide NPCs On Death",
|
||||
description = "Configures which NPCs to hide when they die"
|
||||
@@ -154,7 +165,7 @@ public interface EntityHiderConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 11,
|
||||
position = 13,
|
||||
keyName = "hideProjectiles",
|
||||
name = "Hide Projectiles",
|
||||
description = "Configures whether or not projectiles are hidden"
|
||||
@@ -163,16 +174,4 @@ public interface EntityHiderConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 12,
|
||||
keyName = "hideDeadNPCs",
|
||||
name = "Hide Dead NPCs",
|
||||
description = "Configures whether or not NPCs that just died are hidden"
|
||||
)
|
||||
default boolean hideDeadNPCs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Entity Hider",
|
||||
@@ -107,8 +108,8 @@ public class EntityHiderPlugin extends Plugin
|
||||
|
||||
client.setNPCsHidden(config.hideNPCs());
|
||||
client.setNPCsHidden2D(config.hideNPCs2D());
|
||||
client.setNPCsNames(config.hideNPCsNames());
|
||||
client.setNPCsHiddenOnDeath(config.hideNPCsOnDeath());
|
||||
client.setNPCsNames(Text.fromCSV(config.hideNPCsNames()));
|
||||
client.setNPCsHiddenOnDeath(Text.fromCSV(config.hideNPCsOnDeath()));
|
||||
|
||||
client.setAttackersHidden(config.hideAttackers());
|
||||
|
||||
|
||||
@@ -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