Skip to content

Commit

Permalink
Fixed health handling having two options and not working w/ armour, lead
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Mar 18, 2023
1 parent b8ededb commit 3b6a568
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
8 changes: 6 additions & 2 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- Fixed /ip schematic wand not working
- Fixed disabling settings with permissions not working
- Fixed spectators not being visible in player menus
- Fixed spectators teleport distance being too small
- Fixed "player doesn't exist" for placeholders that don't require player
- Fixed health handling having two config options
- Fixed health handling not working with armour or health effects
- Improved /ip schematic logic
- Improved /ip schematic colouring
- Improved /ip schematic colouring
- Increased spectator teleport distance (30 -> 100 blocks)
- Increased max block lead (64 -> 128 blocks)
6 changes: 2 additions & 4 deletions witp/src/main/java/dev/efnilite/ip/config/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class Option {

public static boolean JOINING;
public static boolean PERMISSIONS_STYLES;
public static boolean SAVE_STATS;
public static boolean SETTINGS_ENABLED;
public static boolean HEALTH_HANDLING;
public static boolean INVENTORY_SAVING;
Expand Down Expand Up @@ -87,7 +86,6 @@ public static void init(boolean firstLoad) {

// Options

SAVE_STATS = config.getBoolean("options.save-stats");
SETTINGS_ENABLED = config.getBoolean("options.enabled");
OPTIONS_TIME_FORMAT = config.getInt("options.time.format");
HEALTH_HANDLING = config.getBoolean("options.health-handling");
Expand Down Expand Up @@ -130,8 +128,8 @@ public static void init(boolean firstLoad) {

POSSIBLE_LEADS = config.getIntegerList("options.leads.amount");
for (int lead : new ArrayList<>(POSSIBLE_LEADS)) {
if (lead < 1 || lead > 64) {
IP.logging().error("Invalid lead in config: found " + lead + ", should be above 1 and below 64 to prevent lag.");
if (lead < 1 || lead > 128) {
IP.logging().error("Invalid lead in config: found " + lead + ", should be above 1 and below 128 to prevent lag on spawn.");
POSSIBLE_LEADS.remove((Object) lead);
}
}
Expand Down
29 changes: 13 additions & 16 deletions witp/src/main/java/dev/efnilite/ip/player/data/PreviousData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
public class PreviousData {

private double health;
private double maxHealth;
private Double health;
private Double maxHealth;
private InventoryData inventoryData;

private final boolean allowFlight;
Expand All @@ -48,16 +48,6 @@ public PreviousData(@NotNull Player player) {
flying = player.getAllowFlight();
collidable = player.isCollidable();

if (Option.SAVE_STATS) {
this.health = player.getHealth();
this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
}

if (Option.HEALTH_HANDLING) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue());
}

if (Option.INVENTORY_HANDLING) {
this.inventoryData = new InventoryData(player);
this.inventoryData.saveInventory();
Expand All @@ -70,6 +60,15 @@ public PreviousData(@NotNull Player player) {
for (PotionEffect effect : effects) {
player.removePotionEffect(effect.getType());
}

// health handling after removing effects and inventory to avoid them affecting it
if (Option.HEALTH_HANDLING) {
this.health = player.getHealth();
this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();

player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
player.setHealth(maxHealth);
}
}

public void apply(boolean teleportBack) {
Expand All @@ -90,10 +89,8 @@ public void apply(boolean teleportBack) {
player.setCollidable(collidable);

// -= Attributes =-
if (Option.SAVE_STATS && Option.HEALTH_HANDLING) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
player.setHealth(health);
}
if (maxHealth != null) player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
if (health != null) player.setHealth(health);

// -= Potions =-
for (PotionEffect effect : player.getActivePotionEffects()) {
Expand Down
4 changes: 0 additions & 4 deletions witp/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ options:
# Disable this if you're experiencing errors with max health, etc.
health-handling: true

# -= Stats saving =-
# Saves things like (max) health, clears effects, etc. for when a player joins the parkour.
save-stats: true

# -= Permissions options =-
# These permissions are used to determine which things the player can change.
# Find them at at https://efnilite.github.io/efnilite.dev/wiki/witp
Expand Down

0 comments on commit 3b6a568

Please sign in to comment.