diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index e4db1c6049..3de67d4fb8 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -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 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 names); /** * Sets whether 2D sprites (ie. overhead prayers) related to diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderConfig.java index cebc09e54b..e817546a98 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderConfig.java @@ -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; - } - } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java index b3b5882072..9fb8c196c1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/entityhider/EntityHiderPlugin.java @@ -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()); diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderBridgeMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderBridgeMixin.java index 7001eb3c0c..81c60a8c12 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderBridgeMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderBridgeMixin.java @@ -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 hideNPCsNames; @Inject - public static String hideNPCsOnDeath; + public static List hideNPCsOnDeath; @Inject @Override @@ -138,14 +139,14 @@ public abstract class EntityHiderBridgeMixin implements RSClient @Inject @Override - public void setNPCsNames(String NPCs) + public void setNPCsNames(List NPCs) { hideNPCsNames = NPCs; } @Inject @Override - public void setNPCsHiddenOnDeath(String NPCs) + public void setNPCsHiddenOnDeath(List NPCs) { hideNPCsOnDeath = NPCs; } diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderMixin.java index 17d0e83b59..80122ba7bf 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/EntityHiderMixin.java @@ -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 hideNPCsNames; @Shadow("hideNPCsOnDeath") - private static String hideNPCsOnDeath; + private static List 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); + } }