Added whitelist option

This commit is contained in:
Zeshan Aslam 2020-04-05 12:47:10 -04:00
parent 17a2fb9b49
commit 61d9d83fdf
5 changed files with 37 additions and 1 deletions

View File

@ -72,6 +72,10 @@ Remember Toggle: false
Blacklist:
- 'CCPD Officer'
# Whitelist by entity name or entity display name.
# Also supports MythicMobs using the internal name.
Whitelist: []
# Show the health of the entity that the player is looking at.
Show On Look: true
Look Distance: 10

View File

@ -1,6 +1,6 @@
name: ActionHealth
main: com.zeshanaslam.actionhealth.Main
version: 3.4.4
version: 3.4.5
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, WorldGuard, mcMMO, MythicMobs, LangUtils]
commands:
Actionhealth:

View File

@ -48,6 +48,12 @@ public class LookThread extends BukkitRunnable {
String name = plugin.healthUtil.getName(livingEntity, player);
if (targetHelper.canSee(player, livingEntity.getLocation(), transparentTypeIds) && !plugin.healthUtil.isBlacklisted(livingEntity, name)) {
if (plugin.configStore.isUsingWhiteList()) {
if (!plugin.healthUtil.isWhiteListed(livingEntity, name)) {
continue;
}
}
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
break;
}

View File

@ -51,6 +51,7 @@ public class ConfigStore {
public double lookTolerance;
public long checkTicks;
public ActionStore actionStore;
public List<String> whitelist = new ArrayList<>();
public ConfigStore(Main plugin) {
// Clear settings for reloads
@ -58,6 +59,7 @@ public class ConfigStore {
regions.clear();
blacklist.clear();
translate.clear();
whitelist.clear();
// Check if using MVdWPlaceholderAPI
hasMVdWPlaceholderAPI = Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI");
@ -119,6 +121,10 @@ public class ConfigStore {
blacklist.addAll(plugin.getConfig().getStringList("Blacklist").stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()));
}
if (plugin.getConfig().contains("Whitelist")) {
whitelist.addAll(plugin.getConfig().getStringList("Whitelist").stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()));
}
if (plugin.getConfig().contains("Toggle Message")) {
toggleMessage = plugin.getConfig().getString("Toggle Message");
}
@ -192,4 +198,8 @@ public class ConfigStore {
showOnLook = false;
}
}
public boolean isUsingWhiteList() {
return !whitelist.isEmpty();
}
}

View File

@ -86,6 +86,11 @@ public class HealthUtil {
String name = getName(entity, receiver);
if (plugin.healthUtil.isBlacklisted(entity, name)) return null;
if (plugin.configStore.stripName) name = ChatColor.stripColor(name);
if (plugin.configStore.isUsingWhiteList()) {
if (!plugin.healthUtil.isWhiteListed(entity, name)) {
return null;
}
}
if (entity instanceof Player) {
String displayName;
@ -355,4 +360,15 @@ public class HealthUtil {
return plugin.configStore.blacklist.contains(name);
}
public boolean isWhiteListed(Entity entity, String name) {
if (plugin.mythicMobsEnabled) {
String mythicName = new MythicMobsSupport().getMythicName(entity);
if (mythicName != null && plugin.configStore.whitelist.contains(mythicName)) {
return true;
}
}
return plugin.configStore.whitelist.contains(name);
}
}