Skip to content

Commit

Permalink
Fix compatibility issues with max health lower than 20; resolves #137
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Aug 20, 2016
1 parent 6ae1118 commit ff7e8db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,6 +170,21 @@ public void setOldExp(float exp) {
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
*/
Expand Down Expand Up @@ -321,7 +337,8 @@ public void load() {

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");

Expand Down Expand Up @@ -354,6 +371,7 @@ public void savePlayerState(Player player) {
oldGameMode = player.getGameMode();
oldFireTicks = player.getFireTicks();
oldFoodLevel = player.getFoodLevel();
oldHealthScale = player.getHealthScale();
oldHealth = player.getHealth();
oldExp = player.getExp();
oldLvl = player.getLevel();
Expand All @@ -366,6 +384,7 @@ public void savePlayerState(Player player) {
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);
Expand All @@ -385,6 +404,7 @@ public void clearPlayerState() {
oldGameMode = null;
oldFireTicks = 0;
oldFoodLevel = 0;
oldHealthScale = 0;
oldHealth = 0;
oldExp = 0;
oldLvl = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public void reset(boolean keepInventory) {
}
player.setLevel(data.getOldLevel());
player.setExp(data.getOldExp());
player.setHealthScale(data.getOldHealthScale());
player.setHealth(data.getOldHealth());
player.setFoodLevel(data.getOldFoodLevel());
player.setGameMode(data.getOldGameMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ public boolean isAnnouncerEnabled() {
* 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());
}
}

Expand Down

0 comments on commit ff7e8db

Please sign in to comment.