Class DuelSession
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSpectator
(@NotNull UUID playerId) Adds a player as a spectator to the duel.getOpponent
(@NotNull UUID playerId) Gets the opponent's UUID for the given player ID.Gets the set of all spectators of the duel.void
Increments the win count for the given player and advances to the next round.boolean
isSpectator
(@NotNull UUID playerId) Checks if a player is currently spectating the duel.int
Calculates how many more rounds the specified player needs to win to win the duel.boolean
over()
Determines if the duel is over.void
removeSpectator
(@NotNull UUID playerId) Removes a player from the list of spectators.int
Gets the current score for the specified player.winner()
Determines the winner of the duel.
-
Constructor Details
-
DuelSession
public DuelSession(DuelArena arena, String displayName, UUID player1, UUID player2, String kit, int rounds) Constructs a new DuelSession.This initializes the session with the provided arena, display name, players, kit, and total rounds.
- Parameters:
arena
- The arena where the duel takes place.displayName
- The display name of the arena.player1
- The first player participating in the duel.player2
- The second player participating in the duel.kit
- The kit used in the duel.rounds
- The total number of rounds in the duel.
-
-
Method Details
-
getOpponent
Gets the opponent's UUID for the given player ID.This method returns the UUID of the opposing player in the duel.
- Parameters:
playerId
- The UUID of the player whose opponent is being retrieved.- Returns:
- The UUID of the opponent.
- Throws:
IllegalArgumentException
- if the player ID does not belong to either of the duel participants.
-
over
public boolean over()Determines if the duel is over.The duel is over when one player has won the required number of rounds.
- Returns:
- true if the duel is over, false otherwise.
-
increment
Increments the win count for the given player and advances to the next round.This method updates the round and the score based on which player won the current round.
- Parameters:
winnerId
- The UUID of the player who won the round.
-
winner
Determines the winner of the duel.This method returns the UUID of the player who has won the duel (i.e., who reached the total number of wins).
- Returns:
- The UUID of the winner, or null if the duel is not over yet.
-
needed
Calculates how many more rounds the specified player needs to win to win the duel.This method is used to determine how close a player is to winning the duel.
- Parameters:
playerId
- The UUID of the player whose required wins are being calculated.- Returns:
- The number of rounds the player needs to win to finish the duel.
- Throws:
IllegalArgumentException
- if the player ID does not belong to either of the duel participants.
-
score
Gets the current score for the specified player.This method returns the number of rounds won by the specified player in the duel.
- Parameters:
playerId
- The UUID of the player whose score is being retrieved.- Returns:
- The number of rounds won by the player.
- Throws:
IllegalArgumentException
- if the player ID does not belong to either of the duel participants.
-
addSpectator
Adds a player as a spectator to the duel.This method allows a player to spectate the duel without participating directly.
- Parameters:
playerId
- The UUID of the player who will be added as a spectator.- Throws:
NullPointerException
- if the playerId is null.
-
removeSpectator
Removes a player from the list of spectators.This method removes a player from the list of spectators, meaning they will no longer be able to spectate the duel.
- Parameters:
playerId
- The UUID of the player to be removed from the spectators.- Throws:
NullPointerException
- if the playerId is null.
-
isSpectator
Checks if a player is currently spectating the duel.This method returns true if the player is in the list of spectators, false otherwise.
- Parameters:
playerId
- The UUID of the player being checked.- Returns:
- true if the player is a spectator, false otherwise.
- Throws:
NullPointerException
- if the playerId is null.
-
getSpectators
Gets the set of all spectators of the duel.This method returns an unmodifiable set of UUIDs representing all players currently spectating the duel.
- Returns:
- An unmodifiable set containing the UUIDs of all spectators.
-