Compare commits

..

No commits in common. "29c46ba48521793be645118fb79610d8dcb959ca" and "4bf6ca9dc49f4db95fc18238be1feb56d22b5714" have entirely different histories.

5 changed files with 10 additions and 28 deletions

View File

@ -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.getHumanReadableName()));
roundState == null ? "null" : roundState.getHumandReadableName()));
return true;
}

View File

@ -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.getHumanReadableName()));
Placeholder.parsed("round_state", roundState.getHumandReadableName()));
}
return true;
}

View File

@ -17,7 +17,7 @@ public enum ROUND_STATE {
return Optional.of(values()[ordinal() + 1]);
}
public String getHumanReadableName() {
public String getHumandReadableName() {
return switch (this) {
case PLAYER_REGISTRATION -> "Player Registration";
case COUNTDOWN -> "Countdown";

View File

@ -42,10 +42,7 @@ 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());

View File

@ -2,17 +2,14 @@ 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;
@ -24,7 +21,6 @@ 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;
@ -34,24 +30,22 @@ 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, PlayerTeleporterService playerTeleporterService) {
public static RoundService createSingletonInstance(Round round, Main main, LootService lootService, StatService statService) {
if (instance != null) {
throw new IllegalStateException("RoundService is already initialized.");
}
instance = new RoundService(round, main, lootService, statService, playerTeleporterService);
instance = new RoundService(round, main, lootService, statService);
return instance;
}
private RoundService(Round round, Main main, LootService lootService, StatService statService, PlayerTeleporterService playerTeleporterService) {
private RoundService(Round round, Main main, LootService lootService, StatService statService) {
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) {
@ -93,10 +87,6 @@ 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();
}
@ -117,17 +107,9 @@ 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("round", roundState.getHumanReadableName())));
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.GAME.NEXT_STATE, Placeholder.parsed("state", roundState.getHumandReadableName())));
}
private void stopFreeze() {
@ -145,4 +127,7 @@ public class RoundService implements RoundListener {
main.getServer().getPluginManager().registerEvents(playerMovementListener, main);
}
public void setBossBarService(BossBarService bossBarService) {
this.bossBarService = bossBarService;
}
}