mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-04 14:38:57 +00:00
feat: event mode
This commit is contained in:
10 files changed
+159
-45
No files matched your search
+20
-24
@@ -19,7 +19,9 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
||||||
maven("https://papermc.io/repo/repository/maven-public/")
|
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/") {
|
maven("https://repo.glaremasters.me/repository/towny/") {
|
||||||
content { includeGroup("com.palmergames.bukkit.towny") }
|
content { includeGroup("com.palmergames.bukkit.towny") }
|
||||||
@@ -49,28 +51,15 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.jetbrains:annotations:24.0.1")
|
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("space.arim.morepaperlib:morepaperlib:0.4.3")
|
||||||
|
|
||||||
implementation("com.github.milkdrinkers:simplixstorage:3.2.7")
|
implementation("com.github.milkdrinkers:crate:1.1.0")
|
||||||
implementation("com.github.milkdrinkers:colorparser:2.0.0") {
|
implementation("com.github.milkdrinkers:colorparser:2.0.0")
|
||||||
exclude(group = "net.kyori", module = "adventure-api")
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
|
implementation("dev.jorel:commandapi-bukkit-shade:9.1.0")
|
||||||
|
|
||||||
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("com.zaxxer:HikariCP:5.0.1")
|
implementation("com.zaxxer:HikariCP:5.0.1")
|
||||||
implementation("org.mariadb.jdbc:mariadb-java-client:3.1.4") {
|
implementation("org.mariadb.jdbc:mariadb-java-client:3.1.4") {
|
||||||
@@ -78,11 +67,17 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileOnly("me.clip:placeholderapi:2.11.3") {
|
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(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/HeadsPlus-7.0.14.jar"))
|
||||||
|
compileOnly(files("lib/Skulls.jar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -112,8 +107,9 @@ tasks {
|
|||||||
fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${project.group}.${targetPkg}")
|
fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${project.group}.${targetPkg}")
|
||||||
|
|
||||||
reloc("space.arim.morepaperlib", "morepaperlib")
|
reloc("space.arim.morepaperlib", "morepaperlib")
|
||||||
reloc("de.leonhard.storage", "storageapi")
|
|
||||||
reloc("dev.jorel.commandapi", "commandapi")
|
reloc("dev.jorel.commandapi", "commandapi")
|
||||||
|
reloc("com.github.milkdrinkers.Crate", "crate")
|
||||||
|
reloc("com.github.milkdrinkers.colorparser", "colorparser")
|
||||||
reloc("com.zaxxer.hikari", "hikaricp")
|
reloc("com.zaxxer.hikari", "hikaricp")
|
||||||
reloc("org.mariadb.jdbc", "mariadb")
|
reloc("org.mariadb.jdbc", "mariadb")
|
||||||
}
|
}
|
||||||
@@ -138,10 +134,10 @@ bukkit {
|
|||||||
description = "${project.description}"
|
description = "${project.description}"
|
||||||
authors = listOf("darksaid98", "ShermansWorld", "NinjaMandalorian", "AubriTheHuman")
|
authors = listOf("darksaid98", "ShermansWorld", "NinjaMandalorian", "AubriTheHuman")
|
||||||
contributors = listOf()
|
contributors = listOf()
|
||||||
apiVersion = "1.19"
|
apiVersion = "1.20"
|
||||||
|
|
||||||
// Misc properties
|
// Misc properties
|
||||||
load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.POSTWORLD // STARTUP or POSTWORLD
|
load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.POSTWORLD // STARTUP or POSTWORLD
|
||||||
depend = listOf("Vault", "Towny")
|
depend = listOf("Vault", "Towny")
|
||||||
softDepend = listOf("TAB")
|
softDepend = listOf("TAB", "Skulls", "HeadsPlus")
|
||||||
}
|
}
|
||||||
@@ -96,6 +96,7 @@ public class AdminCommands {
|
|||||||
WarCommands.commandCreate(true),
|
WarCommands.commandCreate(true),
|
||||||
WarCommands.commandDelete(true),
|
WarCommands.commandDelete(true),
|
||||||
WarCommands.commandJoin(true),
|
WarCommands.commandJoin(true),
|
||||||
|
WarCommands.commandJoinNear(),
|
||||||
WarCommands.commandSurrender(true),
|
WarCommands.commandSurrender(true),
|
||||||
WarCommands.commandList(),
|
WarCommands.commandList(),
|
||||||
WarCommands.commandInfo()
|
WarCommands.commandInfo()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.palmergames.bukkit.towny.object.Town;
|
|||||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||||
import dev.jorel.commandapi.CommandAPICommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||||
|
import dev.jorel.commandapi.arguments.BooleanArgument;
|
||||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
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.sound.Sound;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -58,6 +60,7 @@ public class WarCommands {
|
|||||||
.withArguments(
|
.withArguments(
|
||||||
CommandUtil.customTownAndNationArgument("side1", "war", false),
|
CommandUtil.customTownAndNationArgument("side1", "war", false),
|
||||||
CommandUtil.customTownAndNationArgument("side2", "war", false),
|
CommandUtil.customTownAndNationArgument("side2", "war", false),
|
||||||
|
new BooleanArgument("event"),
|
||||||
new GreedyStringArgument("warlabel")
|
new GreedyStringArgument("warlabel")
|
||||||
.replaceSuggestions(
|
.replaceSuggestions(
|
||||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||||
@@ -89,7 +92,17 @@ public class WarCommands {
|
|||||||
// new PlayerArgument("nation").setOptional(true).withPermission("AlathranWars.admin.join"),
|
// new PlayerArgument("nation").setOptional(true).withPermission("AlathranWars.admin.join"),
|
||||||
// new PlayerArgument("town").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) {
|
public static CommandAPICommand commandSurrender(boolean asAdmin) {
|
||||||
@@ -123,6 +136,8 @@ public class WarCommands {
|
|||||||
if (Objects.equals(args.get("side1"), args.get("side2")))
|
if (Objects.equals(args.get("side1"), args.get("side2")))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
||||||
|
|
||||||
|
final boolean event = (boolean) args.getOrDefault("event", false);
|
||||||
|
|
||||||
final UUID uuid1 = (UUID) args.get("side1");
|
final UUID uuid1 = (UUID) args.get("side1");
|
||||||
final UUID uuid2 = (UUID) args.get("side2");
|
final UUID uuid2 = (UUID) args.get("side2");
|
||||||
|
|
||||||
@@ -142,25 +157,25 @@ public class WarCommands {
|
|||||||
|
|
||||||
// Allow civil wars
|
// Allow civil wars
|
||||||
if (nation2.getUUID() != nation1.getUUID()) {
|
if (nation2.getUUID() != nation1.getUUID()) {
|
||||||
new War(argLabel, nation1, nation2);
|
new War(argLabel, nation1, nation2, event);
|
||||||
} else {
|
} else {
|
||||||
new War(argLabel, town1, town2);
|
new War(argLabel, town1, town2, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (town2 != null) { // Nation vs Town
|
} else if (town2 != null) { // Nation vs Town
|
||||||
|
|
||||||
new War(argLabel, nation1, town2);
|
new War(argLabel, nation1, town2, event);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (town1 != null) {
|
} else if (town1 != null) {
|
||||||
|
|
||||||
if (town2 != null) { // Town vs Town
|
if (town2 != null) { // Town vs Town
|
||||||
|
|
||||||
new War(argLabel, town1, town2);
|
new War(argLabel, town1, town2, event);
|
||||||
|
|
||||||
} else if (nation2 != null) { // Nation vs Town
|
} else if (nation2 != null) { // Nation vs Town
|
||||||
|
|
||||||
new War(argLabel, town1, nation2);
|
new War(argLabel, town1, nation2, event);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +224,7 @@ public class WarCommands {
|
|||||||
final boolean canKingJoin = (res.hasNation() && res.getNationOrNull().equals(nation) && res.isKing() && nation.isKing(res));
|
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));
|
final boolean canMayorJoin = (res.hasTown() && res.getTownOrNull().equals(town) && res.isMayor() && town.isMayor(res));
|
||||||
|
|
||||||
|
if (!war.isEvent()) {
|
||||||
// Join nation into war
|
// Join nation into war
|
||||||
if (isNation && nation != null && !war.isNationInWar(nation) && (asAdmin || canKingJoin)) {
|
if (isNation && nation != null && !war.isNationInWar(nation) && (asAdmin || canKingJoin)) {
|
||||||
side.addNation(nation);
|
side.addNation(nation);
|
||||||
@@ -274,6 +290,7 @@ public class WarCommands {
|
|||||||
} else if (targetPlayer == null && town != null && !canMayorJoin) {
|
} else if (targetPlayer == null && town != null && !canMayorJoin) {
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Town is already in that war.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Town is already in that war.").build());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Join player into war
|
// Join player into war
|
||||||
if (isPlayer && targetPlayer != null && !war.isPlayerInWar(targetPlayer) && asAdmin) {
|
if (isPlayer && targetPlayer != null && !war.isPlayerInWar(targetPlayer) && asAdmin) {
|
||||||
@@ -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() + "<red>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("<gradient:#D72A09:#B01F03><u><b>War")
|
||||||
|
.build(),
|
||||||
|
ColorParser.of("<gray><i>You entered the war of <war>!")
|
||||||
|
.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 {
|
protected static void warSurrender(@NotNull Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException {
|
||||||
War war = (War) args.get("war");
|
War war = (War) args.get("war");
|
||||||
if (war == null) return;
|
if (war == null) return;
|
||||||
|
|||||||
@@ -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 name; // Used in commands and such, like "TidalHaven.vs.Meme"
|
||||||
private final String label;
|
private final String label;
|
||||||
private final ConflictType conflictType = ConflictType.WAR;
|
private final ConflictType conflictType = ConflictType.WAR;
|
||||||
|
private boolean event = false;
|
||||||
|
|
||||||
private final @NotNull Side side1;
|
private final @NotNull Side side1;
|
||||||
private final Side side2;
|
private final Side side2;
|
||||||
@@ -54,7 +55,8 @@ public class War extends Conflict {
|
|||||||
@NotNull Side side1,
|
@NotNull Side side1,
|
||||||
Side side2,
|
Side side2,
|
||||||
Set<Siege> sieges,
|
Set<Siege> sieges,
|
||||||
Set<Raid> raids
|
Set<Raid> raids,
|
||||||
|
boolean event
|
||||||
) {
|
) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -68,6 +70,7 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
this.sieges = sieges;
|
this.sieges = sieges;
|
||||||
this.raids = raids;
|
this.raids = raids;
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
@@ -79,7 +82,7 @@ public class War extends Conflict {
|
|||||||
* @param aggressor the side 1
|
* @param aggressor the side 1
|
||||||
* @param victim the side 2
|
* @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.uuid = UUIDUtil.generateWarUUID();
|
||||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@@ -94,13 +97,14 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
WarManager.getInstance().addWar(this);
|
WarManager.getInstance().addWar(this);
|
||||||
|
|
||||||
start();
|
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.uuid = UUIDUtil.generateWarUUID();
|
||||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@@ -115,13 +119,14 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
WarManager.getInstance().addWar(this);
|
WarManager.getInstance().addWar(this);
|
||||||
|
|
||||||
start();
|
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.uuid = UUIDUtil.generateWarUUID();
|
||||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@@ -136,13 +141,14 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
WarManager.getInstance().addWar(this);
|
WarManager.getInstance().addWar(this);
|
||||||
|
|
||||||
start();
|
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.uuid = UUIDUtil.generateWarUUID();
|
||||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@@ -157,6 +163,7 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
WarManager.getInstance().addWar(this);
|
WarManager.getInstance().addWar(this);
|
||||||
|
|
||||||
@@ -635,4 +642,12 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEvent(boolean event) {
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEvent() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,7 @@ public class Siege extends Battle {
|
|||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
siegeRunnable = new SiegeRunnable(this);
|
siegeRunnable = new SiegeRunnable(this);
|
||||||
|
if (!war.isEvent())
|
||||||
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.Times times = Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(3500), Duration.ofMillis(500));
|
||||||
@@ -165,6 +166,7 @@ public class Siege extends Battle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void attackersWin() {
|
public void attackersWin() {
|
||||||
|
if (!war.isEvent()) {
|
||||||
Main.econ.depositPlayer(siegeLeader, SIEGE_VICTORY_MONEY);
|
Main.econ.depositPlayer(siegeLeader, SIEGE_VICTORY_MONEY);
|
||||||
double amt;
|
double amt;
|
||||||
|
|
||||||
@@ -177,6 +179,7 @@ public class Siege extends Battle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Main.econ.depositPlayer(siegeLeader, amt);
|
Main.econ.depositPlayer(siegeLeader, amt);
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.broadcast(ColorParser.of("<prefix>The town of <town> has been sacked and placed under occupation by the armies of <attacker>!")
|
Bukkit.broadcast(ColorParser.of("<prefix>The town of <town> has been sacked and placed under occupation by the armies of <attacker>!")
|
||||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
@@ -219,6 +222,7 @@ public class Siege extends Battle {
|
|||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
if (!war.isEvent()) {
|
||||||
Side townSide = getWar().getTownSide(town);
|
Side townSide = getWar().getTownSide(town);
|
||||||
Side attackerSide = getAttackerSide();
|
Side attackerSide = getAttackerSide();
|
||||||
|
|
||||||
@@ -230,8 +234,10 @@ public class Siege extends Battle {
|
|||||||
war.surrenderTown(town);
|
war.surrenderTown(town);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void defendersWin() {
|
public void defendersWin() {
|
||||||
|
if (!war.isEvent())
|
||||||
town.getAccount().deposit(SIEGE_VICTORY_MONEY, "Siege Victory");
|
town.getAccount().deposit(SIEGE_VICTORY_MONEY, "Siege Victory");
|
||||||
|
|
||||||
Bukkit.broadcast(
|
Bukkit.broadcast(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.github.alathra.AlathranWars.data;
|
package com.github.alathra.AlathranWars.data;
|
||||||
|
|
||||||
import com.github.alathra.AlathranWars.Main;
|
import com.github.alathra.AlathranWars.Main;
|
||||||
import de.leonhard.storage.Config;
|
import com.github.milkdrinkers.Crate.Config;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final Main instance;
|
private final Main instance;
|
||||||
|
|||||||
+38
@@ -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.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.utility.Utils;
|
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 com.ranull.graves.event.GraveCreateEvent;
|
||||||
import io.github.thatsmusic99.headsplus.api.events.PlayerHeadDropEvent;
|
import io.github.thatsmusic99.headsplus.api.events.PlayerHeadDropEvent;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -34,6 +37,39 @@ public class PlayerDeathListener implements Listener {
|
|||||||
e.setCancelled(true);
|
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
|
@EventHandler
|
||||||
private void onPlayerDeath(PlayerDeathEvent e) {
|
private void onPlayerDeath(PlayerDeathEvent e) {
|
||||||
Player victim = e.getPlayer();
|
Player victim = e.getPlayer();
|
||||||
@@ -82,6 +118,7 @@ public class PlayerDeathListener implements Listener {
|
|||||||
e.setKeepInventory(true);
|
e.setKeepInventory(true);
|
||||||
e.getDrops().clear();
|
e.getDrops().clear();
|
||||||
e.setKeepLevel(true);
|
e.setKeepLevel(true);
|
||||||
|
e.setDroppedExp(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,5 +132,6 @@ public class PlayerDeathListener implements Listener {
|
|||||||
e.setKeepInventory(true);
|
e.setKeepInventory(true);
|
||||||
e.getDrops().clear();
|
e.getDrops().clear();
|
||||||
e.setKeepLevel(true);
|
e.setKeepLevel(true);
|
||||||
|
e.setDroppedExp(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* Convenience class for accessing {@link com.github.alathra.AlathranWars.data.ConfigManager}
|
* Convenience class for accessing {@link com.github.alathra.AlathranWars.data.ConfigManager}
|
||||||
*/
|
*/
|
||||||
public abstract class Config {
|
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();
|
return Main.getInstance().getConfigManager().getConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,6 +144,10 @@ public abstract class SQLQueries {
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
) 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();
|
statement.executeLargeBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -153,8 +157,8 @@ public abstract class SQLQueries {
|
|||||||
public static void saveAll() {
|
public static void saveAll() {
|
||||||
try (
|
try (
|
||||||
@NotNull Connection con = DB.get();
|
@NotNull Connection con = DB.get();
|
||||||
PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) "
|
PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`, `event`) VALUES (?, ?, ?, ?, ?, ?) "
|
||||||
+ "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?")
|
+ "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?, `event` = ?")
|
||||||
) {
|
) {
|
||||||
// Save wars
|
// Save wars
|
||||||
for (@NotNull War war : WarManager.getInstance().getWars()) {
|
for (@NotNull War war : WarManager.getInstance().getWars()) {
|
||||||
@@ -164,12 +168,14 @@ public abstract class SQLQueries {
|
|||||||
warStatement.setString(3, war.getLabel());
|
warStatement.setString(3, war.getLabel());
|
||||||
warStatement.setString(4, war.getSide1().getUUID().toString());
|
warStatement.setString(4, war.getSide1().getUUID().toString());
|
||||||
warStatement.setString(5, war.getSide2().getUUID().toString());
|
warStatement.setString(5, war.getSide2().getUUID().toString());
|
||||||
|
warStatement.setBoolean(6, war.isEvent());
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
warStatement.setString(6, war.getName());
|
warStatement.setString(7, war.getName());
|
||||||
warStatement.setString(7, war.getLabel());
|
warStatement.setString(8, war.getLabel());
|
||||||
warStatement.setString(8, war.getSide1().getUUID().toString());
|
warStatement.setString(9, war.getSide1().getUUID().toString());
|
||||||
warStatement.setString(9, war.getSide2().getUUID().toString());
|
warStatement.setString(10, war.getSide2().getUUID().toString());
|
||||||
|
warStatement.setBoolean(11, war.isEvent());
|
||||||
|
|
||||||
warStatement.executeUpdate();
|
warStatement.executeUpdate();
|
||||||
|
|
||||||
@@ -336,6 +342,7 @@ public abstract class SQLQueries {
|
|||||||
@NotNull UUID side2UUID = UUID.fromString(warsResult.getString("side2"));
|
@NotNull UUID side2UUID = UUID.fromString(warsResult.getString("side2"));
|
||||||
@NotNull Side side1 = loadSide(con, uuid, side1UUID);
|
@NotNull Side side1 = loadSide(con, uuid, side1UUID);
|
||||||
@NotNull Side side2 = loadSide(con, uuid, side2UUID);
|
@NotNull Side side2 = loadSide(con, uuid, side2UUID);
|
||||||
|
boolean event = warsResult.getBoolean("event");
|
||||||
|
|
||||||
wars.add(new War(
|
wars.add(new War(
|
||||||
uuid,
|
uuid,
|
||||||
@@ -344,7 +351,8 @@ public abstract class SQLQueries {
|
|||||||
side1,
|
side1,
|
||||||
side2,
|
side2,
|
||||||
new HashSet<>(),
|
new HashSet<>(),
|
||||||
new HashSet<>()
|
new HashSet<>(),
|
||||||
|
event
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user