Updated limit health and upper limit health

This commit is contained in:
Zeshan Aslam 2020-07-04 13:31:13 -04:00
parent ae20ed7af6
commit faab244c85
4 changed files with 36 additions and 5 deletions

View File

@ -61,9 +61,14 @@ Disabled regions:
# Disable ActionHealth in regions where PvP is denied.
Region PvP: true
# Limits the health style to a certain amount of symbols.
# Limits the health style to a certain amount of symbols. Static limit (-1 to disable)
# Limit health WILL accurately still display the entities health.
Limit Health: 10
# If 'Limit Health' is set to -1. With 'Upper Limit Health' you can trigger 'Limit Health' logic to prevent 'Use Style' going off screen'
# '40 -> 10' = If health over 40, use limit health 10. Leave empty to disable
Upper Limit Health: "40 -> 10"
# Saves players /actionhealth toggle state.
# Uses flat file. If interested in SQL support ask in discussion.
Remember Toggle: false

View File

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

View File

@ -52,6 +52,9 @@ public class ConfigStore {
public long checkTicks;
public ActionStore actionStore;
public List<String> whitelist = new ArrayList<>();
public String upperLimit;
public int upperLimitStart;
public int upperLimitLength;
public ConfigStore(Main plugin) {
// Clear settings for reloads
@ -197,6 +200,16 @@ public class ConfigStore {
plugin.taskID = -1;
showOnLook = false;
}
if (plugin.getConfig().contains("Upper Limit Health")) {
upperLimit = plugin.getConfig().getString("Upper Limit Health");
String[] limits = upperLimit.split(" -> ");
upperLimitStart = Integer.parseInt(limits[0]);
upperLimitLength = Integer.parseInt(limits[1]);
} else {
upperLimit = null;
}
}
public boolean isUsingWhiteList() {

View File

@ -127,13 +127,13 @@ public class HealthUtil {
if (output.contains("{usestyle}")) {
StringBuilder style = new StringBuilder();
int left = plugin.configStore.limitHealth;
double heart = maxHealth / plugin.configStore.limitHealth;
int left = getLimitHealth(maxHealth);
double heart = maxHealth / getLimitHealth(maxHealth);
double halfHeart = heart / 2;
double tempHealth = health;
if (maxHealth != health && health >= 0 && !entity.isDead()) {
for (int i = 0; i < plugin.configStore.limitHealth; i++) {
for (int i = 0; i < getLimitHealth(maxHealth); i++) {
if (tempHealth - heart > 0) {
tempHealth = tempHealth - heart;
@ -176,6 +176,19 @@ public class HealthUtil {
return output;
}
public int getLimitHealth(double maxHealth) {
if (plugin.configStore.limitHealth == -1) {
int health = (int) maxHealth;
if (plugin.configStore.upperLimit != null) {
return (health >= plugin.configStore.upperLimitStart) ? plugin.configStore.upperLimitLength : health;
}
return health;
}
return plugin.configStore.limitHealth;
}
public String getName(LivingEntity entity, Player receiver) {
String name;