package net.knarcraft.minigames.arena.parkour; import net.knarcraft.minigames.arena.AbstractPlayerEntryState; import net.knarcraft.minigames.container.SerializableUUID; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.UUID; /** * The state of a player before entering a parkour arena */ public class ParkourPlayerEntryState extends AbstractPlayerEntryState { /** * Instantiates a new player state * * @param player

The player whose state should be stored

*/ public ParkourPlayerEntryState(@NotNull Player player) { super(player); } /** * Instantiates a new parkour player entry state * * @param playerId

The id of the player whose state this should keep track of

* @param entryLocation

The location the player entered from

* @param originalIsFlying

Whether the player was flying before entering the arena

* @param originalGameMode

The game-mode of the player before entering the arena

* @param originalAllowFlight

Whether the player was allowed flight before entering the arena

* @param originalInvulnerable

Whether the player was invulnerable before entering the arena

* @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

* @param originalSaturation

The saturation 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, double originalHealth, float originalSaturation) { super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth, originalSaturation); } @Override public void setArenaState() { Player player = getPlayer(); if (player == null) { return; } player.setAllowFlight(false); player.setFlying(false); player.setGameMode(GameMode.ADVENTURE); player.setSwimming(false); } /** * Deserializes a ParkourPlayerEntryState from the given data * * @return

The data to deserialize

*/ @SuppressWarnings({"unused", "unchecked"}) public static ParkourPlayerEntryState deserialize(Map data) { UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue(); Location entryLocation = (Location) data.get("entryLocation"); boolean originalIsFlying = getBoolean(data, "originalIsFlying"); GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode")); boolean originalAllowFlight = getBoolean(data, "originalAllowFlight"); boolean originalInvulnerable = getBoolean(data, "originalInvulnerable"); boolean originalIsSwimming = getBoolean(data, "originalIsSwimming"); boolean originalCollideAble = getBoolean(data, "originalCollideAble"); Collection originalPotionEffect = (Collection) data.getOrDefault("originalPotionEffects", new ArrayList<>()); double originalHealth = ((Number) data.get("originalHealth")).doubleValue(); float originalSaturation = ((Number) data.get("originalSaturation")).floatValue(); return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffect, originalHealth, originalSaturation); } }