Fix compatibility issues with max health lower than 20; resolves #137

This commit is contained in:
Daniel Saukel 2016-08-20 23:34:03 +02:00
parent 6ae1118056
commit ff7e8dbf5f
3 changed files with 31 additions and 9 deletions

View File

@ -53,6 +53,7 @@ public class PlayerData extends BRConfig {
private ItemStack oldOffHand;
private int oldLvl;
private float oldExp;
private double oldHealthScale;
private double oldHealth;
private int oldFoodLevel;
private int oldFireTicks;
@ -169,6 +170,21 @@ public class PlayerData extends BRConfig {
oldExp = exp;
}
/**
* @return the old health scale
*/
public double getOldHealthScale() {
return oldHealthScale;
}
/**
* @param healthScale
* the healthScale to set
*/
public void setOldHealthScale(double healthScale) {
oldHealthScale = healthScale;
}
/**
* @return the old health
*/
@ -321,7 +337,8 @@ public class PlayerData extends BRConfig {
oldLvl = config.getInt(PREFIX_STATE_PERSISTENCE + "oldLvl");
oldExp = config.getInt(PREFIX_STATE_PERSISTENCE + "oldExp");
oldHealth = config.getInt(PREFIX_STATE_PERSISTENCE + "oldHealth");
oldHealthScale = config.getDouble(PREFIX_STATE_PERSISTENCE + "oldHealthScale");
oldHealth = config.getDouble(PREFIX_STATE_PERSISTENCE + "oldHealth");
oldFoodLevel = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFoodLevel");
oldFireTicks = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFireTicks");
@ -354,6 +371,7 @@ public class PlayerData extends BRConfig {
oldGameMode = player.getGameMode();
oldFireTicks = player.getFireTicks();
oldFoodLevel = player.getFoodLevel();
oldHealthScale = player.getHealthScale();
oldHealth = player.getHealth();
oldExp = player.getExp();
oldLvl = player.getLevel();
@ -366,6 +384,7 @@ public class PlayerData extends BRConfig {
config.set(PREFIX_STATE_PERSISTENCE + "oldGameMode", oldGameMode.toString());
config.set(PREFIX_STATE_PERSISTENCE + "oldFireTicks", oldFireTicks);
config.set(PREFIX_STATE_PERSISTENCE + "oldFoodLevel", oldFoodLevel);
config.set(PREFIX_STATE_PERSISTENCE + "oldHealthScale", oldHealthScale);
config.set(PREFIX_STATE_PERSISTENCE + "oldHealth", oldHealth);
config.set(PREFIX_STATE_PERSISTENCE + "oldExp", oldExp);
config.set(PREFIX_STATE_PERSISTENCE + "oldLvl", oldLvl);
@ -385,6 +404,7 @@ public class PlayerData extends BRConfig {
oldGameMode = null;
oldFireTicks = 0;
oldFoodLevel = 0;
oldHealthScale = 0;
oldHealth = 0;
oldExp = 0;
oldLvl = 0;

View File

@ -277,6 +277,7 @@ public class DGlobalPlayer {
}
player.setLevel(data.getOldLevel());
player.setExp(data.getOldExp());
player.setHealthScale(data.getOldHealthScale());
player.setHealth(data.getOldHealth());
player.setFoodLevel(data.getOldFoodLevel());
player.setGameMode(data.getOldGameMode());

View File

@ -77,14 +77,15 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
* Clear the player's inventory, potion effects etc.
*/
public void clearPlayerData() {
getPlayer().getInventory().clear();
getPlayer().getInventory().setArmorContents(null);
getPlayer().setTotalExperience(0);
getPlayer().setLevel(0);
getPlayer().setHealth(20);
getPlayer().setFoodLevel(20);
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
getPlayer().removePotionEffect(effect.getType());
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.setTotalExperience(0);
player.setLevel(0);
player.setHealthScale(20);
player.setHealth(20);
player.setFoodLevel(20);
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
}