Refactor respawn handling: streamline spectator teleportation, reset player experience, adjust finale border size, and improve game stage countdown logic.
This commit is contained in:
parent
99bff5446d
commit
1a9f4cbd2d
|
|
@ -57,6 +57,6 @@ public class PlayerDamageListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
playerService.handlePlayerRespawn(event.getPlayer());
|
||||
playerService.handlePlayerRespawn(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -36,6 +38,7 @@ public class PlayerService implements RoundListener {
|
|||
@Override
|
||||
public void stateChange(ROUND_STATE roundState) {
|
||||
this.roundState = roundState;
|
||||
playerTeleporterService.reset();
|
||||
switch (roundState) {
|
||||
case PLAYER_REGISTRATION, KILL_PHASE, SAFE_PHASE -> {
|
||||
//Nothing
|
||||
|
|
@ -113,10 +116,9 @@ public class PlayerService implements RoundListener {
|
|||
Placeholder.unparsed("remaining", String.valueOf(remaining))));
|
||||
}
|
||||
|
||||
public void handlePlayerRespawn(Player player) {
|
||||
roundService.getPlayerState(player.getUniqueId())
|
||||
.filter(state -> state == PLAYER_STATE.SPECTATING)
|
||||
.ifPresent(state -> playerTeleporterService.teleportPlayer(player, DESTINATION.SPECTATOR_AREA));
|
||||
public void handlePlayerRespawn(PlayerRespawnEvent event) {
|
||||
Location spectatorArea = playerTeleporterService.getLocationFromDestination(DESTINATION.SPECTATOR_AREA);
|
||||
event.setRespawnLocation(spectatorArea);
|
||||
}
|
||||
|
||||
private Optional<PLAYER_STATE> determinePlayerState(UUID playerUuid) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,12 @@ public class PlayerTeleporterService implements RoundListener {
|
|||
player.teleport(getLocationFromDestination(destination));
|
||||
}
|
||||
|
||||
private Location getLocationFromDestination(DESTINATION destination) {
|
||||
public void reset() {
|
||||
placementCount.clear();
|
||||
usedLocations.clear();
|
||||
}
|
||||
|
||||
public Location getLocationFromDestination(DESTINATION destination) {
|
||||
return switch (destination) {
|
||||
case START_AREA -> {
|
||||
Location startCenter = Config.DESTINATION.START_CENTER;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.hunger_games.services;
|
|||
|
||||
import com.alttd.hunger_games.config.Config;
|
||||
import com.alttd.hunger_games.data_objects.GameStage;
|
||||
import com.alttd.hunger_games.data_objects.PLAYER_STATE;
|
||||
import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
||||
import com.alttd.hunger_games.game.GameStageHandler;
|
||||
import lombok.Setter;
|
||||
|
|
@ -99,6 +100,13 @@ public class Round {
|
|||
|
||||
final Instant endTime = Instant.now().plus(duration);
|
||||
countdownFuture = scheduledExecutorService.scheduleAtFixedRate(() -> {
|
||||
if (roundState.equals(ROUND_STATE.FINALE)) {
|
||||
if (countdownFuture != null) {
|
||||
countdownFuture.cancel(false);
|
||||
countdownFuture = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Duration timeLeft = Duration.between(Instant.now(), endTime);
|
||||
if (bossBarService != null) {
|
||||
bossBarService.updateCountdown(timeLeft, duration, roundState);
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ public class RoundService implements RoundListener {
|
|||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.getInventory().clear();
|
||||
player.sendExperienceChange(-player.getExp(), -player.getLevel());
|
||||
player.setExp(0);
|
||||
player.setTotalExperience(0);
|
||||
player.setExp(0.0f);
|
||||
player.setLevel(0);
|
||||
round.endRound();
|
||||
}
|
||||
|
|
@ -129,12 +129,15 @@ public class RoundService implements RoundListener {
|
|||
player.setFoodLevel(20);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
player.setTotalExperience(0);
|
||||
player.setExp(0.0f);
|
||||
player.setLevel(0);
|
||||
});
|
||||
startFreeze();
|
||||
WorldBorderUtil.resetBorder();
|
||||
}
|
||||
if (roundState.equals(ROUND_STATE.FINALE)) {
|
||||
WorldBorderUtil.setSize(100);
|
||||
WorldBorderUtil.setSize(75);
|
||||
}
|
||||
if (!roundState.equals(ROUND_STATE.ENDED)) {
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.GAME.NEXT_STATE, Placeholder.parsed("round", roundState.getHumanReadableName())));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user