added countdown and sounds

This commit is contained in:
2025-12-23 21:43:25 +01:00
parent ef153d5d8f
commit 2b0c7c1a9e
3 changed files with 56 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ import eu.mhsl.craftattack.spawn.event.appliances.deathrun.listeners.DeathrunPor
import eu.mhsl.craftattack.spawn.event.appliances.eventController.Event;
import eu.mhsl.craftattack.spawn.event.appliances.eventController.Scorable;
import eu.mhsl.craftattack.spawn.event.appliances.eventController.scoreboard.EventScoreboardBuilder;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
@@ -28,7 +29,7 @@ import java.util.UUID;
@Appliance.Flags(autoload = false)
public class Deathrun extends Appliance implements Event, Scorable {
private final EventScoreboardBuilder scoreboardBuilder = new EventScoreboardBuilder(this, 3, 2, 3);
private final double borderDistance = 75;
private final double borderDistance = 100;
private final int borderVisibilityDistance = 8;
private long durationSeconds;
private boolean isBeforeStart = true;
@@ -81,15 +82,25 @@ public class Deathrun extends Appliance implements Event, Scorable {
// TODO: Soll PvP überhaupt aktiviert werden? Soll Respawn erlaubt sein?
Bukkit.getOnlinePlayers().forEach(player -> {
player.showTitle(title);
player.sendMessage(Component.text("PvP wird in 10 Minuten aktiviert!", NamedTextColor.GOLD));
player.sendMessage(Component.text("Start! Laufe Richtung Osten (positiv x)!", NamedTextColor.YELLOW));
});
Bukkit.getScheduler().runTaskLater(
Main.instance(),
() -> Bukkit.getOnlinePlayers().forEach(player ->
player.sendMessage(Component.text("PvP wird in 10 Minuten aktiviert!", NamedTextColor.GOLD))
),
Ticks.TICKS_PER_SECOND * 5
);
this.world.getWorldBorder().setSize(this.world.getWorldBorder().getMaxSize());
this.pvpTask = Bukkit.getScheduler().runTaskLater(
Main.instance(),
() -> {
this.pvpDisabled = false;
Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(Component.text("PvP ist jetzt aktiviert!", NamedTextColor.GOLD)));
Bukkit.getOnlinePlayers().forEach(player -> {
player.sendMessage(Component.text("PvP ist jetzt aktiviert!", NamedTextColor.GOLD));
player.playSound(Sound.sound(org.bukkit.Sound.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.MASTER, 500f, 2f));
});
},
Ticks.TICKS_PER_SECOND * 60 * 10
);

View File

@@ -6,6 +6,8 @@ import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.core.util.IteratorUtil;
import eu.mhsl.craftattack.spawn.core.util.entity.PlayerUtils;
import eu.mhsl.craftattack.spawn.core.util.server.PluginMessage;
import eu.mhsl.craftattack.spawn.core.util.text.ComponentUtil;
import eu.mhsl.craftattack.spawn.core.util.text.Countdown;
import eu.mhsl.craftattack.spawn.event.appliances.eventController.commands.BigEventCommand;
import eu.mhsl.craftattack.spawn.event.appliances.eventController.commands.JoinCraftattackCommand;
import net.kyori.adventure.sound.Sound;
@@ -27,6 +29,13 @@ public class EventController extends Appliance {
private List<Appliance> eventAppliances = null;
private Event selectedEvent = null;
private int timerTaskId = -1;
private long durationMinutes;
private final Countdown countdown = new Countdown(
10,
this::format,
this::announce,
this::startEvent
);
private final Map<GameRule<Boolean>, Boolean> gameRulesAfterStart = Map.ofEntries(
entry(GameRule.DO_DAYLIGHT_CYCLE, true),
@@ -72,6 +81,36 @@ public class EventController extends Appliance {
this.selectedEvent = null;
}
public void scheduleStart(long durationMinutes) {
if(this.selectedEvent == null) throw new ApplianceCommand.Error("There is no event selected!");
this.durationMinutes = durationMinutes;
this.countdown.start();
}
public void cancelStart() {
this.countdown.cancel();
}
private Component format(Countdown.AnnouncementData data) {
return Component.text()
.append(ComponentUtil.createRainbowText(this.selectedEvent.getClass().getSimpleName(), 10))
.append(Component.text(" startet in ", NamedTextColor.GOLD))
.append(Component.text(data.count(), NamedTextColor.AQUA))
.append(Component.text(" " + data.unit() + "!", NamedTextColor.GOLD))
.build();
}
private void announce(Component message) {
IteratorUtil.onlinePlayers(player -> {
player.sendMessage(message);
player.playSound(Sound.sound(org.bukkit.Sound.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.MASTER, 500f, 1f));
});
}
private void startEvent() {
this.startEvent(this.durationMinutes);
}
public void startEvent(long durationMinutes) {
if(this.selectedEvent == null) throw new ApplianceCommand.Error("There is no event selected!");
IteratorUtil.worlds(world -> IteratorUtil.setGameRules(this.gameRulesAfterStart, false));

View File

@@ -35,12 +35,12 @@ public class BigEventCommand extends ApplianceCommand<EventController> {
}
case "start": {
if(args.length == 1) {
this.getAppliance().startEvent(60 * 2);
this.getAppliance().scheduleStart(60 * 2);
break;
}
if(args.length == 2) {
try {
this.getAppliance().startEvent(Long.parseLong(args[1]));
this.getAppliance().scheduleStart(Long.parseLong(args[1]));
} catch(NumberFormatException e) {
throw new Error("Last argument has to be a long.");
}
@@ -48,6 +48,7 @@ public class BigEventCommand extends ApplianceCommand<EventController> {
break;
}
case "stop": {
this.getAppliance().cancelStart();
this.getAppliance().stopEvent();
break;
}