Added alterative placeholders in case being overridden

This commit is contained in:
Zeshan Aslam 2021-06-08 18:57:07 -04:00
parent 9e2121e7f4
commit 6c0a799198
10 changed files with 32 additions and 39 deletions

View File

@ -6,6 +6,7 @@
# {displayname} will use player/mob custom name.
# {opponentlastdamage} the amount of damage the enemy last received.
# {percenthealth} displays the percentage of health left.
# Note: if placeholders are being overridden by other plugins you can add 'ah' in front of it i.e {ahhealth}
#
# For PlaceholderAPI or MVdWPlaceholderAPI:
# By default placeholders will be retrieved as the attacking player.

View File

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

View File

@ -35,7 +35,7 @@ public class LookThread extends BukkitRunnable {
for (Player player : Bukkit.getOnlinePlayers()) {
if (plugin.toggle.contains(player.getUniqueId())) {
if (plugin.configStore.toggleMessage != null && !plugin.configStore.toggleMessage.equals("")) {
plugin.healthUtil.sendActionBar(player, plugin.configStore.toggleMessage.replace("{name}", player.getName()));
plugin.healthUtil.sendActionBar(player, plugin.healthUtil.replacePlaceholders(plugin.configStore.toggleMessage, "name", player.getName()));
}
continue;
}

View File

@ -16,7 +16,6 @@ import org.bukkit.projectiles.ProjectileSource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public class ActionHelper {
@ -28,7 +27,7 @@ public class ActionHelper {
public void executeTriggers(ActionStore.ActionType actionType, Player player, ItemStack itemStack) {
if (itemStack != null) {
for (String name: getName(itemStack))
for (String name : getName(itemStack))
executeTriggers(actionType, player, name);
}
}

View File

@ -4,7 +4,6 @@ import com.zeshanaslam.actionhealth.Main;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
@ -15,15 +14,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.projectiles.ProjectileSource;
import java.util.ArrayList;
import java.util.List;
public class ActionListener implements Listener {
@ -113,7 +103,7 @@ public class ActionListener implements Listener {
ActionStore.ActionType actionType = ActionStore.ActionType.RIGHTCLICK;
actionHelper.executeTriggers(actionType, player, itemStack);
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
ActionStore.ActionType actionType = ActionStore.ActionType.LEFTCLICK;
actionHelper.executeTriggers(actionType, player, itemStack);
}

View File

@ -1,4 +1,5 @@
package com.zeshanaslam.actionhealth.action;
import com.zeshanaslam.actionhealth.Main;
import com.zeshanaslam.actionhealth.action.data.Action;
import com.zeshanaslam.actionhealth.action.data.Tagged;
@ -22,11 +23,11 @@ public class ActionStore {
this.main = main;
enabled = main.getConfig().getBoolean("Action.Enabled");
tagLength = main.getConfig().getInt("Action.TagLength");
tagAmount = main.getConfig().getInt("Action.TagAmount");
tagAmount = main.getConfig().getInt("Action.TagAmount");
events = new HashMap<>();
for (String action: main.getConfig().getConfigurationSection("Action.Events").getKeys(false)) {
for (String type: main.getConfig().getConfigurationSection("Action.Events." + action).getKeys(false)) {
for (String action : main.getConfig().getConfigurationSection("Action.Events").getKeys(false)) {
for (String type : main.getConfig().getConfigurationSection("Action.Events." + action).getKeys(false)) {
String output = main.getConfig().getString("Action.Events." + action + "." + type);
ActionType actionType = ActionType.valueOf(action);
@ -70,8 +71,8 @@ public class ActionStore {
}
private void sendMessage(LivingEntity entity, String message, Optional<Double> health) {
for (List<Tagged> taggedList: tagged.values()) {
for (Tagged tagged: taggedList) {
for (List<Tagged> taggedList : tagged.values()) {
for (Tagged tagged : taggedList) {
if (tagged.damaged.equals(entity.getUniqueId())) {
Player damager = Bukkit.getServer().getPlayer(tagged.damager);

View File

@ -17,7 +17,7 @@ public class ActionTask extends BukkitRunnable {
@Override
public void run() {
for (UUID key: main.configStore.actionStore.tagged.keySet()) {
for (UUID key : main.configStore.actionStore.tagged.keySet()) {
Iterator<Tagged> taggedIterator = main.configStore.actionStore.tagged.get(key).iterator();
while (taggedIterator.hasNext()) {
Tagged tagged = taggedIterator.next();

View File

@ -42,11 +42,12 @@ public class HealthCommand implements CommandExecutor {
if (plugin.toggle.contains(player.getUniqueId())) {
plugin.toggle.remove(player.getUniqueId());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.configStore.enableMessage).replace("{name}", player.getName()));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.healthUtil.replacePlaceholders(plugin.configStore.enableMessage, "name", player.getName())));
} else {
plugin.toggle.add(player.getUniqueId());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.configStore.disableMessage).replace("{name}", player.getName()));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.healthUtil.replacePlaceholders(plugin.configStore.disableMessage, "name", player.getName())));
}
if (plugin.configStore.rememberToggle) {

View File

@ -2,7 +2,6 @@ package com.zeshanaslam.actionhealth.events;
import com.zeshanaslam.actionhealth.Main;
import com.zeshanaslam.actionhealth.utils.FileHandler;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -11,7 +10,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

View File

@ -1,6 +1,5 @@
package com.zeshanaslam.actionhealth.utils;
import be.maximvdw.placeholderapi.PlaceholderAPI;
import com.zeshanaslam.actionhealth.Main;
import com.zeshanaslam.actionhealth.api.HealthSendEvent;
import com.zeshanaslam.actionhealth.support.*;
@ -103,16 +102,16 @@ public class HealthUtil {
displayName = player.getDisplayName();
}
output = output.replace("{displayname}", displayName);
output = replacePlaceholders(output, "displayname", displayName);
// Set placeholders as attacker
if (plugin.configStore.hasMVdWPlaceholderAPI) {
output = output.replace("ATTACKEDPLAYER_", "");
output = replacePlaceholders(output, "ATTACKEDPLAYER_", "");
output = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, output);
}
if (plugin.configStore.hasPlaceholderAPI) {
output = output.replace("ATTACKEDPLAYER_", "");
output = replacePlaceholders(output, "ATTACKEDPLAYER_", "");
output = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, output);
}
} else {
@ -120,7 +119,7 @@ public class HealthUtil {
output = plugin.configStore.healthMessageOther;
}
output = output.replace("{displayname}", name);
output = replacePlaceholders(output, "displayname", name);
}
// Set placeholders as receiver
@ -132,13 +131,13 @@ public class HealthUtil {
output = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(receiver, output);
}
output = output.replace("{name}", name);
output = output.replace("{health}", String.valueOf((int) health));
output = output.replace("{maxhealth}", String.valueOf((int) maxHealth));
output = output.replace("{percenthealth}", String.valueOf((int) ((health / maxHealth) * 100.0)));
output = output.replace("{opponentlastdamage}", String.valueOf((int) entity.getLastDamage()));
output = replacePlaceholders(output, "name", name);
output = replacePlaceholders(output, "health", String.valueOf((int) health));
output = replacePlaceholders(output, "maxhealth", String.valueOf((int) maxHealth));
output = replacePlaceholders(output, "percenthealth", String.valueOf((int) ((health / maxHealth) * 100.0)));
output = replacePlaceholders(output, "opponentlastdamage", String.valueOf((int) entity.getLastDamage()));
if (output.contains("{usestyle}")) {
if (output.contains("usestyle")) {
StringBuilder style = new StringBuilder();
int left = getLimitHealth(maxHealth);
double heart = maxHealth / getLimitHealth(maxHealth);
@ -176,7 +175,7 @@ public class HealthUtil {
}
}
output = output.replace("{usestyle}", style.toString());
output = replacePlaceholders(output, "usestyle", style.toString());
}
HealthSendEvent healthSendEvent = new HealthSendEvent(receiver, entity, output);
@ -234,6 +233,10 @@ public class HealthUtil {
return name;
}
public String replacePlaceholders(String s, String key, String value) {
return s.replace("{" + key + "}", value).replace("{ah" + key + "}", value);
}
private String getNameReflection(LivingEntity entity) {
String name;
Method getName = null;
@ -265,7 +268,7 @@ public class HealthUtil {
message = ChatColor.translateAlternateColorCodes('&', message);
try {
if(plugin.configStore.mcVersion.equals("v1_16_R1") || plugin.configStore.mcVersion.equals("v1_16_R2") || plugin.configStore.mcVersion.equals("v1_16_R3")){
if (plugin.configStore.mcVersion.equals("v1_16_R1") || plugin.configStore.mcVersion.equals("v1_16_R2") || plugin.configStore.mcVersion.equals("v1_16_R3")) {
new PreAction(player, message);
} else if (plugin.configStore.mcVersion.equals("v1_12_R1") || plugin.configStore.mcVersion.startsWith("v1_13") || plugin.configStore.mcVersion.startsWith("v1_14_") || plugin.configStore.mcVersion.startsWith("v1_15_")) {
new LegacyPreAction(player, message);
@ -373,7 +376,7 @@ public class HealthUtil {
private void sendMessage(Player player) {
if (plugin.configStore.toggleMessage != null && !plugin.configStore.toggleMessage.equals("")) {
plugin.healthUtil.sendActionBar(player, plugin.configStore.toggleMessage.replace("{name}", player.getName()));
plugin.healthUtil.sendActionBar(player, replacePlaceholders(plugin.configStore.toggleMessage, "name", player.getName()));
}
}