Remove IN_GAME player state and related logic; integrate destination-based teleportation during round progression.
This commit is contained in:
parent
0cf662dfef
commit
d3946bc16a
3
TODO.md
3
TODO.md
|
|
@ -101,8 +101,7 @@ A Minecraft survival/PvP plugin with configurable loot, shrinking world border,
|
|||
|
||||
### Player States
|
||||
Track each registered player in one of these states:
|
||||
- [ ] `REGISTERED` — signed up, round not yet started
|
||||
- [ ] `IN_GAME` — actively in the round
|
||||
- [ ] `REGISTERED` — signed up or in game (depending on round state)
|
||||
- [ ] `DISCONNECTED` — left the server mid-round
|
||||
- [ ] `SPECTATING` — non-participant/dead observer
|
||||
|
||||
|
|
|
|||
|
|
@ -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.PlayerJoinListener;
|
||||
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.RoundService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -17,6 +18,7 @@ public final class Main extends JavaPlugin {
|
|||
|
||||
private RoundService roundService;
|
||||
private PlayerService playerService;
|
||||
private PlayerTeleporterService playerTeleporterService;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
@ -31,7 +33,8 @@ public final class Main extends JavaPlugin {
|
|||
private void registerServices() {
|
||||
Round round = Round.createSingletonInstance();
|
||||
roundService = RoundService.createSingletonInstance(round);
|
||||
playerService = new PlayerService(roundService);
|
||||
playerTeleporterService = PlayerTeleporterService.createSingletonInstance();
|
||||
playerService = PlayerService.createSingletonInstance(roundService, playerTeleporterService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ public class Register extends SubCommand {
|
|||
|
||||
switch (nullablePlayerState) {
|
||||
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 SPECTATING -> log.info("Player {} is now spectating the game", playerToRegister.getName());
|
||||
}
|
||||
|
|
@ -83,8 +82,6 @@ public class Register extends SubCommand {
|
|||
switch (playerState) {
|
||||
case REGISTERED -> commandPlayer.sendRichMessage(Messages.REGISTER.PLAYER_REGISTERED,
|
||||
Placeholder.component("player", playerToRegister.name()));
|
||||
case IN_GAME -> commandPlayer.sendRichMessage(Messages.REGISTER.PLAYER_ALREADY_IN_ROUND,
|
||||
Placeholder.component("player", playerToRegister.name()));
|
||||
case DISCONNECTED -> {
|
||||
//should not be possible
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_PLAYER = "<red>Unable to register player <player></red>";
|
||||
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 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>";
|
||||
|
|
@ -93,7 +92,6 @@ public class Messages extends AbstractConfig {
|
|||
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);
|
||||
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);
|
||||
SUCCESSFUL_REGISTER = config.getString(prefix, "successful", SUCCESSFUL_REGISTER);
|
||||
GAME_RUNNING = config.getString(prefix, "game-running", GAME_RUNNING);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.alttd.hunger_games.data_objects;
|
|||
|
||||
public enum PLAYER_STATE {
|
||||
REGISTERED,
|
||||
IN_GAME,
|
||||
DISCONNECTED,
|
||||
SPECTATING
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.hunger_games.services;
|
||||
|
||||
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.ROUND_STATE;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -12,9 +13,20 @@ import java.util.*;
|
|||
@RequiredArgsConstructor
|
||||
public class PlayerService implements RoundListener {
|
||||
|
||||
private static PlayerService instance = null;
|
||||
|
||||
private final RoundService roundService;
|
||||
private final PlayerTeleporterService playerTeleporterService;
|
||||
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
|
||||
public void stateChange(ROUND_STATE roundState) {
|
||||
this.roundState = roundState;
|
||||
|
|
@ -24,14 +36,20 @@ public class PlayerService implements RoundListener {
|
|||
}
|
||||
case COUNTDOWN -> {
|
||||
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 -> {
|
||||
//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 -> {
|
||||
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();
|
||||
return Optional.of(switch (playerState) {
|
||||
case DISCONNECTED, SPECTATING -> PLAYER_STATE.SPECTATING;
|
||||
case IN_GAME -> PLAYER_STATE.IN_GAME;
|
||||
case REGISTERED -> PLAYER_STATE.REGISTERED;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user