Compare commits

..

No commits in common. "56455b4c50e24cda69b4389b90efb93075480e69" and "237cae37ca3838a8483a1787f7fb5b6e0a6192bb" have entirely different histories.

4 changed files with 17 additions and 33 deletions

View File

@ -8,7 +8,6 @@ import com.alttd.ctf.team.TeamColor;
import com.alttd.ctf.team.TeamPlayer; import com.alttd.ctf.team.TeamPlayer;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
@ -82,8 +81,8 @@ public class Flag implements Runnable {
//TODO add de-buffs and enable buffs for others? //TODO add de-buffs and enable buffs for others?
player.getInventory().setItem(EquipmentSlot.HEAD, flagItem); player.getInventory().setItem(EquipmentSlot.HEAD, flagItem);
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(Material.AIR)); Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(Material.AIR));
flagCarrier = player;
notifyAboutCapture(); notifyAboutCapture();
flagCarrier = player;
resetFlag(); resetFlag();
} }
@ -225,10 +224,10 @@ public class Flag implements Runnable {
Bukkit.broadcast(miniMessage.deserialize("<player> captured the flag for <team>!", Bukkit.broadcast(miniMessage.deserialize("<player> captured the flag for <team>!",
Placeholder.component("player", flagCarrier.displayName()), Placeholder.component("player", flagCarrier.displayName()),
Placeholder.component("team", winningTeam.getName()))); Placeholder.component("team", winningTeam.getName())));
Title title = Title.title(Component.empty(), Title title = Title.title(miniMessage.deserialize("<green><player> captured the flag for team <team>!</green>",
miniMessage.deserialize("<green><player> captured the flag for <team> team</green>", Placeholder.component("team", winningTeam.getName())),
Placeholder.component("player", flagCarrier.displayName()), miniMessage.deserialize("<green>protect <player> while they bring it to your base.</green>",
Placeholder.component("team", winningTeam.getName()))); Placeholder.component("player", flagCarrier.displayName())));
Bukkit.getOnlinePlayers().forEach(player -> player.showTitle(title)); Bukkit.getOnlinePlayers().forEach(player -> player.showTitle(title));
} }

View File

@ -13,7 +13,6 @@ import javax.annotation.Nullable;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@Slf4j @Slf4j
@ -40,6 +39,7 @@ public class RunningGame implements Runnable {
try { try {
GamePhase nextPhase = (currentPhase.ordinal() + 1 < GamePhase.values().length) ? GamePhase.values()[currentPhase.ordinal() + 1] : null; GamePhase nextPhase = (currentPhase.ordinal() + 1 < GamePhase.values().length) ? GamePhase.values()[currentPhase.ordinal() + 1] : null;
if (phaseStartTime == null) { if (phaseStartTime == null) {
phaseStartTime = Instant.now();
nextPhaseActions(null, currentPhase); nextPhaseActions(null, currentPhase);
} }
@ -58,19 +58,15 @@ public class RunningGame implements Runnable {
} }
private void nextPhaseActions(@Nullable GamePhase previousPhase, @NotNull GamePhase phase) { private void nextPhaseActions(@Nullable GamePhase previousPhase, @NotNull GamePhase phase) {
//TODO command to go to next phase
this.currentPhase = phase; this.currentPhase = phase;
this.phaseStartTime = Instant.now();
if (previousPhase != null) { if (previousPhase != null) {
gameManager.getPhaseExecutor(previousPhase).end(phase); gameManager.getPhaseExecutor(previousPhase).end(phase);
} }
gameManager.getPhaseExecutor(phase).start(flag); gameManager.getPhaseExecutor(phase).start(flag);
if (phase.equals(GamePhase.ENDED)) {
executorService.shutdown();
}
} }
private static final List<Integer> NOTIFY_SECONDS = List.of(45, 30, 15, 10, 5, 3, 2, 1); private void broadcastNextPhaseStartTime(GamePhase currentPhase, GamePhase nextPhase) {//TODO check how this works/what it should do
private void broadcastNextPhaseStartTime(GamePhase currentPhase, GamePhase nextPhase) {
//Remaining time for this phase //Remaining time for this phase
Duration duration = phaseDurations.get(currentPhase).minus(Duration.between(phaseStartTime, Instant.now())); Duration duration = phaseDurations.get(currentPhase).minus(Duration.between(phaseStartTime, Instant.now()));
log.debug(duration.toString());//TODO remove debug log.debug(duration.toString());//TODO remove debug
@ -79,21 +75,11 @@ public class RunningGame implements Runnable {
return; return;
} }
lastMinuteBroadcast = (int) duration.toMinutes(); lastMinuteBroadcast = (int) duration.toMinutes();
if (nextPhase.equals(GamePhase.ENDED)) {
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
"<green>The game will end in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>"));
return;
}
Bukkit.broadcast(MiniMessage.miniMessage().deserialize( Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
"<green>The <phase> will start in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>", "<green>The <phase> will start in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>",
Placeholder.component("phase", nextPhase.getDisplayName()) Placeholder.component("phase", nextPhase.getDisplayName())
)); ));
} else if (duration.toMinutes() < 1 && NOTIFY_SECONDS.contains(duration.toSecondsPart())) { } else if (duration.toMinutes() < 1 && duration.toSeconds() % 15 == 0) {
if (nextPhase.equals(GamePhase.ENDED)) {
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
"<green>The game will end in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>"));
return;
}
Bukkit.broadcast(MiniMessage.miniMessage().deserialize( Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
"<green>The <phase> will start in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>", "<green>The <phase> will start in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>",
Placeholder.component("phase", nextPhase.getDisplayName()) Placeholder.component("phase", nextPhase.getDisplayName())

View File

@ -15,18 +15,17 @@ public class CombatPhase implements GamePhaseExecutor {
private ScheduledExecutorService executorService = null; private ScheduledExecutorService executorService = null;
@Override @Override
public synchronized void start(Flag flag) { public void start(Flag flag) {
Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>")); Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>"));
flag.spawnFlag(); flag.spawnFlag();
if (executorService == null) { if (executorService == null || !executorService.isShutdown()) {
executorService = Executors.newSingleThreadScheduledExecutor(); if (executorService != null) {
} else if (executorService.isTerminated() || executorService.isShutdown()) { executorService.shutdown();
executorService = Executors.newSingleThreadScheduledExecutor(); }
} else {
executorService.shutdown();
executorService = Executors.newSingleThreadScheduledExecutor(); executorService = Executors.newSingleThreadScheduledExecutor();
} }
executorService.scheduleAtFixedRate(flag, 0, 1, TimeUnit.SECONDS); executorService.scheduleAtFixedRate(flag, 0, 1, TimeUnit.SECONDS);
// TODO Add players to bossbar list for capture progress(or maybe only when any progress is made)
} }
@Override @Override

View File

@ -1,3 +1,3 @@
#Tue Feb 11 22:21:13 CET 2025 #Tue Feb 11 22:04:16 CET 2025
buildNumber=45 buildNumber=42
version=0.1 version=0.1