diff --git a/build.gradle.kts b/build.gradle.kts index 88d3c77..48db873 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,7 +61,7 @@ dependencies { compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.7") { - exclude(group = "com.palmergames", module = "adventure") + exclude(group = "com.palmergames.adventure") } compileOnly("me.neznamy:tab-api:4.0.0") diff --git a/src/main/java/com/github/alathra/AlathranWars/conflict/War.java b/src/main/java/com/github/alathra/AlathranWars/conflict/War.java index d546557..259d292 100644 --- a/src/main/java/com/github/alathra/AlathranWars/conflict/War.java +++ b/src/main/java/com/github/alathra/AlathranWars/conflict/War.java @@ -14,12 +14,16 @@ import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +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.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -293,6 +297,11 @@ public class War extends Conflict { return sieges; } + public void setSieges(Set sieges) { + this.sieges = sieges; + this.sieges.forEach(Siege::resume); + } + @Nullable public Siege getSiege(UUID uuid) { for (@NotNull Siege siege : sieges) { @@ -316,11 +325,6 @@ public class War extends Conflict { sieges.remove(siege); } - public void setSieges(Set sieges) { - this.sieges = sieges; - this.sieges.forEach(Siege::resume); - } - /** * Gets raids. * @@ -569,6 +573,25 @@ public class War extends Conflict { .build() ); + final Title warTitle = Title.title( + ColorParser.of("War") + .build(), + ColorParser.of("The war of has begun!") + .parseMinimessagePlaceholder("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); + + side1.getPlayers().forEach(player -> { + player.showTitle(warTitle); + player.playSound(warSound); + }); + side2.getPlayers().forEach(player -> { + player.showTitle(warTitle); + player.playSound(warSound); + }); + side1.applyNameTags(); side2.applyNameTags(); } diff --git a/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/Siege.java b/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/Siege.java index 6b5bb5c..2493fe7 100644 --- a/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/Siege.java +++ b/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/Siege.java @@ -14,7 +14,10 @@ import com.github.milkdrinkers.colorparser.ColorParser; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; +import net.kyori.adventure.title.Title; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -24,9 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.time.Duration; import java.time.Instant; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,8 +41,9 @@ public class Siege extends Battle { public static final int BATTLEFIELD_START_MAX_RANGE = BATTLEFIELD_RANGE * 2; public static final int BATTLEFIELD_START_MIN_RANGE = 75; public static final double SIEGE_VICTORY_MONEY = 2500.0; - - private @NotNull War war; // War which siege belongs to + private final static Title.Times TITLE_TIMES = Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)); + private final static Sound SOUND_VICTORY = Sound.sound(Key.key("item.goat_horn.sound.0"), Sound.Source.VOICE, 0.5f, 1.0F); + private final static Sound SOUND_DEFEAT = Sound.sound(Key.key("entity.wither.death"), Sound.Source.VOICE, 0.5f, 1.0F); private final @NotNull UUID uuid; private final Set attackers = new HashSet<>(); // Players inside battlefield private final Set defenders = new HashSet<>(); // Players inside battlefield @@ -49,21 +51,17 @@ public class Siege extends Battle { private final Set defenderPlayers = new HashSet<>(); private final Set attackerPlayersIncludingOffline = new HashSet<>(); private final Set defenderPlayersIncludingOffline = new HashSet<>(); - + private @NotNull War war; // War which siege belongs to private Instant endTime; private int siegeProgress = 0; private Instant lastTouched; - private SiegeRunnable siegeRunnable; - private Town town; // Town of the siege private boolean side1AreAttackers; // bool of if side1 being attacker - private OfflinePlayer siegeLeader; private @Nullable TownBlock homeBlock = null; private @Nullable Location townSpawn = null; private @Nullable BossBar activeBossBar = null; - private boolean stopped = false; // Used to track if the siege has been already deleted public Siege(final @NotNull War war, final Town town, Player siegeLeader) { @@ -111,6 +109,41 @@ public class Siege extends Battle { public void start() { siegeRunnable = new SiegeRunnable(this); Main.econ.withdrawPlayer(siegeLeader, SIEGE_VICTORY_MONEY); + + final Title.Times times = Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500)); + final Title defTitle = Title.title( + ColorParser.of("") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + ColorParser.of("Is under siege, defend!") + .build(), + times + ); + final Title attTitle = Title.title( + ColorParser.of("") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + ColorParser.of("Has been put to siege, attack!") + .build(), + times + ); + + final List soundList = List.of( + Sound.sound(Key.key("item.goat_horn.sound.0"), Sound.Source.VOICE, 0.5f, new Random().nextFloat(0.9F, 1.0F)), + Sound.sound(Key.key("item.goat_horn.sound.2"), Sound.Source.VOICE, 0.5f, new Random().nextFloat(0.9F, 1.0F)), + Sound.sound(Key.key("item.goat_horn.sound.3"), Sound.Source.VOICE, 0.5f, new Random().nextFloat(0.9F, 1.0F)), + Sound.sound(Key.key("item.goat_horn.sound.7"), Sound.Source.VOICE, 0.5f, new Random().nextFloat(0.9F, 1.0F)) + ); + + getDefenderPlayers().forEach(player -> { + player.showTitle(defTitle); + player.playSound(soundList.get(new Random().nextInt(1, soundList.size()))); + }); + + getAttackerPlayers().forEach(player -> { + player.showTitle(attTitle); + player.playSound(soundList.get(new Random().nextInt(1, soundList.size()))); + }); } /** @@ -139,20 +172,6 @@ public class Siege extends Battle { amt = Math.floor(town.getAccount().getHoldingBalance()) / 4.0; town.getAccount().withdraw(amt, "Siege Defeat"); } else { - /*if (town.getAccount().getHoldingBalance() < SIEGE_VICTORY_MONEY) { - Bukkit.broadcast( - ColorParser.of("The town of has been destroyed by !") - .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) - .parseMinimessagePlaceholder("town", town.getName()) - .parseMinimessagePlaceholder("attacker", getAttackerSide().getName()) - .build() - ); - amt = town.getAccount().getHoldingBalance(); - Main.econ.depositPlayer(siegeLeader, amt); - TownyAPI.getInstance().getDataSource().deleteTown(town); - return; - }*/ - town.getAccount().withdraw(SIEGE_VICTORY_MONEY, "Siege Defeat"); amt = SIEGE_VICTORY_MONEY; } @@ -165,6 +184,31 @@ public class Siege extends Battle { .parseMinimessagePlaceholder("attacker", getAttackerSide().getName()) .build()); + final Title vicAttackTitle = Title.title( + ColorParser.of("Victory") + .build(), + ColorParser.of(" has been captured!") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + TITLE_TIMES + ); + final Title losAttackTitle = Title.title( + ColorParser.of("Defeat") + .build(), + ColorParser.of(" has been lost!") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + TITLE_TIMES + ); + getAttackers().forEach(player -> { + player.showTitle(vicAttackTitle); + player.playSound(SOUND_VICTORY); + }); + getDefenders().forEach(player -> { + player.showTitle(losAttackTitle); + player.playSound(SOUND_DEFEAT); + }); + if (side1AreAttackers) { war.getSide1().addScore(50); war.getSide2().addScore(5); @@ -197,6 +241,31 @@ public class Siege extends Battle { .build() ); + final Title vicDefendTitle = Title.title( + ColorParser.of("Defeat") + .build(), + ColorParser.of("We failed to capture !") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + TITLE_TIMES + ); + final Title losDefendTitle = Title.title( + ColorParser.of("Victory") + .build(), + ColorParser.of(" has been made safe!") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + TITLE_TIMES + ); + getAttackers().forEach(player -> { + player.showTitle(vicDefendTitle); + player.playSound(SOUND_DEFEAT); + }); + getDefenders().forEach(player -> { + player.showTitle(losDefendTitle); + player.playSound(SOUND_VICTORY); + }); + if (side1AreAttackers) { war.getSide2().addScore(10); } else { @@ -216,6 +285,24 @@ public class Siege extends Battle { .parseMinimessagePlaceholder("town", town.getName()) .build() ); + + final Title drawTitle = Title.title( + ColorParser.of("Draw") + .build(), + ColorParser.of("The siege at has ended!") + .parseMinimessagePlaceholder("town", town.getName()) + .build(), + TITLE_TIMES + ); + getAttackers().forEach(player -> { + player.showTitle(drawTitle); + player.playSound(SOUND_DEFEAT); + }); + getDefenders().forEach(player -> { + player.showTitle(drawTitle); + player.playSound(SOUND_DEFEAT); + }); + stop(); } diff --git a/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/SiegeRunnable.java b/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/SiegeRunnable.java index 44ca983..b98d31c 100644 --- a/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/SiegeRunnable.java +++ b/src/main/java/com/github/alathra/AlathranWars/conflict/battle/siege/SiegeRunnable.java @@ -30,7 +30,7 @@ public class SiegeRunnable implements Runnable { // Variables private @NotNull CaptureProgressDirection oldProgressDirection = UNCONTESTED; private Instant nextAnnouncement; - private ScheduledTask task; + private final ScheduledTask task; private @Nullable Laser beam; /**