From 3b6a56836b150b0a2776cea162151e3a6b0f01b0 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:10:33 +0100 Subject: [PATCH] Fixed health handling having two options and not working w/ armour, lead --- changes.md | 8 +++-- .../java/dev/efnilite/ip/config/Option.java | 6 ++-- .../efnilite/ip/player/data/PreviousData.java | 29 +++++++++---------- witp/src/main/resources/config.yml | 4 --- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/changes.md b/changes.md index fffc801e..e5a43e1e 100644 --- a/changes.md +++ b/changes.md @@ -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 \ No newline at end of file +- Improved /ip schematic colouring +- Increased spectator teleport distance (30 -> 100 blocks) +- Increased max block lead (64 -> 128 blocks) \ No newline at end of file diff --git a/witp/src/main/java/dev/efnilite/ip/config/Option.java b/witp/src/main/java/dev/efnilite/ip/config/Option.java index 108333a2..83c9c0ac 100644 --- a/witp/src/main/java/dev/efnilite/ip/config/Option.java +++ b/witp/src/main/java/dev/efnilite/ip/config/Option.java @@ -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; @@ -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"); @@ -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); } } diff --git a/witp/src/main/java/dev/efnilite/ip/player/data/PreviousData.java b/witp/src/main/java/dev/efnilite/ip/player/data/PreviousData.java index 009ab83a..f0f6593a 100644 --- a/witp/src/main/java/dev/efnilite/ip/player/data/PreviousData.java +++ b/witp/src/main/java/dev/efnilite/ip/player/data/PreviousData.java @@ -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; @@ -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(); @@ -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) { @@ -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()) { diff --git a/witp/src/main/resources/config.yml b/witp/src/main/resources/config.yml index b2ae4a23..ff0e6f8b 100644 --- a/witp/src/main/resources/config.yml +++ b/witp/src/main/resources/config.yml @@ -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