From 13011ff371a74d4956d9845bc81d75c9404a544e Mon Sep 17 00:00:00 2001 From: darksaid98 Date: Sun, 17 Sep 2023 01:13:51 +0200 Subject: [PATCH] feat: event mode --- build.gradle.kts | 44 ++--- .../AlathranWars/commands/AdminCommands.java | 1 + .../AlathranWars/commands/WarCommands.java | 185 +++++++++++------- .../alathra/AlathranWars/conflict/War.java | 25 ++- .../conflict/battle/siege/Siege.java | 46 +++-- .../AlathranWars/data/ConfigManager.java | 2 +- .../listeners/siege/PlayerDeathListener.java | 38 ++++ .../alathra/AlathranWars/utility/Config.java | 2 +- .../AlathranWars/utility/SQLQueries.java | 22 ++- war.todo | 1 - 10 files changed, 240 insertions(+), 126 deletions(-) delete mode 100644 war.todo diff --git a/build.gradle.kts b/build.gradle.kts index 25adae2..e78d585 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,9 @@ repositories { mavenCentral() maven("https://papermc.io/repo/repository/maven-public/") - maven("https://mvn-repo.arim.space/lesser-gpl3/") + maven("https://mvn-repo.arim.space/lesser-gpl3/") { + content { includeGroup("space.arim.morepaperlib") } + } maven("https://repo.glaremasters.me/repository/towny/") { content { includeGroup("com.palmergames.bukkit.towny") } @@ -49,28 +51,15 @@ repositories { dependencies { compileOnly("org.jetbrains:annotations:24.0.1") + annotationProcessor("org.jetbrains:annotations:24.0.1") - paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") implementation("space.arim.morepaperlib:morepaperlib:0.4.3") - implementation("com.github.milkdrinkers:simplixstorage:3.2.7") - implementation("com.github.milkdrinkers:colorparser:2.0.0") { - exclude(group = "net.kyori", module = "adventure-api") - } + implementation("com.github.milkdrinkers:crate:1.1.0") + implementation("com.github.milkdrinkers:colorparser:2.0.0") - compileOnly("com.github.MilkBowl:VaultAPI:1.7") - - compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.7") { - exclude(group = "com.palmergames.adventure") - } - - compileOnly("me.neznamy:tab-api:4.0.0") - - implementation("dev.jorel:commandapi-bukkit-shade:9.0.3") { - exclude(group = "net.kyori", module = "adventure-api") - } - compileOnly("dev.jorel:commandapi-annotations:9.0.3") - annotationProcessor("dev.jorel:commandapi-annotations:9.0.3") + implementation("dev.jorel:commandapi-bukkit-shade:9.1.0") implementation("com.zaxxer:HikariCP:5.0.1") implementation("org.mariadb.jdbc:mariadb-java-client:3.1.4") { @@ -78,11 +67,17 @@ dependencies { } compileOnly("me.clip:placeholderapi:2.11.3") { - exclude(group = "me.clip.placeholderapi.libs", module = "kyori") + exclude("me.clip.placeholderapi.libs", "kyori") } + compileOnly("com.github.MilkBowl:VaultAPI:1.7") + compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.7") { + exclude("com.palmergames.adventure") + } + compileOnly("me.neznamy:tab-api:4.0.0") compileOnly(files("lib/Graves-4.9.jar")) - compileOnly("com.github.Gecolay.GSit:core:1.4.9") + compileOnly("com.github.Gecolay.GSit:core:1.4.10") compileOnly(files("lib/HeadsPlus-7.0.14.jar")) + compileOnly(files("lib/Skulls.jar")) } tasks { @@ -112,8 +107,9 @@ tasks { fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${project.group}.${targetPkg}") reloc("space.arim.morepaperlib", "morepaperlib") - reloc("de.leonhard.storage", "storageapi") reloc("dev.jorel.commandapi", "commandapi") + reloc("com.github.milkdrinkers.Crate", "crate") + reloc("com.github.milkdrinkers.colorparser", "colorparser") reloc("com.zaxxer.hikari", "hikaricp") reloc("org.mariadb.jdbc", "mariadb") } @@ -138,10 +134,10 @@ bukkit { description = "${project.description}" authors = listOf("darksaid98", "ShermansWorld", "NinjaMandalorian", "AubriTheHuman") contributors = listOf() - apiVersion = "1.19" + apiVersion = "1.20" // Misc properties load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.POSTWORLD // STARTUP or POSTWORLD depend = listOf("Vault", "Towny") - softDepend = listOf("TAB") + softDepend = listOf("TAB", "Skulls", "HeadsPlus") } \ No newline at end of file diff --git a/src/main/java/com/github/alathra/AlathranWars/commands/AdminCommands.java b/src/main/java/com/github/alathra/AlathranWars/commands/AdminCommands.java index 8a0efe7..64c36f8 100644 --- a/src/main/java/com/github/alathra/AlathranWars/commands/AdminCommands.java +++ b/src/main/java/com/github/alathra/AlathranWars/commands/AdminCommands.java @@ -96,6 +96,7 @@ public class AdminCommands { WarCommands.commandCreate(true), WarCommands.commandDelete(true), WarCommands.commandJoin(true), + WarCommands.commandJoinNear(), WarCommands.commandSurrender(true), WarCommands.commandList(), WarCommands.commandInfo() 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 d7155b4..aadad9a 100644 --- a/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java +++ b/src/main/java/com/github/alathra/AlathranWars/commands/WarCommands.java @@ -13,6 +13,7 @@ import com.palmergames.bukkit.towny.object.Town; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.BooleanArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; @@ -21,6 +22,7 @@ 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.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -58,6 +60,7 @@ public class WarCommands { .withArguments( CommandUtil.customTownAndNationArgument("side1", "war", false), CommandUtil.customTownAndNationArgument("side2", "war", false), + new BooleanArgument("event"), new GreedyStringArgument("warlabel") .replaceSuggestions( ArgumentSuggestions.stringCollection(info -> List.of( @@ -89,7 +92,17 @@ public class WarCommands { // new PlayerArgument("nation").setOptional(true).withPermission("AlathranWars.admin.join"), // new PlayerArgument("town").setOptional(true).withPermission("AlathranWars.admin.join") ) - .executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, false)); + .executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, asAdmin)); + } + + public static CommandAPICommand commandJoinNear() { + return new CommandAPICommand("joinnear") + .withPermission("AlathranWars.admin") + .withArguments( + CommandUtil.warWarArgument("war", true, ALL_WARS, ""), + CommandUtil.warSideCreateArgument("side", "war", true, false, "") + ) + .executesPlayer((Player p, CommandArguments args) -> warJoinNear(p, args, true)); } public static CommandAPICommand commandSurrender(boolean asAdmin) { @@ -123,6 +136,8 @@ public class WarCommands { if (Objects.equals(args.get("side1"), args.get("side2"))) throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Cannot declare war on oneself.").build()); + final boolean event = (boolean) args.getOrDefault("event", false); + final UUID uuid1 = (UUID) args.get("side1"); final UUID uuid2 = (UUID) args.get("side2"); @@ -142,25 +157,25 @@ public class WarCommands { // Allow civil wars if (nation2.getUUID() != nation1.getUUID()) { - new War(argLabel, nation1, nation2); + new War(argLabel, nation1, nation2, event); } else { - new War(argLabel, town1, town2); + new War(argLabel, town1, town2, event); } } else if (town2 != null) { // Nation vs Town - new War(argLabel, nation1, town2); + new War(argLabel, nation1, town2, event); } } else if (town1 != null) { if (town2 != null) { // Town vs Town - new War(argLabel, town1, town2); + new War(argLabel, town1, town2, event); } else if (nation2 != null) { // Nation vs Town - new War(argLabel, town1, nation2); + new War(argLabel, town1, nation2, event); } @@ -209,70 +224,72 @@ public class WarCommands { final boolean canKingJoin = (res.hasNation() && res.getNationOrNull().equals(nation) && res.isKing() && nation.isKing(res)); final boolean canMayorJoin = (res.hasTown() && res.getTownOrNull().equals(town) && res.isMayor() && town.isMayor(res)); - // Join nation into war - if (isNation && nation != null && !war.isNationInWar(nation) && (asAdmin || canKingJoin)) { - side.addNation(nation); - nation.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(PlayerJoinListener::checkPlayer); - Bukkit.broadcast( - ColorParser.of( - "The nation of joined the war of on the side of ." - ) - .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) - .parseMinimessagePlaceholder("nation", nation.getName()) - .parseMinimessagePlaceholder("war", war.getLabel()) - .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); + if (!war.isEvent()) { + // Join nation into war + if (isNation && nation != null && !war.isNationInWar(nation) && (asAdmin || canKingJoin)) { + side.addNation(nation); + nation.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(PlayerJoinListener::checkPlayer); + Bukkit.broadcast( + ColorParser.of( + "The nation of joined the war of on the side of ." + ) + .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) + .parseMinimessagePlaceholder("nation", nation.getName()) + .parseMinimessagePlaceholder("war", war.getLabel()) + .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()); - } + 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()); + } - // Join town into war - if (isTown && town != null && !war.isTownInWar(town) && (asAdmin || canMayorJoin)) { - side.addTown(town); - town.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(PlayerJoinListener::checkPlayer); - Bukkit.broadcast( - ColorParser.of( - "The town of joined the war of on the side of ." - ) - .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) - .parseMinimessagePlaceholder("town", town.getName()) - .parseMinimessagePlaceholder("war", war.getLabel()) - .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); + // Join town into war + if (isTown && town != null && !war.isTownInWar(town) && (asAdmin || canMayorJoin)) { + side.addTown(town); + town.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(PlayerJoinListener::checkPlayer); + Bukkit.broadcast( + ColorParser.of( + "The town of joined the war of on the side of ." + ) + .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) + .parseMinimessagePlaceholder("town", town.getName()) + .parseMinimessagePlaceholder("war", war.getLabel()) + .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()); + 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()); + } } // Join player into war @@ -313,6 +330,40 @@ public class WarCommands { }*/ } + protected static void warJoinNear(@NotNull Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException { + War war = (War) args.get("war"); + if (war == null) return; + + if (!(args.get("side") instanceof final Side side)) + throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You need to specify a side.").build()); + + final Location location = p.getLocation(); + + for (Player targetPlayer : Bukkit.getOnlinePlayers()) { + if (p.equals(targetPlayer)) continue; + final Location targetLocation = targetPlayer.getLocation(); + if (!location.getWorld().equals(targetLocation.getWorld())) continue; + if (location.distance(targetLocation) > 25D) continue; + if (war.isPlayerInWar(targetPlayer)) continue; + + 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); + } + } + protected static void warSurrender(@NotNull Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException { War war = (War) args.get("war"); if (war == null) return; 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 259d292..1130f29 100644 --- a/src/main/java/com/github/alathra/AlathranWars/conflict/War.java +++ b/src/main/java/com/github/alathra/AlathranWars/conflict/War.java @@ -38,6 +38,7 @@ public class War extends Conflict { private final String name; // Used in commands and such, like "TidalHaven.vs.Meme" private final String label; private final ConflictType conflictType = ConflictType.WAR; + private boolean event = false; private final @NotNull Side side1; private final Side side2; @@ -54,7 +55,8 @@ public class War extends Conflict { @NotNull Side side1, Side side2, Set sieges, - Set raids + Set raids, + boolean event ) { this.uuid = uuid; this.name = name; @@ -68,6 +70,7 @@ public class War extends Conflict { this.sieges = sieges; this.raids = raids; + this.event = event; resume(); } @@ -79,7 +82,7 @@ public class War extends Conflict { * @param aggressor the side 1 * @param victim the side 2 */ - public War(final String label, @NotNull Town aggressor, @NotNull Town victim) throws WrapperCommandSyntaxException { + public War(final String label, @NotNull Town aggressor, @NotNull Town victim, boolean event) throws WrapperCommandSyntaxException { this.uuid = UUIDUtil.generateWarUUID(); this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName()); this.label = label; @@ -94,13 +97,14 @@ public class War extends Conflict { this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2; this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2; + this.event = event; WarManager.getInstance().addWar(this); start(); } - public War(final String label, @NotNull Nation aggressor, @NotNull Nation victim) throws WrapperCommandSyntaxException { + public War(final String label, @NotNull Nation aggressor, @NotNull Nation victim, boolean event) throws WrapperCommandSyntaxException { this.uuid = UUIDUtil.generateWarUUID(); this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName()); this.label = label; @@ -115,13 +119,14 @@ public class War extends Conflict { this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2; this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2; + this.event = event; WarManager.getInstance().addWar(this); start(); } - public War(final String label, @NotNull Town aggressor, @NotNull Nation victim) throws WrapperCommandSyntaxException { + public War(final String label, @NotNull Town aggressor, @NotNull Nation victim, boolean event) throws WrapperCommandSyntaxException { this.uuid = UUIDUtil.generateWarUUID(); this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName()); this.label = label; @@ -136,13 +141,14 @@ public class War extends Conflict { this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2; this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2; + this.event = event; WarManager.getInstance().addWar(this); start(); } - public War(final String label, @NotNull Nation aggressor, @NotNull Town victim) throws WrapperCommandSyntaxException { + public War(final String label, @NotNull Nation aggressor, @NotNull Town victim, boolean event) throws WrapperCommandSyntaxException { this.uuid = UUIDUtil.generateWarUUID(); this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName()); this.label = label; @@ -157,6 +163,7 @@ public class War extends Conflict { this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2; this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2; + this.event = event; WarManager.getInstance().addWar(this); @@ -635,4 +642,12 @@ public class War extends Conflict { end(); } + + public void setEvent(boolean event) { + this.event = event; + } + + public boolean isEvent() { + return event; + } } 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 2493fe7..f66fabc 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 @@ -108,7 +108,8 @@ public class Siege extends Battle { */ public void start() { siegeRunnable = new SiegeRunnable(this); - Main.econ.withdrawPlayer(siegeLeader, SIEGE_VICTORY_MONEY); + if (!war.isEvent()) + 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( @@ -165,19 +166,21 @@ public class Siege extends Battle { } public void attackersWin() { - Main.econ.depositPlayer(siegeLeader, SIEGE_VICTORY_MONEY); - double amt; + if (!war.isEvent()) { + Main.econ.depositPlayer(siegeLeader, SIEGE_VICTORY_MONEY); + double amt; - if (town.getAccount().getHoldingBalance() > 10000.0) { - amt = Math.floor(town.getAccount().getHoldingBalance()) / 4.0; - town.getAccount().withdraw(amt, "Siege Defeat"); - } else { - town.getAccount().withdraw(SIEGE_VICTORY_MONEY, "Siege Defeat"); - amt = SIEGE_VICTORY_MONEY; + if (town.getAccount().getHoldingBalance() > 10000.0) { + amt = Math.floor(town.getAccount().getHoldingBalance()) / 4.0; + town.getAccount().withdraw(amt, "Siege Defeat"); + } else { + town.getAccount().withdraw(SIEGE_VICTORY_MONEY, "Siege Defeat"); + amt = SIEGE_VICTORY_MONEY; + } + + Main.econ.depositPlayer(siegeLeader, amt); } - Main.econ.depositPlayer(siegeLeader, amt); - Bukkit.broadcast(ColorParser.of("The town of has been sacked and placed under occupation by the armies of !") .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) .parseMinimessagePlaceholder("town", town.getName()) @@ -219,20 +222,23 @@ public class Siege extends Battle { stop(); - Side townSide = getWar().getTownSide(town); - Side attackerSide = getAttackerSide(); + if (!war.isEvent()) { + Side townSide = getWar().getTownSide(town); + Side attackerSide = getAttackerSide(); - if (attackerSide.equals(townSide)) { - if (townSide.isTownSurrendered(town)) - war.unsurrenderTown(town); - } else { - if (!townSide.isTownSurrendered(town)) - war.surrenderTown(town); + if (attackerSide.equals(townSide)) { + if (townSide.isTownSurrendered(town)) + war.unsurrenderTown(town); + } else { + if (!townSide.isTownSurrendered(town)) + war.surrenderTown(town); + } } } public void defendersWin() { - town.getAccount().deposit(SIEGE_VICTORY_MONEY, "Siege Victory"); + if (!war.isEvent()) + town.getAccount().deposit(SIEGE_VICTORY_MONEY, "Siege Victory"); Bukkit.broadcast( ColorParser.of("The siege of has been lifted by the defenders!") diff --git a/src/main/java/com/github/alathra/AlathranWars/data/ConfigManager.java b/src/main/java/com/github/alathra/AlathranWars/data/ConfigManager.java index e6b7e17..cf13707 100644 --- a/src/main/java/com/github/alathra/AlathranWars/data/ConfigManager.java +++ b/src/main/java/com/github/alathra/AlathranWars/data/ConfigManager.java @@ -1,7 +1,7 @@ package com.github.alathra.AlathranWars.data; import com.github.alathra.AlathranWars.Main; -import de.leonhard.storage.Config; +import com.github.milkdrinkers.Crate.Config; public class ConfigManager { private final Main instance; diff --git a/src/main/java/com/github/alathra/AlathranWars/listeners/siege/PlayerDeathListener.java b/src/main/java/com/github/alathra/AlathranWars/listeners/siege/PlayerDeathListener.java index 82ad968..463c4df 100644 --- a/src/main/java/com/github/alathra/AlathranWars/listeners/siege/PlayerDeathListener.java +++ b/src/main/java/com/github/alathra/AlathranWars/listeners/siege/PlayerDeathListener.java @@ -2,6 +2,9 @@ package com.github.alathra.AlathranWars.listeners.siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.utility.Utils; +import com.palmergames.bukkit.towny.event.deathprice.NationPaysDeathPriceEvent; +import com.palmergames.bukkit.towny.event.deathprice.PlayerPaysDeathPriceEvent; +import com.palmergames.bukkit.towny.event.deathprice.TownPaysDeathPriceEvent; import com.ranull.graves.event.GraveCreateEvent; import io.github.thatsmusic99.headsplus.api.events.PlayerHeadDropEvent; import org.bukkit.entity.EntityType; @@ -34,6 +37,39 @@ public class PlayerDeathListener implements Listener { e.setCancelled(true); } + @EventHandler + public void onPlayerPaysDeathPrice(PlayerPaysDeathPriceEvent e) { + Player p = e.getDeadResident().getPlayer(); + Siege siege = Utils.getClosestSiege(p, true); + if (siege == null) return; + + if (!Utils.isOnSiegeBattlefield(p, siege)) return; + + e.setCancelled(true); + } + + @EventHandler + public void onPlayerPaysDeathPrice(TownPaysDeathPriceEvent e) { + Player p = e.getDeadResident().getPlayer(); + Siege siege = Utils.getClosestSiege(p, true); + if (siege == null) return; + + if (!Utils.isOnSiegeBattlefield(p, siege)) return; + + e.setCancelled(true); + } + + @EventHandler + public void onPlayerPaysDeathPrice(NationPaysDeathPriceEvent e) { + Player p = e.getDeadResident().getPlayer(); + Siege siege = Utils.getClosestSiege(p, true); + if (siege == null) return; + + if (!Utils.isOnSiegeBattlefield(p, siege)) return; + + e.setCancelled(true); + } + @EventHandler private void onPlayerDeath(PlayerDeathEvent e) { Player victim = e.getPlayer(); @@ -82,6 +118,7 @@ public class PlayerDeathListener implements Listener { e.setKeepInventory(true); e.getDrops().clear(); e.setKeepLevel(true); + e.setDroppedExp(0); } /** @@ -95,5 +132,6 @@ public class PlayerDeathListener implements Listener { e.setKeepInventory(true); e.getDrops().clear(); e.setKeepLevel(true); + e.setDroppedExp(0); } } diff --git a/src/main/java/com/github/alathra/AlathranWars/utility/Config.java b/src/main/java/com/github/alathra/AlathranWars/utility/Config.java index 8cd4d45..f7ceeb6 100644 --- a/src/main/java/com/github/alathra/AlathranWars/utility/Config.java +++ b/src/main/java/com/github/alathra/AlathranWars/utility/Config.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; * Convenience class for accessing {@link com.github.alathra.AlathranWars.data.ConfigManager} */ public abstract class Config { - public static @NotNull de.leonhard.storage.Config get() { + public static @NotNull com.github.milkdrinkers.Crate.Config get() { return Main.getInstance().getConfigManager().getConfig(); } } diff --git a/src/main/java/com/github/alathra/AlathranWars/utility/SQLQueries.java b/src/main/java/com/github/alathra/AlathranWars/utility/SQLQueries.java index 9c4a434..36fb848 100644 --- a/src/main/java/com/github/alathra/AlathranWars/utility/SQLQueries.java +++ b/src/main/java/com/github/alathra/AlathranWars/utility/SQLQueries.java @@ -144,6 +144,10 @@ public abstract class SQLQueries { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; """); + statement.addBatch(""" + ALTER TABLE `wars_list` ADD COLUMN `event` BIT NOT NULL DEFAULT 0 AFTER `side2`; + """); + statement.executeLargeBatch(); } catch (SQLException e) { e.printStackTrace(); @@ -153,8 +157,8 @@ public abstract class SQLQueries { public static void saveAll() { try ( @NotNull Connection con = DB.get(); - PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) " - + "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?") + PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`, `event`) VALUES (?, ?, ?, ?, ?, ?) " + + "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?, `event` = ?") ) { // Save wars for (@NotNull War war : WarManager.getInstance().getWars()) { @@ -164,12 +168,14 @@ public abstract class SQLQueries { warStatement.setString(3, war.getLabel()); warStatement.setString(4, war.getSide1().getUUID().toString()); warStatement.setString(5, war.getSide2().getUUID().toString()); + warStatement.setBoolean(6, war.isEvent()); // Update - warStatement.setString(6, war.getName()); - warStatement.setString(7, war.getLabel()); - warStatement.setString(8, war.getSide1().getUUID().toString()); - warStatement.setString(9, war.getSide2().getUUID().toString()); + warStatement.setString(7, war.getName()); + warStatement.setString(8, war.getLabel()); + warStatement.setString(9, war.getSide1().getUUID().toString()); + warStatement.setString(10, war.getSide2().getUUID().toString()); + warStatement.setBoolean(11, war.isEvent()); warStatement.executeUpdate(); @@ -336,6 +342,7 @@ public abstract class SQLQueries { @NotNull UUID side2UUID = UUID.fromString(warsResult.getString("side2")); @NotNull Side side1 = loadSide(con, uuid, side1UUID); @NotNull Side side2 = loadSide(con, uuid, side2UUID); + boolean event = warsResult.getBoolean("event"); wars.add(new War( uuid, @@ -344,7 +351,8 @@ public abstract class SQLQueries { side1, side2, new HashSet<>(), - new HashSet<>() + new HashSet<>(), + event )); } diff --git a/war.todo b/war.todo deleted file mode 100644 index 6b84ccc..0000000 --- a/war.todo +++ /dev/null @@ -1 +0,0 @@ -* Ignore all cannon block placements so engineers can build them and destroy during oldSieges \ No newline at end of file