mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-12-21 02:08:47 +01:00
94 lines
4.5 KiB
Java
94 lines
4.5 KiB
Java
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 <p>The player whose state should be stored</p>
|
|
*/
|
|
public ParkourPlayerEntryState(@NotNull Player player) {
|
|
super(player);
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new parkour player entry state
|
|
*
|
|
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
|
* @param entryLocation <p>The location the player entered from</p>
|
|
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
|
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
|
* @param originalAllowFlight <p>Whether the player was allowed flight before entering the arena</p>
|
|
* @param originalInvulnerable <p>Whether the player was invulnerable before entering the arena</p>
|
|
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
|
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
|
* @param originalPotionEffects <p>The potion effects applied to the player when joining</p>
|
|
* @param originalHealth <p>The health of the player when joining the arena</p>
|
|
* @param originalSaturation <p>The saturation of the player when joining the arena</p>
|
|
*/
|
|
public ParkourPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation,
|
|
boolean originalIsFlying, @NotNull GameMode originalGameMode, boolean originalAllowFlight,
|
|
boolean originalInvulnerable, boolean originalIsSwimming,
|
|
boolean originalCollideAble, @NotNull Collection<PotionEffect> 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 <p>The data to deserialize</p>
|
|
*/
|
|
@SuppressWarnings({"unused", "unchecked"})
|
|
@NotNull
|
|
public static ParkourPlayerEntryState deserialize(@NotNull Map<String, Object> 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<PotionEffect> originalPotionEffect =
|
|
(Collection<PotionEffect>) 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);
|
|
}
|
|
|
|
}
|