fix: colors, /dbd join flow, world creation, role assign, action bar lobby, /dbdadmin world, tab complete
This commit is contained in:
parent
327ad9b906
commit
1adb8c84fd
19 changed files with 874 additions and 112 deletions
|
|
@ -1,10 +1,11 @@
|
|||
package dev.loki.phase;
|
||||
|
||||
import dev.loki.core.GameSession;
|
||||
import dev.loki.objective.Generator;
|
||||
import dev.loki.objective.GeneratorManager;
|
||||
import dev.loki.player.BasePlayer;
|
||||
import dev.loki.player.PlayerState;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -24,14 +25,14 @@ public class GameplayPhase implements Phase {
|
|||
|
||||
@Override
|
||||
public void enter(GameSession session) {
|
||||
Bukkit.broadcastMessage("[DBD] Игра началась! Выжившие, чините генераторы!");
|
||||
Bukkit.broadcast(Component.text("[DBD] Игра началась! Выжившие, чините генераторы!", NamedTextColor.GREEN));
|
||||
tickCounter = 0;
|
||||
// Teleport is handled by RoleAssigner.assignRoles — no double-teleport needed here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(GameSession session) {
|
||||
tickCounter++;
|
||||
|
||||
generatorManager.tick();
|
||||
|
||||
if (tickCounter % 20 == 0) {
|
||||
|
|
@ -45,7 +46,8 @@ public class GameplayPhase implements Phase {
|
|||
|
||||
if (generatorManager.areAllRequiredCompleted()) {
|
||||
allGensDone = true;
|
||||
Bukkit.broadcastMessage("[DBD] §a§lВсе генераторы починены! Открывайте ворота!");
|
||||
Bukkit.broadcast(Component.text(
|
||||
"[DBD] Все генераторы починены! Открывайте ворота!", NamedTextColor.GREEN));
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null) {
|
||||
|
|
@ -58,13 +60,11 @@ public class GameplayPhase implements Phase {
|
|||
private void checkWinConditions(GameSession session) {
|
||||
int aliveSurvivors = 0;
|
||||
int escapedSurvivors = 0;
|
||||
boolean killerDead = true;
|
||||
int totalSurvivors = 0;
|
||||
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
if (bp.isKiller()) {
|
||||
killerDead = false;
|
||||
continue;
|
||||
}
|
||||
if (bp.isKiller()) continue;
|
||||
totalSurvivors++;
|
||||
PlayerState state = bp.getState();
|
||||
if (state == PlayerState.ESCAPED) {
|
||||
escapedSurvivors++;
|
||||
|
|
@ -73,16 +73,17 @@ public class GameplayPhase implements Phase {
|
|||
}
|
||||
}
|
||||
|
||||
boolean allSurvivorsDead = (aliveSurvivors == 0 && escapedSurvivors == 0);
|
||||
boolean allSurvivorsDead = (aliveSurvivors == 0 && escapedSurvivors == 0 && totalSurvivors > 0);
|
||||
boolean allEscaped = (escapedSurvivors == totalSurvivors && totalSurvivors > 0);
|
||||
|
||||
if (allSurvivorsDead || escapedSurvivors == session.getPlayerCount() - 1) {
|
||||
if (allSurvivorsDead || allEscaped) {
|
||||
shouldEnd = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(GameSession session) {
|
||||
Bukkit.broadcastMessage("[DBD] §6Игровая фаза завершена!");
|
||||
Bukkit.broadcast(Component.text("[DBD] Игровая фаза завершена!", NamedTextColor.GOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package dev.loki.phase;
|
|||
|
||||
import dev.loki.config.GameConfig;
|
||||
import dev.loki.core.GameSession;
|
||||
import dev.loki.player.BasePlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LobbyPhase implements Phase {
|
||||
private final GameConfig config;
|
||||
|
|
@ -22,6 +24,14 @@ public class LobbyPhase implements Phase {
|
|||
@Override
|
||||
public void enter(GameSession session) {
|
||||
Bukkit.broadcast(Component.text("[DBD] Лобби открыто! Используйте /dbd join", NamedTextColor.GREEN));
|
||||
// Teleport already-in-session players to lobby (e.g. on restart)
|
||||
var lobbyManager = session.getPlugin().getLobbyManager();
|
||||
for (var player : session.getPlayers().values()) {
|
||||
var bukkitPlayer = player.getPlayer();
|
||||
if (bukkitPlayer != null && bukkitPlayer.isOnline()) {
|
||||
lobbyManager.teleportToLobby(bukkitPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -33,6 +43,9 @@ public class LobbyPhase implements Phase {
|
|||
secondsLeft = config.getLobbyCountdown();
|
||||
countdown = 0;
|
||||
started = false;
|
||||
// Show waiting message in action bar to all players in lobby
|
||||
sendActionBarToAll(session,
|
||||
Component.text("⏳ Ожидание игроков: " + playerCount + "/" + minPlayers, NamedTextColor.YELLOW));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -40,12 +53,18 @@ public class LobbyPhase implements Phase {
|
|||
if (countdown >= 20) {
|
||||
countdown = 0;
|
||||
secondsLeft--;
|
||||
}
|
||||
|
||||
if (secondsLeft <= 5 || secondsLeft % 10 == 0) {
|
||||
Bukkit.broadcast(Component.text(
|
||||
"[DBD] До начала: " + secondsLeft + " сек. (" + playerCount + "/" + minPlayers + ")",
|
||||
NamedTextColor.YELLOW));
|
||||
}
|
||||
// Action bar: показываем каждый тик (обновляется плавно)
|
||||
String bar = buildCountdownBar(secondsLeft, config.getLobbyCountdown());
|
||||
sendActionBarToAll(session,
|
||||
Component.text("▶ Старт через: " + secondsLeft + "с " + bar +
|
||||
" (" + playerCount + "/" + minPlayers + ")", NamedTextColor.GREEN));
|
||||
|
||||
// Chat-announce на ключевых отметках
|
||||
if (countdown == 0 && (secondsLeft <= 5 || secondsLeft == 10 || secondsLeft == 30)) {
|
||||
Bukkit.broadcast(Component.text(
|
||||
"[DBD] До начала: " + secondsLeft + " сек.", NamedTextColor.YELLOW));
|
||||
}
|
||||
|
||||
if (secondsLeft <= 0) {
|
||||
|
|
@ -53,11 +72,41 @@ public class LobbyPhase implements Phase {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendActionBarToAll(GameSession session, Component msg) {
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) {
|
||||
p.sendActionBar(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String buildCountdownBar(int current, int total) {
|
||||
int filled = total > 0 ? (int) (10.0 * current / total) : 0;
|
||||
int empty = 10 - filled;
|
||||
return "§a" + "█".repeat(Math.max(0, filled)) + "§7" + "░".repeat(Math.max(0, empty));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(GameSession session) {
|
||||
// Clear action bar for all
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) p.sendActionBar(Component.empty());
|
||||
}
|
||||
Bukkit.broadcast(Component.text("[DBD] Игра начинается!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoined(GameSession session, Player player) {
|
||||
session.getPlugin().getLobbyManager().teleportToLobby(player);
|
||||
int playerCount = session.getPlayerCount();
|
||||
int minPlayers = config.getMinPlayers();
|
||||
Bukkit.broadcast(Component.text(
|
||||
"[DBD] " + player.getName() + " присоединился к очереди! (" + playerCount + "/" + minPlayers + ")",
|
||||
NamedTextColor.YELLOW));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return started;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package dev.loki.phase;
|
||||
|
||||
import dev.loki.core.GameSession;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Phase {
|
||||
void enter(GameSession session);
|
||||
void tick(GameSession session);
|
||||
void exit(GameSession session);
|
||||
boolean isComplete();
|
||||
default void onPlayerJoined(GameSession session, Player player) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package dev.loki.phase;
|
|||
|
||||
import dev.loki.core.GameSession;
|
||||
import dev.loki.role.RoleAssigner;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class RoleAssignPhase implements Phase {
|
||||
|
|
@ -30,7 +32,7 @@ public class RoleAssignPhase implements Phase {
|
|||
|
||||
@Override
|
||||
public void exit(GameSession session) {
|
||||
Bukkit.broadcastMessage("[DBD] Роли назначены!");
|
||||
Bukkit.broadcast(Component.text("[DBD] Роли назначены!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue