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

View File

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

View File

@ -15,18 +15,17 @@ public class CombatPhase implements GamePhaseExecutor {
private ScheduledExecutorService executorService = null;
@Override
public synchronized void start(Flag flag) {
public void start(Flag flag) {
Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>"));
flag.spawnFlag();
if (executorService == null) {
executorService = Executors.newSingleThreadScheduledExecutor();
} else if (executorService.isTerminated() || executorService.isShutdown()) {
executorService = Executors.newSingleThreadScheduledExecutor();
} else {
if (executorService == null || !executorService.isShutdown()) {
if (executorService != null) {
executorService.shutdown();
}
executorService = Executors.newSingleThreadScheduledExecutor();
}
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

View File

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