npchider: change method by which npcs are hidden by name (#1573)
* npchider: change method by which npcs are hidden by name * fix bug on client startup/shutdown where nothing gets hidden * entityhider: change method by which npcs are hidden on death
This commit is contained in:
@@ -1464,18 +1464,46 @@ public interface Client extends GameShell
|
|||||||
void setNPCsHidden(boolean state);
|
void setNPCsHidden(boolean state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets which NPCs are hidden
|
* Increments the counter for how many times this npc has been selected to be hidden
|
||||||
*
|
*
|
||||||
* @param names the names of the npcs
|
* @param name npc name
|
||||||
*/
|
*/
|
||||||
void setNPCsNames(List<String> names);
|
void addHiddenNpcName(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets which NPCs are hidden on death
|
* Decrements the counter for how many times this npc has been selected to be hidden
|
||||||
*
|
*
|
||||||
* @param names the names of the npcs
|
* @param name npc name
|
||||||
*/
|
*/
|
||||||
void setNPCsHiddenOnDeath(List<String> names);
|
void removeHiddenNpcName(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forcibly unhides an npc by setting its counter to zero
|
||||||
|
*
|
||||||
|
* @param name npc name
|
||||||
|
*/
|
||||||
|
void forciblyUnhideNpcName(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the counter for how many times this npc has been selected to be hidden on death
|
||||||
|
*
|
||||||
|
* @param name npc name
|
||||||
|
*/
|
||||||
|
void addHiddenNpcDeath(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the counter for how many times this npc has been selected to be hidden on death
|
||||||
|
*
|
||||||
|
* @param name npc name
|
||||||
|
*/
|
||||||
|
void removeHiddenNpcDeath(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forcibly unhides a hidden-while-dead npc by setting its counter to zero
|
||||||
|
*
|
||||||
|
* @param name npc name
|
||||||
|
*/
|
||||||
|
void forciblyUnhideNpcDeath(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether 2D sprites (ie. overhead prayers) related to
|
* Sets whether 2D sprites (ie. overhead prayers) related to
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
||||||
|
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -40,6 +41,10 @@ import net.runelite.client.eventbus.EventBus;
|
|||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Entity Hider",
|
name = "Entity Hider",
|
||||||
description = "Hide players, NPCs, and/or projectiles",
|
description = "Hide players, NPCs, and/or projectiles",
|
||||||
@@ -69,6 +74,9 @@ public class EntityHiderPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
updateConfig();
|
updateConfig();
|
||||||
addSubscriptions();
|
addSubscriptions();
|
||||||
|
|
||||||
|
Text.fromCSV(config.hideNPCsNames()).forEach(client::addHiddenNpcName);
|
||||||
|
Text.fromCSV(config.hideNPCsOnDeath()).forEach(client::addHiddenNpcDeath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSubscriptions()
|
private void addSubscriptions()
|
||||||
@@ -82,6 +90,30 @@ public class EntityHiderPlugin extends Plugin
|
|||||||
if (event.getGroup().equals("entityhider"))
|
if (event.getGroup().equals("entityhider"))
|
||||||
{
|
{
|
||||||
updateConfig();
|
updateConfig();
|
||||||
|
|
||||||
|
if (event.getKey().equals("hideNPCsNames"))
|
||||||
|
{
|
||||||
|
List<String> oldList = Text.fromCSV(event.getOldValue());
|
||||||
|
List<String> newList = Text.fromCSV(event.getNewValue());
|
||||||
|
|
||||||
|
ArrayList<String> removed = oldList.stream().filter(s -> !newList.contains(s)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
ArrayList<String> added = newList.stream().filter(s -> !oldList.contains(s)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
|
||||||
|
removed.forEach(client::removeHiddenNpcName);
|
||||||
|
added.forEach(client::addHiddenNpcName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getKey().equals("hideNPCsOnDeath"))
|
||||||
|
{
|
||||||
|
List<String> oldList = Text.fromCSV(event.getOldValue());
|
||||||
|
List<String> newList = Text.fromCSV(event.getNewValue());
|
||||||
|
|
||||||
|
ArrayList<String> removed = oldList.stream().filter(s -> !newList.contains(s)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
ArrayList<String> added = newList.stream().filter(s -> !oldList.contains(s)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
|
||||||
|
removed.forEach(client::removeHiddenNpcDeath);
|
||||||
|
added.forEach(client::addHiddenNpcDeath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +141,8 @@ public class EntityHiderPlugin extends Plugin
|
|||||||
|
|
||||||
client.setNPCsHidden(config.hideNPCs());
|
client.setNPCsHidden(config.hideNPCs());
|
||||||
client.setNPCsHidden2D(config.hideNPCs2D());
|
client.setNPCsHidden2D(config.hideNPCs2D());
|
||||||
client.setNPCsNames(Text.fromCSV(config.hideNPCsNames()));
|
//client.setNPCsNames(Text.fromCSV(config.hideNPCsNames()));
|
||||||
client.setNPCsHiddenOnDeath(Text.fromCSV(config.hideNPCsOnDeath()));
|
//client.setNPCsHiddenOnDeath(Text.fromCSV(config.hideNPCsOnDeath()));
|
||||||
|
|
||||||
client.setAttackersHidden(config.hideAttackers());
|
client.setAttackersHidden(config.hideAttackers());
|
||||||
|
|
||||||
@@ -143,6 +175,9 @@ public class EntityHiderPlugin extends Plugin
|
|||||||
client.setProjectilesHidden(false);
|
client.setProjectilesHidden(false);
|
||||||
|
|
||||||
client.setDeadNPCsHidden(false);
|
client.setDeadNPCsHidden(false);
|
||||||
|
|
||||||
|
Text.fromCSV(config.hideNPCsNames()).forEach(client::removeHiddenNpcName);
|
||||||
|
Text.fromCSV(config.hideNPCsOnDeath()).forEach(client::removeHiddenNpcDeath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPlayerRegionAllowed()
|
private boolean isPlayerRegionAllowed()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
||||||
|
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -24,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.mixins;
|
package net.runelite.mixins;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
@@ -69,13 +72,13 @@ public abstract class EntityHiderBridgeMixin implements RSClient
|
|||||||
public static boolean hideDeadNPCs;
|
public static boolean hideDeadNPCs;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public static List<String> hideNPCsNames;
|
public static HashMap<String, Integer> hiddenNpcsName = new HashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public static List<String> hideNPCsOnDeath;
|
public static HashMap<String, Integer> hiddenNpcsDeath = new HashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public static List<String> hideSpecificPlayers;
|
public static List<String> hideSpecificPlayers = new ArrayList<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
@@ -142,16 +145,74 @@ public abstract class EntityHiderBridgeMixin implements RSClient
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public void setNPCsNames(List<String> NPCs)
|
public void addHiddenNpcName(String npc)
|
||||||
{
|
{
|
||||||
hideNPCsNames = NPCs;
|
npc = npc.toLowerCase();
|
||||||
|
int i = hiddenNpcsName.getOrDefault(npc, 0);
|
||||||
|
if (i == Integer.MAX_VALUE)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("NPC name " + npc + " has been hidden Integer.MAX_VALUE times, is something wrong?");
|
||||||
|
}
|
||||||
|
|
||||||
|
hiddenNpcsName.put(npc, ++i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public void setNPCsHiddenOnDeath(List<String> NPCs)
|
public void removeHiddenNpcName(String npc)
|
||||||
{
|
{
|
||||||
hideNPCsOnDeath = NPCs;
|
npc = npc.toLowerCase();
|
||||||
|
int i = hiddenNpcsName.getOrDefault(npc, 0);
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hiddenNpcsName.put(npc, --i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void forciblyUnhideNpcName(String npc)
|
||||||
|
{
|
||||||
|
npc = npc.toLowerCase();
|
||||||
|
hiddenNpcsName.put(npc, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void addHiddenNpcDeath(String npc)
|
||||||
|
{
|
||||||
|
npc = npc.toLowerCase();
|
||||||
|
int i = hiddenNpcsDeath.getOrDefault(npc, 0);
|
||||||
|
if (i == Integer.MAX_VALUE)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("NPC death " + npc + " has been hidden Integer.MAX_VALUE times, is something wrong?");
|
||||||
|
}
|
||||||
|
|
||||||
|
hiddenNpcsDeath.put(npc, ++i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void removeHiddenNpcDeath(String npc)
|
||||||
|
{
|
||||||
|
npc = npc.toLowerCase();
|
||||||
|
int i = hiddenNpcsDeath.getOrDefault(npc, 0);
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hiddenNpcsDeath.put(npc, --i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void forciblyUnhideNpcDeath(String npc)
|
||||||
|
{
|
||||||
|
npc = npc.toLowerCase();
|
||||||
|
hiddenNpcsDeath.put(npc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
||||||
|
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -24,9 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.mixins;
|
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.Copy;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
@@ -41,15 +39,12 @@ import net.runelite.rs.api.RSPlayer;
|
|||||||
import net.runelite.rs.api.RSProjectile;
|
import net.runelite.rs.api.RSProjectile;
|
||||||
import net.runelite.rs.api.RSScene;
|
import net.runelite.rs.api.RSScene;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(RSScene.class)
|
@Mixin(RSScene.class)
|
||||||
public abstract class EntityHiderMixin implements RSScene
|
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")
|
@Shadow("client")
|
||||||
private static RSClient client;
|
private static RSClient client;
|
||||||
|
|
||||||
@@ -77,11 +72,11 @@ public abstract class EntityHiderMixin implements RSScene
|
|||||||
@Shadow("hideNPCs")
|
@Shadow("hideNPCs")
|
||||||
private static boolean hideNPCs;
|
private static boolean hideNPCs;
|
||||||
|
|
||||||
@Shadow("hideNPCsNames")
|
@Shadow("hiddenNpcsName")
|
||||||
private static List<String> hideNPCsNames;
|
private static HashMap<String, Integer> hiddenNpcsName;
|
||||||
|
|
||||||
@Shadow("hideNPCsOnDeath")
|
@Shadow("hiddenNpcsDeath")
|
||||||
private static List<String> hideNPCsOnDeath;
|
private static HashMap<String, Integer> hiddenNpcsDeath;
|
||||||
|
|
||||||
@Shadow("hideSpecificPlayers")
|
@Shadow("hideSpecificPlayers")
|
||||||
private static List<String> hideSpecificPlayers;
|
private static List<String> hideSpecificPlayers;
|
||||||
@@ -117,7 +112,8 @@ public abstract class EntityHiderMixin implements RSScene
|
|||||||
client.getOccupiedTilesTick()[tileX][tileY] = -1;
|
client.getOccupiedTilesTick()[tileX][tileY] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shouldDraw && addEntityMarker(var1, var2, var3, var4, var5, x, y, var8, entity, var10, var11, var12, var13);
|
return shouldDraw &&
|
||||||
|
addEntityMarker(var1, var2, var3, var4, var5, x, y, var8, entity, var10, var11, var12, var13);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Copy("drawActor2d")
|
@Copy("drawActor2d")
|
||||||
@@ -177,7 +173,8 @@ public abstract class EntityHiderMixin implements RSScene
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (!hideFriends && player.isFriend()) || (!isLocalPlayer && !hideClanMates && player.isClanMember());
|
return (!hideFriends && player.isFriend()) ||
|
||||||
|
(!isLocalPlayer && !hideClanMates && player.isClanMember());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (entity instanceof RSNPC)
|
else if (entity instanceof RSNPC)
|
||||||
@@ -197,26 +194,16 @@ public abstract class EntityHiderMixin implements RSScene
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String name : hideNPCsNames)
|
if (npc.getName() != null &&
|
||||||
|
hiddenNpcsName.getOrDefault(Text.standardize(npc.getName().toLowerCase()), 0) > 0)
|
||||||
{
|
{
|
||||||
if (name != null && !name.equals(""))
|
return false;
|
||||||
{
|
|
||||||
if (npc.getName() != null && matches(name, npc.getName()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String name : hideNPCsOnDeath)
|
if (npc.getName() != null && npc.getHealthRatio() == 0 &&
|
||||||
|
hiddenNpcsDeath.getOrDefault(Text.standardize(npc.getName().toLowerCase()), 0) > 0)
|
||||||
{
|
{
|
||||||
if (name != null && !name.equals(""))
|
return false;
|
||||||
{
|
|
||||||
if (npc.getName() != null && matches(name, npc.getName()) && npc.getHealthRatio() == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return drawingUI ? !hideNPCs2D : !hideNPCs;
|
return drawingUI ? !hideNPCs2D : !hideNPCs;
|
||||||
@@ -228,34 +215,4 @@ public abstract class EntityHiderMixin implements RSScene
|
|||||||
|
|
||||||
return true;
|
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