Refactor PlayerService to include Round dependency and update singleton initialization logic

This commit is contained in:
akastijn 2026-05-30 19:56:50 +02:00
parent 9db0e70425
commit c969873e0a
2 changed files with 9 additions and 5 deletions

View File

@ -36,7 +36,7 @@ public final class Main extends JavaPlugin {
round = Round.createSingletonInstance();
roundService = RoundService.createSingletonInstance(round);
playerTeleporterService = PlayerTeleporterService.createSingletonInstance();
playerService = PlayerService.createSingletonInstance(roundService, playerTeleporterService);
playerService = PlayerService.createSingletonInstance(round, roundService, playerTeleporterService);
}
@Override

View File

@ -4,13 +4,11 @@ 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;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
@RequiredArgsConstructor
public class PlayerService implements RoundListener {
private static PlayerService instance = null;
@ -19,11 +17,17 @@ public class PlayerService implements RoundListener {
private final PlayerTeleporterService playerTeleporterService;
private ROUND_STATE roundState;
public static PlayerService createSingletonInstance(RoundService roundService, PlayerTeleporterService playerTeleporterService) {
public PlayerService(Round round, RoundService roundService, PlayerTeleporterService playerTeleporterService) {
this.roundService = roundService;
this.playerTeleporterService = playerTeleporterService;
this.roundState = round.register(this);
}
public static PlayerService createSingletonInstance(Round round, RoundService roundService, PlayerTeleporterService playerTeleporterService) {
if (instance != null) {
throw new IllegalStateException("PlayerService is already initialized.");
}
instance = new PlayerService(roundService, playerTeleporterService);
instance = new PlayerService(round, roundService, playerTeleporterService);
return instance;
}