fix: stop game immediately when timer expires (show results, teleport to lobby)
This commit is contained in:
parent
8b1bcf0433
commit
b0afb3f6be
1 changed files with 26 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ import dev.loki.ui.ActionBar;
|
|||
import dev.loki.ui.TitleUI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
|
|
@ -120,9 +121,18 @@ public class GameplayPhase implements Phase {
|
|||
if (tickCounter % 20 == 0) {
|
||||
checkGeneratorProgress(session);
|
||||
winConditions.checkWinConditions(session);
|
||||
if (winConditions.isShouldEnd() || timeExpired) shouldEnd = true;
|
||||
if (winConditions.isShouldEnd() || timeExpired) {
|
||||
shouldEnd = true;
|
||||
}
|
||||
ui.updateSidebar(session, generatorManager);
|
||||
}
|
||||
|
||||
if (timeExpired) {
|
||||
showGameResults(session);
|
||||
teleportAllToLobby(session);
|
||||
session.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -351,6 +361,21 @@ public class GameplayPhase implements Phase {
|
|||
}
|
||||
}
|
||||
|
||||
private void teleportAllToLobby(GameSession session) {
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) {
|
||||
p.setGameMode(org.bukkit.GameMode.ADVENTURE);
|
||||
p.getInventory().clear();
|
||||
p.setWalkSpeed(0.2f);
|
||||
p.setFlySpeed(0.1f);
|
||||
p.setHealth(20.0);
|
||||
p.setFoodLevel(20);
|
||||
session.getPlugin().getLobbyManager().teleportToLobby(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearListeners() {
|
||||
if (interaction != null) interaction.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue