mirror of
https://github.com/zeshan321/ActionHealth.git
synced 2024-11-14 23:05:11 +01:00
Added MVdWPlaceholderAPI support and display name placeholder
This commit is contained in:
parent
67a318ff70
commit
f51048b444
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
name: ActionHealth
|
||||
main: com.zeshanaslam.actionhealth.Main
|
||||
version: 3.1.6
|
||||
softdepend: [MVdWPlaceholderAPI]
|
||||
commands:
|
||||
Actionhealth:
|
||||
description: Actionhealth main command.
|
@ -1,5 +1,6 @@
|
||||
package com.zeshanaslam.actionhealth;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -19,26 +20,26 @@ public class HealthUtil {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void sendHealth(Player player, LivingEntity entity, double health) {
|
||||
public void sendHealth(Player receiver, LivingEntity entity, double health) {
|
||||
if (plugin.settingsManager.delay) {
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
String output = getOutput(entity.getHealth(), entity);
|
||||
String output = getOutput(entity.getHealth(), receiver, entity);
|
||||
|
||||
if (output != null)
|
||||
sendActionBar(player, output);
|
||||
sendActionBar(receiver, output);
|
||||
}
|
||||
}.runTaskLater(plugin, 1L);
|
||||
} else {
|
||||
String output = getOutput(health, entity);
|
||||
String output = getOutput(health, receiver, entity);
|
||||
|
||||
if (output != null)
|
||||
sendActionBar(player, output);
|
||||
sendActionBar(receiver, output);
|
||||
}
|
||||
}
|
||||
|
||||
private String getOutput(double health, LivingEntity entity) {
|
||||
private String getOutput(double health, Player receiver, LivingEntity entity) {
|
||||
String name;
|
||||
double maxHealth = entity.getMaxHealth();
|
||||
|
||||
@ -61,6 +62,19 @@ public class HealthUtil {
|
||||
output = output.replace("{health}", String.valueOf((int) health));
|
||||
output = output.replace("{maxhealth}", String.valueOf((int) maxHealth));
|
||||
|
||||
if (entity instanceof Player) {
|
||||
String displayName;
|
||||
Player player = (Player) entity;
|
||||
|
||||
if (player.getDisplayName() == null) {
|
||||
displayName = name;
|
||||
} else {
|
||||
displayName = player.getDisplayName();
|
||||
}
|
||||
|
||||
output = output.replace("{displayname}", displayName);
|
||||
}
|
||||
|
||||
if (output.contains("{usestyle}")) {
|
||||
String style = "";
|
||||
int left = 10;
|
||||
@ -102,6 +116,10 @@ public class HealthUtil {
|
||||
output = output.replace("{usestyle}", style);
|
||||
}
|
||||
|
||||
if (plugin.settingsManager.placeholderAPI) {
|
||||
output = PlaceholderAPI.replacePlaceholders(receiver, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class LookThread extends BukkitRunnable {
|
||||
List<LivingEntity> entities = TargetHelper.getLivingTargets(player, plugin.settingsManager.lookDistance);
|
||||
|
||||
if (!entities.isEmpty()) {
|
||||
for (LivingEntity livingEntity: entities) {
|
||||
for (LivingEntity livingEntity : entities) {
|
||||
if (livingEntity.getType().name().equals("ARMOR_STAND")) continue;
|
||||
|
||||
String name;
|
||||
|
@ -33,6 +33,7 @@ public class SettingsManager {
|
||||
public String toggleMessage;
|
||||
public String enableMessage;
|
||||
public String disableMessage;
|
||||
public boolean placeholderAPI;
|
||||
|
||||
public SettingsManager(Main plugin) {
|
||||
// Clear settings for reloads
|
||||
@ -42,6 +43,9 @@ public class SettingsManager {
|
||||
|
||||
if (plugin.taskID != -1) Bukkit.getScheduler().cancelTask(plugin.taskID);
|
||||
|
||||
// Check if using MVdWPlaceholderAPI
|
||||
placeholderAPI = Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI ");
|
||||
|
||||
// Get settings from config
|
||||
healthMessage = plugin.getConfig().getString("Health Message");
|
||||
usePerms = plugin.getConfig().getBoolean("Use Permissions");
|
||||
|
Loading…
Reference in New Issue
Block a user