feat: war/siege start/end titles & sounds

This commit is contained in:
darksaid98 committed 2023-08-01 17:30:30 +02:00
1 parent 31d0bb1f6b
commit b58100a814
4 files changed
+141 -31

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ dependencies {
compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.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") compileOnly("me.neznamy:tab-api:4.0.0")
@@ -14,12 +14,16 @@ import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@@ -293,6 +297,11 @@ public class War extends Conflict {
return sieges; return sieges;
} }
public void setSieges(Set<Siege> sieges) {
this.sieges = sieges;
this.sieges.forEach(Siege::resume);
}
@Nullable @Nullable
public Siege getSiege(UUID uuid) { public Siege getSiege(UUID uuid) {
for (@NotNull Siege siege : sieges) { for (@NotNull Siege siege : sieges) {
@@ -316,11 +325,6 @@ public class War extends Conflict {
sieges.remove(siege); sieges.remove(siege);
} }
public void setSieges(Set<Siege> sieges) {
this.sieges = sieges;
this.sieges.forEach(Siege::resume);
}
/** /**
* Gets raids. * Gets raids.
* *
@@ -569,6 +573,25 @@ public class War extends Conflict {
.build() .build()
); );
final Title warTitle = Title.title(
ColorParser.of("<gradient:#D72A09:#B01F03><u><b>War")
.build(),
ColorParser.of("<gray><i>The war of <war> 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(); side1.applyNameTags();
side2.applyNameTags(); side2.applyNameTags();
} }
@@ -14,7 +14,10 @@ import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import net.kyori.adventure.bossbar.BossBar; 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.text.Component;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -24,9 +27,7 @@ import org.jetbrains.annotations.Nullable;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.HashSet; import java.util.*;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; 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_MAX_RANGE = BATTLEFIELD_RANGE * 2;
public static final int BATTLEFIELD_START_MIN_RANGE = 75; public static final int BATTLEFIELD_START_MIN_RANGE = 75;
public static final double SIEGE_VICTORY_MONEY = 2500.0; public static final double SIEGE_VICTORY_MONEY = 2500.0;
private final static Title.Times TITLE_TIMES = Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500));
private @NotNull War war; // War which siege belongs to 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 @NotNull UUID uuid;
private final Set<Player> attackers = new HashSet<>(); // Players inside battlefield private final Set<Player> attackers = new HashSet<>(); // Players inside battlefield
private final Set<Player> defenders = new HashSet<>(); // Players inside battlefield private final Set<Player> defenders = new HashSet<>(); // Players inside battlefield
@@ -49,21 +51,17 @@ public class Siege extends Battle {
private final Set<Player> defenderPlayers = new HashSet<>(); private final Set<Player> defenderPlayers = new HashSet<>();
private final Set<UUID> attackerPlayersIncludingOffline = new HashSet<>(); private final Set<UUID> attackerPlayersIncludingOffline = new HashSet<>();
private final Set<UUID> defenderPlayersIncludingOffline = new HashSet<>(); private final Set<UUID> defenderPlayersIncludingOffline = new HashSet<>();
private @NotNull War war; // War which siege belongs to
private Instant endTime; private Instant endTime;
private int siegeProgress = 0; private int siegeProgress = 0;
private Instant lastTouched; private Instant lastTouched;
private SiegeRunnable siegeRunnable; private SiegeRunnable siegeRunnable;
private Town town; // Town of the siege private Town town; // Town of the siege
private boolean side1AreAttackers; // bool of if side1 being attacker private boolean side1AreAttackers; // bool of if side1 being attacker
private OfflinePlayer siegeLeader; private OfflinePlayer siegeLeader;
private @Nullable TownBlock homeBlock = null; private @Nullable TownBlock homeBlock = null;
private @Nullable Location townSpawn = null; private @Nullable Location townSpawn = null;
private @Nullable BossBar activeBossBar = null; private @Nullable BossBar activeBossBar = null;
private boolean stopped = false; // Used to track if the siege has been already deleted 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) { public Siege(final @NotNull War war, final Town town, Player siegeLeader) {
@@ -111,6 +109,41 @@ public class Siege extends Battle {
public void start() { public void start() {
siegeRunnable = new SiegeRunnable(this); siegeRunnable = new SiegeRunnable(this);
Main.econ.withdrawPlayer(siegeLeader, SIEGE_VICTORY_MONEY); 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("<red><u><b><town>")
.parseMinimessagePlaceholder("town", town.getName())
.build(),
ColorParser.of("<gray><i>Is under siege, defend!")
.build(),
times
);
final Title attTitle = Title.title(
ColorParser.of("<red><u><b><town>")
.parseMinimessagePlaceholder("town", town.getName())
.build(),
ColorParser.of("<gray><i>Has been put to siege, attack!")
.build(),
times
);
final List<Sound> 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; amt = Math.floor(town.getAccount().getHoldingBalance()) / 4.0;
town.getAccount().withdraw(amt, "Siege Defeat"); town.getAccount().withdraw(amt, "Siege Defeat");
} else { } else {
/*if (town.getAccount().getHoldingBalance() < SIEGE_VICTORY_MONEY) {
Bukkit.broadcast(
ColorParser.of("<prefix>The town of <town> has been destroyed by <attacker>!")
.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"); town.getAccount().withdraw(SIEGE_VICTORY_MONEY, "Siege Defeat");
amt = SIEGE_VICTORY_MONEY; amt = SIEGE_VICTORY_MONEY;
} }
@@ -165,6 +184,31 @@ public class Siege extends Battle {
.parseMinimessagePlaceholder("attacker", getAttackerSide().getName()) .parseMinimessagePlaceholder("attacker", getAttackerSide().getName())
.build()); .build());
final Title vicAttackTitle = Title.title(
ColorParser.of("<green><u><b>Victory")
.build(),
ColorParser.of("<gray><i><town> has been captured!")
.parseMinimessagePlaceholder("town", town.getName())
.build(),
TITLE_TIMES
);
final Title losAttackTitle = Title.title(
ColorParser.of("<red><u><b>Defeat")
.build(),
ColorParser.of("<gray><i><town> 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) { if (side1AreAttackers) {
war.getSide1().addScore(50); war.getSide1().addScore(50);
war.getSide2().addScore(5); war.getSide2().addScore(5);
@@ -197,6 +241,31 @@ public class Siege extends Battle {
.build() .build()
); );
final Title vicDefendTitle = Title.title(
ColorParser.of("<red><u><b>Defeat")
.build(),
ColorParser.of("<gray><i>We failed to capture <town>!")
.parseMinimessagePlaceholder("town", town.getName())
.build(),
TITLE_TIMES
);
final Title losDefendTitle = Title.title(
ColorParser.of("<green><u><b>Victory")
.build(),
ColorParser.of("<gray><i><town> 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) { if (side1AreAttackers) {
war.getSide2().addScore(10); war.getSide2().addScore(10);
} else { } else {
@@ -216,6 +285,24 @@ public class Siege extends Battle {
.parseMinimessagePlaceholder("town", town.getName()) .parseMinimessagePlaceholder("town", town.getName())
.build() .build()
); );
final Title drawTitle = Title.title(
ColorParser.of("<yellow><u><b>Draw")
.build(),
ColorParser.of("<gray><i>The siege at <town> 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(); stop();
} }
@@ -30,7 +30,7 @@ public class SiegeRunnable implements Runnable {
// Variables // Variables
private @NotNull CaptureProgressDirection oldProgressDirection = UNCONTESTED; private @NotNull CaptureProgressDirection oldProgressDirection = UNCONTESTED;
private Instant nextAnnouncement; private Instant nextAnnouncement;
private ScheduledTask task; private final ScheduledTask task;
private @Nullable Laser beam; private @Nullable Laser beam;
/** /**