Compare commits
2 Commits
4bf6ca9dc4
...
29c46ba485
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29c46ba485 | ||
|
|
ca7b6f1152 |
|
|
@ -20,7 +20,7 @@ public class RoundState extends SubCommand {
|
|||
ROUND_STATE roundState = roundService.getRoundState();
|
||||
commandSender.sendRichMessage(Messages.ROUND_STATE.ROUND_STATE,
|
||||
Placeholder.parsed("round_state",
|
||||
roundState == null ? "null" : roundState.getHumandReadableName()));
|
||||
roundState == null ? "null" : roundState.getHumanReadableName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class StartRound extends SubCommand {
|
|||
round.startRound();
|
||||
} else {
|
||||
commandSender.sendRichMessage(Messages.START_ROUND.CAN_NOT_START_ROUND,
|
||||
Placeholder.parsed("round_state", roundState.getHumandReadableName()));
|
||||
Placeholder.parsed("round_state", roundState.getHumanReadableName()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public enum ROUND_STATE {
|
|||
return Optional.of(values()[ordinal() + 1]);
|
||||
}
|
||||
|
||||
public String getHumandReadableName() {
|
||||
public String getHumanReadableName() {
|
||||
return switch (this) {
|
||||
case PLAYER_REGISTRATION -> "Player Registration";
|
||||
case COUNTDOWN -> "Countdown";
|
||||
|
|
|
|||
|
|
@ -42,7 +42,10 @@ public class PlayerDamageListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
event.setShowDeathMessages(false);
|
||||
event.deathMessage(null);
|
||||
event.getDrops().clear();
|
||||
player.getInventory().clear();
|
||||
playerService.handlePlayerDeath(player);
|
||||
statService.addDeath(player.getUniqueId());
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@ package com.alttd.hunger_games.services;
|
|||
|
||||
import com.alttd.hunger_games.Main;
|
||||
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 com.alttd.hunger_games.event_listeners.PlayerMovementListener;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
|
@ -21,6 +24,7 @@ public class RoundService implements RoundListener {
|
|||
|
||||
private static RoundService instance = null;
|
||||
private PlayerMovementListener playerMovementListener;
|
||||
private final PlayerTeleporterService playerTeleporterService;
|
||||
private final Main main;
|
||||
private final LootService lootService;
|
||||
private final StatService statService;
|
||||
|
|
@ -30,22 +34,24 @@ public class RoundService implements RoundListener {
|
|||
private final HashMap<UUID, PLAYER_STATE> players = new HashMap<>();
|
||||
|
||||
private final Round round;
|
||||
@Setter
|
||||
private BossBarService bossBarService;
|
||||
|
||||
public static RoundService createSingletonInstance(Round round, Main main, LootService lootService, StatService statService) {
|
||||
public static RoundService createSingletonInstance(Round round, Main main, LootService lootService, StatService statService, PlayerTeleporterService playerTeleporterService) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("RoundService is already initialized.");
|
||||
}
|
||||
instance = new RoundService(round, main, lootService, statService);
|
||||
instance = new RoundService(round, main, lootService, statService, playerTeleporterService);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private RoundService(Round round, Main main, LootService lootService, StatService statService) {
|
||||
private RoundService(Round round, Main main, LootService lootService, StatService statService, PlayerTeleporterService playerTeleporterService) {
|
||||
this.round = round;
|
||||
this.roundState = round.register(this);
|
||||
this.main = main;
|
||||
this.lootService = lootService;
|
||||
this.statService = statService;
|
||||
this.playerTeleporterService = playerTeleporterService;
|
||||
}
|
||||
|
||||
public Set<UUID> getPlayers(PLAYER_STATE playerState) {
|
||||
|
|
@ -87,6 +93,10 @@ public class RoundService implements RoundListener {
|
|||
statService.setWon(winnerUUID, true);
|
||||
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.GAME.WINNER, Placeholder.component("player", player.name())));
|
||||
playerTeleporterService.teleportPlayer(player, DESTINATION.SPECTATOR_AREA);
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.getInventory().clear();
|
||||
round.endRound();
|
||||
}
|
||||
|
||||
|
|
@ -107,9 +117,17 @@ public class RoundService implements RoundListener {
|
|||
lootService.clear();
|
||||
}
|
||||
if (roundState.equals(ROUND_STATE.COUNTDOWN)) {
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> PLAYER_STATE.REGISTERED.equals(getPlayerState(player.getUniqueId()).orElse(null)))
|
||||
.forEach(player -> {
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
});
|
||||
startFreeze();
|
||||
}
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.GAME.NEXT_STATE, Placeholder.parsed("state", roundState.getHumandReadableName())));
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.GAME.NEXT_STATE, Placeholder.parsed("round", roundState.getHumanReadableName())));
|
||||
}
|
||||
|
||||
private void stopFreeze() {
|
||||
|
|
@ -127,7 +145,4 @@ public class RoundService implements RoundListener {
|
|||
main.getServer().getPluginManager().registerEvents(playerMovementListener, main);
|
||||
}
|
||||
|
||||
public void setBossBarService(BossBarService bossBarService) {
|
||||
this.bossBarService = bossBarService;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user