diff --git a/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java b/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java index 0a82dc9..d7155b4 100644 --- a/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java +++ b/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java @@ -17,12 +17,16 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.title.Title; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.List; import java.util.Objects; import java.util.Set; @@ -219,6 +223,20 @@ public class WarCommands { .parseMinimessagePlaceholder("side", side.getName()) .build() ); + final Title warTitle = Title.title( + ColorParser.of("War") + .build(), + ColorParser.of("You entered the war of !") + .parseMinimessagePlaceholder("war", war.getLabel()) + .build(), + Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)) + ); + final Sound warSound = Sound.sound(Key.key("entity.wither.spawn"), Sound.Source.VOICE, 0.5f, 1.0F); + + nation.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(player -> { + player.showTitle(warTitle); + player.playSound(warSound); + }); return; } else if (town == null && nation != null && (!canKingJoin || !asAdmin)) { throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("Nation is already in that war.").build()); @@ -238,6 +256,20 @@ public class WarCommands { .parseMinimessagePlaceholder("side", side.getName()) .build() ); + final Title warTitle = Title.title( + ColorParser.of("War") + .build(), + ColorParser.of("You entered the war of !") + .parseMinimessagePlaceholder("war", war.getLabel()) + .build(), + Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)) + ); + final Sound warSound = Sound.sound(Key.key("entity.wither.spawn"), Sound.Source.VOICE, 0.5f, 1.0F); + + town.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(player -> { + player.showTitle(warTitle); + player.playSound(warSound); + }); return; } else if (targetPlayer == null && town != null && !canMayorJoin) { throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("Town is already in that war.").build()); @@ -248,6 +280,18 @@ public class WarCommands { targetPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build()); side.addPlayer(targetPlayer); PlayerJoinListener.checkPlayer(targetPlayer); + final Title warTitle = Title.title( + ColorParser.of("War") + .build(), + ColorParser.of("You entered the war of !") + .parseMinimessagePlaceholder("war", war.getLabel()) + .build(), + Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)) + ); + final Sound warSound = Sound.sound(Key.key("entity.wither.spawn"), Sound.Source.VOICE, 0.5f, 1.0F); + + targetPlayer.showTitle(warTitle); + targetPlayer.playSound(warSound); return; } else if (!asAdmin) { throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("Players cannot individually join wars.").build()); diff --git a/src/main/java/com/github/alathra/AlathranWars/listeners/war/TownListener.java b/src/main/java/com/github/alathra/AlathranWars/listeners/war/TownListener.java index 8f7917e..567d8fe 100644 --- a/src/main/java/com/github/alathra/AlathranWars/listeners/war/TownListener.java +++ b/src/main/java/com/github/alathra/AlathranWars/listeners/war/TownListener.java @@ -3,17 +3,24 @@ package com.github.alathra.AlathranWars.listeners.war; import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.WarManager; +import com.github.milkdrinkers.colorparser.ColorParser; import com.palmergames.bukkit.towny.event.TownAddResidentEvent; import com.palmergames.bukkit.towny.event.TownPreRenameEvent; import com.palmergames.bukkit.towny.event.town.TownKickEvent; import com.palmergames.bukkit.towny.event.town.TownLeaveEvent; import com.palmergames.bukkit.towny.event.town.TownPreMergeEvent; import com.palmergames.bukkit.towny.event.town.TownRuinedEvent; +import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.title.Title; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import java.time.Duration; + public class TownListener implements Listener { @EventHandler private void onRename(TownPreRenameEvent e) { @@ -37,6 +44,19 @@ public class TownListener implements Listener { Side side = war.getTownSide(town); if (side == null) continue; side.addPlayer(p); + + final Title warTitle = Title.title( + ColorParser.of("War") + .build(), + ColorParser.of("You entered the war of !") + .parseMinimessagePlaceholder("war", war.getLabel()) + .build(), + Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)) + ); + final Sound warSound = Sound.sound(Key.key("entity.wither.spawn"), Sound.Source.VOICE, 0.5f, 1.0F); + + p.showTitle(warTitle); + p.playSound(warSound); } PlayerJoinListener.checkPlayer(p);