Remove IN_GAME player state and related logic; integrate destination-based teleportation during round progression.

This commit is contained in:
akastijn 2026-05-30 00:10:35 +02:00
parent 0cf662dfef
commit d3946bc16a
6 changed files with 26 additions and 13 deletions

View File

@ -101,8 +101,7 @@ A Minecraft survival/PvP plugin with configurable loot, shrinking world border,
### Player States ### Player States
Track each registered player in one of these states: Track each registered player in one of these states:
- [ ] `REGISTERED` — signed up, round not yet started - [ ] `REGISTERED` — signed up or in game (depending on round state)
- [ ] `IN_GAME` — actively in the round
- [ ] `DISCONNECTED` — left the server mid-round - [ ] `DISCONNECTED` — left the server mid-round
- [ ] `SPECTATING` — non-participant/dead observer - [ ] `SPECTATING` — non-participant/dead observer

View File

@ -6,6 +6,7 @@ import com.alttd.hunger_games.config.Messages;
import com.alttd.hunger_games.event_listeners.PlayerDisconnectListener; import com.alttd.hunger_games.event_listeners.PlayerDisconnectListener;
import com.alttd.hunger_games.event_listeners.PlayerJoinListener; import com.alttd.hunger_games.event_listeners.PlayerJoinListener;
import com.alttd.hunger_games.services.PlayerService; import com.alttd.hunger_games.services.PlayerService;
import com.alttd.hunger_games.services.PlayerTeleporterService;
import com.alttd.hunger_games.services.Round; import com.alttd.hunger_games.services.Round;
import com.alttd.hunger_games.services.RoundService; import com.alttd.hunger_games.services.RoundService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -17,6 +18,7 @@ public final class Main extends JavaPlugin {
private RoundService roundService; private RoundService roundService;
private PlayerService playerService; private PlayerService playerService;
private PlayerTeleporterService playerTeleporterService;
@Override @Override
public void onEnable() { public void onEnable() {
@ -31,7 +33,8 @@ public final class Main extends JavaPlugin {
private void registerServices() { private void registerServices() {
Round round = Round.createSingletonInstance(); Round round = Round.createSingletonInstance();
roundService = RoundService.createSingletonInstance(round); roundService = RoundService.createSingletonInstance(round);
playerService = new PlayerService(roundService); playerTeleporterService = PlayerTeleporterService.createSingletonInstance();
playerService = PlayerService.createSingletonInstance(roundService, playerTeleporterService);
} }
@Override @Override

View File

@ -67,7 +67,6 @@ public class Register extends SubCommand {
switch (nullablePlayerState) { switch (nullablePlayerState) {
case REGISTERED -> log.info("Registered player {} for the next round", playerToRegister.getName()); case REGISTERED -> log.info("Registered player {} for the next round", playerToRegister.getName());
case IN_GAME -> log.info("Player {} is already in a round", playerToRegister.getName());
case DISCONNECTED -> log.info("Player {} is disconnected (should not be possible)", playerToRegister.getName()); case DISCONNECTED -> log.info("Player {} is disconnected (should not be possible)", playerToRegister.getName());
case SPECTATING -> log.info("Player {} is now spectating the game", playerToRegister.getName()); case SPECTATING -> log.info("Player {} is now spectating the game", playerToRegister.getName());
} }
@ -83,8 +82,6 @@ public class Register extends SubCommand {
switch (playerState) { switch (playerState) {
case REGISTERED -> commandPlayer.sendRichMessage(Messages.REGISTER.PLAYER_REGISTERED, case REGISTERED -> commandPlayer.sendRichMessage(Messages.REGISTER.PLAYER_REGISTERED,
Placeholder.component("player", playerToRegister.name())); Placeholder.component("player", playerToRegister.name()));
case IN_GAME -> commandPlayer.sendRichMessage(Messages.REGISTER.PLAYER_ALREADY_IN_ROUND,
Placeholder.component("player", playerToRegister.name()));
case DISCONNECTED -> { case DISCONNECTED -> {
//should not be possible //should not be possible
} }

View File

@ -83,7 +83,6 @@ public class Messages extends AbstractConfig {
public static String FAILED_TO_REGISTER_YOU = "<red>You were unable to join HungerGames because no HungerGames round was found</red>"; public static String FAILED_TO_REGISTER_YOU = "<red>You were unable to join HungerGames because no HungerGames round was found</red>";
public static String FAILED_TO_REGISTER_PLAYER = "<red>Unable to register player <player></red>"; public static String FAILED_TO_REGISTER_PLAYER = "<red>Unable to register player <player></red>";
public static String PLAYER_REGISTERED = "<green>Registered <player> for the game</green>"; public static String PLAYER_REGISTERED = "<green>Registered <player> for the game</green>";
public static String PLAYER_ALREADY_IN_ROUND = "<yellow><player> is already in a round</yellow>";
public static String PLAYER_SPECTATING = "<yellow><player> is now spectating the game</yellow>"; public static String PLAYER_SPECTATING = "<yellow><player> is now spectating the game</yellow>";
public static String SUCCESSFUL_REGISTER = "<green>Successfully registered you for the upcoming Hunger Games round</green>"; public static String SUCCESSFUL_REGISTER = "<green>Successfully registered you for the upcoming Hunger Games round</green>";
public static String GAME_RUNNING = "<yellow>The game is currently running, you will need to spectate the current round</yellow>"; public static String GAME_RUNNING = "<yellow>The game is currently running, you will need to spectate the current round</yellow>";
@ -93,7 +92,6 @@ public class Messages extends AbstractConfig {
FAILED_TO_REGISTER_YOU = config.getString(prefix, "failed", FAILED_TO_REGISTER_YOU); FAILED_TO_REGISTER_YOU = config.getString(prefix, "failed", FAILED_TO_REGISTER_YOU);
FAILED_TO_REGISTER_PLAYER = config.getString(prefix, "failed-player", FAILED_TO_REGISTER_PLAYER); FAILED_TO_REGISTER_PLAYER = config.getString(prefix, "failed-player", FAILED_TO_REGISTER_PLAYER);
PLAYER_REGISTERED = config.getString(prefix, "player-registered", PLAYER_REGISTERED); PLAYER_REGISTERED = config.getString(prefix, "player-registered", PLAYER_REGISTERED);
PLAYER_ALREADY_IN_ROUND = config.getString(prefix, "player-already-in-game", PLAYER_ALREADY_IN_ROUND);
PLAYER_SPECTATING = config.getString(prefix, "player-spectating", PLAYER_SPECTATING); PLAYER_SPECTATING = config.getString(prefix, "player-spectating", PLAYER_SPECTATING);
SUCCESSFUL_REGISTER = config.getString(prefix, "successful", SUCCESSFUL_REGISTER); SUCCESSFUL_REGISTER = config.getString(prefix, "successful", SUCCESSFUL_REGISTER);
GAME_RUNNING = config.getString(prefix, "game-running", GAME_RUNNING); GAME_RUNNING = config.getString(prefix, "game-running", GAME_RUNNING);

View File

@ -2,7 +2,6 @@ package com.alttd.hunger_games.data_objects;
public enum PLAYER_STATE { public enum PLAYER_STATE {
REGISTERED, REGISTERED,
IN_GAME,
DISCONNECTED, DISCONNECTED,
SPECTATING SPECTATING
} }

View File

@ -1,6 +1,7 @@
package com.alttd.hunger_games.services; package com.alttd.hunger_games.services;
import com.alttd.hunger_games.config.Messages; import com.alttd.hunger_games.config.Messages;
import com.alttd.hunger_games.data_objects.DESTINATION;
import com.alttd.hunger_games.data_objects.PLAYER_STATE; import com.alttd.hunger_games.data_objects.PLAYER_STATE;
import com.alttd.hunger_games.data_objects.ROUND_STATE; import com.alttd.hunger_games.data_objects.ROUND_STATE;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -12,9 +13,20 @@ import java.util.*;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PlayerService implements RoundListener { public class PlayerService implements RoundListener {
private static PlayerService instance = null;
private final RoundService roundService; private final RoundService roundService;
private final PlayerTeleporterService playerTeleporterService;
private ROUND_STATE roundState; private ROUND_STATE roundState;
public static PlayerService createSingletonInstance(RoundService roundService, PlayerTeleporterService playerTeleporterService) {
if (instance != null) {
throw new IllegalStateException("PlayerService is already initialized.");
}
instance = new PlayerService(roundService, playerTeleporterService);
return instance;
}
@Override @Override
public void stateChange(ROUND_STATE roundState) { public void stateChange(ROUND_STATE roundState) {
this.roundState = roundState; this.roundState = roundState;
@ -24,14 +36,20 @@ public class PlayerService implements RoundListener {
} }
case COUNTDOWN -> { case COUNTDOWN -> {
setNonRegisteredPlayersToSpectator(); setNonRegisteredPlayersToSpectator();
//TODO: teleport players to spawn location Set<UUID> players = roundService.getPlayers(PLAYER_STATE.REGISTERED);
Bukkit.getOnlinePlayers().stream()
.filter(player -> players.contains(player.getUniqueId()))
.forEach(player -> playerTeleporterService.teleportPlayer(player, DESTINATION.START_AREA));
} }
case FINALE -> { case FINALE -> {
//TODO: teleport players to finale location Set<UUID> players = roundService.getPlayers(PLAYER_STATE.REGISTERED);
Bukkit.getOnlinePlayers().stream()
.filter(player -> players.contains(player.getUniqueId()))
.forEach(player -> playerTeleporterService.teleportPlayer(player, DESTINATION.FINALE_AREA));
} }
case ENDED -> { case ENDED -> {
roundService.clear(); roundService.clear();
//TODO: teleport everyone to spawn (or spectator?) location Bukkit.getOnlinePlayers().forEach(player -> playerTeleporterService.teleportPlayer(player, DESTINATION.START_AREA));
} }
} }
} }
@ -88,7 +106,6 @@ public class PlayerService implements RoundListener {
PLAYER_STATE playerState = optionalPlayerState.get(); PLAYER_STATE playerState = optionalPlayerState.get();
return Optional.of(switch (playerState) { return Optional.of(switch (playerState) {
case DISCONNECTED, SPECTATING -> PLAYER_STATE.SPECTATING; case DISCONNECTED, SPECTATING -> PLAYER_STATE.SPECTATING;
case IN_GAME -> PLAYER_STATE.IN_GAME;
case REGISTERED -> PLAYER_STATE.REGISTERED; case REGISTERED -> PLAYER_STATE.REGISTERED;
}); });
} }