package net.knarcraft.minigames.arena.parkour; import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; import java.util.UUID; /** * A registry to keep track of which players are playing in which arenas */ public class ParkourArenaPlayerRegistry implements ArenaPlayerRegistry { private final Map arenaPlayers = new HashMap<>(); /** * Registers that the given player has started playing the given parkour arena session * * @param playerId

The id of the player that started playing

* @param arena

The arena session to register

*/ public void registerPlayer(@NotNull UUID playerId, @NotNull ParkourArenaSession arena) { this.arenaPlayers.put(playerId, arena); } /** * Removes this player from players currently playing * * @param playerId

The id of the player to remove

*/ public boolean removePlayer(@NotNull UUID playerId) { return this.arenaPlayers.remove(playerId) != null; } /** * Gets the player's active parkour arena session * * @param playerId

The id of the player to get arena for

* @return

The player's active arena session, or null if not currently playing

*/ public @Nullable ParkourArenaSession getArenaSession(@NotNull UUID playerId) { return this.arenaPlayers.getOrDefault(playerId, null); } @Override public void removeForArena(ParkourArena arena, boolean immediately) { for (Map.Entry entry : this.arenaPlayers.entrySet()) { if (entry.getValue().getArena() == arena) { // Kick the player gracefully entry.getValue().triggerQuit(immediately); this.arenaPlayers.remove(entry.getKey()); } } } }