Add player join and disconnect event handling with state updates
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.alttd.hunger_games.services;
|
||||
|
||||
import com.alttd.hunger_games.config.Messages;
|
||||
import com.alttd.hunger_games.data_objects.PLAYER_STATE;
|
||||
import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -60,6 +61,24 @@ public class PlayerService implements RoundListener {
|
||||
return optionalPlayerState;
|
||||
}
|
||||
|
||||
public void handleDisconnect(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
roundService.setPlayerState(uuid, PLAYER_STATE.DISCONNECTED);
|
||||
}
|
||||
|
||||
public void handleJoin(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
Optional<PLAYER_STATE> state = roundService.getPlayerState(uuid);
|
||||
if (state.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (state.get() != PLAYER_STATE.DISCONNECTED) {
|
||||
return;
|
||||
}
|
||||
roundService.setPlayerState(uuid, PLAYER_STATE.SPECTATING);
|
||||
player.sendRichMessage(Messages.RECONNECT.FORFEITED);
|
||||
}
|
||||
|
||||
private Optional<PLAYER_STATE> determinePlayerState(UUID playerUuid) {
|
||||
if (roundState == null) {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.alttd.hunger_games.services;
|
||||
import com.alttd.hunger_games.data_objects.PLAYER_STATE;
|
||||
import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
Reference in New Issue
Block a user