From 2ec15c69c787510268e91495ce277f524c69fc20 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 16 May 2024 13:32:58 +0200 Subject: [PATCH] Restores player health upon arena exit --- .../minigames/arena/AbstractPlayerEntryState.java | 11 +++++++++-- .../arena/dropper/DropperPlayerEntryState.java | 13 ++++++++----- .../arena/parkour/ParkourPlayerEntryState.java | 10 +++++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java index 2ce326f..96c86d5 100644 --- a/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java @@ -36,6 +36,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { private final boolean originalInvulnerable; private final boolean originalIsSwimming; private final boolean originalCollideAble; + private final double originalHealth; private final Collection originalPotionEffects; /** @@ -52,6 +53,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { this.originalInvulnerable = player.isInvulnerable(); this.originalIsSwimming = player.isSwimming(); this.originalCollideAble = player.isCollidable(); + this.originalHealth = player.getHealth(); // Store and clear potion effects this.originalPotionEffects = getPlayer().getActivePotionEffects(); @@ -72,11 +74,13 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { * @param originalIsSwimming

Whether the player was swimming before entering the arena

* @param originalCollideAble

Whether the player was collide-able before entering the arena

* @param originalPotionEffects

The potion effects applied to the player when joining

+ * @param originalHealth

The health of the player when joining the arena

*/ - public AbstractPlayerEntryState(@NotNull UUID playerId, Location entryLocation, + public AbstractPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, boolean originalInvulnerable, boolean originalIsSwimming, - boolean originalCollideAble, Collection originalPotionEffects) { + boolean originalCollideAble, @NotNull Collection originalPotionEffects, + double originalHealth) { this.playerId = playerId; this.entryLocation = entryLocation; this.originalIsFlying = originalIsFlying; @@ -86,6 +90,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { this.originalIsSwimming = originalIsSwimming; this.originalCollideAble = originalCollideAble; this.originalPotionEffects = originalPotionEffects; + this.originalHealth = originalHealth; } @Override @@ -115,6 +120,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { player.addPotionEffect(potionEffect); } removeMenuItem(player); + player.setHealth(originalHealth); } @Override @@ -149,6 +155,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { data.put("originalIsSwimming", this.originalIsSwimming); data.put("originalCollideAble", this.originalCollideAble); data.put("originalPotionEffects", this.originalPotionEffects); + data.put("originalHealth", this.originalHealth); return data; } diff --git a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java index 7edf216..68b542e 100644 --- a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java @@ -49,15 +49,16 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState { * @param horizontalVelocity

The horizontal velocity of the player before entering the arena

* @param originalCollideAble

Whether the player was collide-able before entering the arena

* @param originalPotionEffects

The potion effects applied to the player when joining

+ * @param originalHealth

The health of the player when joining the arena

*/ - public DropperPlayerEntryState(@NotNull UUID playerId, Location entryLocation, + public DropperPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, boolean originalInvulnerable, boolean originalIsSwimming, float originalFlySpeed, float horizontalVelocity, - DropperArenaGameMode arenaGameMode, boolean originalCollideAble, - Collection originalPotionEffects) { + @NotNull DropperArenaGameMode arenaGameMode, boolean originalCollideAble, + @NotNull Collection originalPotionEffects, double originalHealth) { super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, - originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects); + originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth); this.originalFlySpeed = originalFlySpeed; this.horizontalVelocity = horizontalVelocity; this.arenaGameMode = arenaGameMode; @@ -128,10 +129,12 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState { boolean originalCollideAble = getBoolean(data, "originalCollideAble"); Collection originalPotionEffect = (Collection) data.getOrDefault("originalPotionEffects", new ArrayList<>()); + double originalHealth = ((Number) data.get("originalHealth")).doubleValue(); return new DropperPlayerEntryState(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, - originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble, originalPotionEffect); + originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble, originalPotionEffect, + originalHealth); } } diff --git a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java index c95b8bf..c641b48 100644 --- a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java @@ -39,13 +39,15 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState { * @param originalIsSwimming

Whether the player was swimming before entering the arena

* @param originalCollideAble

Whether the player was collide-able before entering the arena

* @param originalPotionEffects

The potion effects applied to the player when joining

+ * @param originalHealth

The health of the player when joining the arena

*/ public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, boolean originalInvulnerable, boolean originalIsSwimming, - boolean originalCollideAble, Collection originalPotionEffects) { + boolean originalCollideAble, Collection originalPotionEffects, + double originalHealth) { super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, - originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects); + originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth); } @Override @@ -77,9 +79,11 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState { boolean originalCollideAble = getBoolean(data, "originalCollideAble"); Collection originalPotionEffect = (Collection) data.getOrDefault("originalPotionEffects", new ArrayList<>()); + double originalHealth = ((Number) data.get("originalHealth")).doubleValue(); return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying, originalGameMode, - originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffect); + originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble, + originalPotionEffect, originalHealth); } }