Use attribute base value instead of 20 when setting player health.

The previous hardcoded value of `20.0` works in most cases, but if a server uses a base health higher than 20, players don't get a full heal. Worse, if the base health is lower than 20, MobArena crashes when it tries to set the health to 20, which is now out of range.

This commit introduces the Attribute enum to MobArena's code base and uses it to get the base value for player max health. This should fix the aforementioned issues.

Fixes #513
This commit is contained in:
Andreas Troelsen
2019-02-16 17:41:55 +01:00
parent afcc526a71
commit 93af93d5a0
3 changed files with 9 additions and 3 deletions
@@ -35,6 +35,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.ConfigurationSection;
@@ -834,7 +835,9 @@ public class ArenaImpl implements Arena
return;
}
p.setHealth(20.0);
double full = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
p.setHealth(full);
plugin.getServer().getScheduler()
.scheduleSyncDelayedTask(plugin, () -> revivePlayer(p));
endArena();
@@ -1,9 +1,9 @@
package com.garbagemule.MobArena.steps;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
class SetHealth extends PlayerStep {
private static final double FULL_HEALTH = 20.0;
private static final int NORMAL_FIRE = -20;
private static final int NORMAL_AIR = 300;
@@ -23,7 +23,9 @@ class SetHealth extends PlayerStep {
player.setRemainingAir(NORMAL_AIR);
player.setFireTicks(NORMAL_FIRE);
player.setHealth(FULL_HEALTH);
double full = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
player.setHealth(full);
}
@Override