mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 14:38:56 +00:00
refactor: wip update 9
This commit is contained in:
41 files changed
+1104
-803
No files matched your search
+13
-8
@@ -7,7 +7,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.github.alathra.AlathranWars"
|
group = "com.github.alathra.AlathranWars"
|
||||||
version = "3.0.2-SNAPSHOT"
|
version = "3.0.0-SNAPSHOT-2"
|
||||||
description = ""
|
description = ""
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -29,6 +29,7 @@ repositories {
|
|||||||
includeGroup("com.github.milkdrinkers")
|
includeGroup("com.github.milkdrinkers")
|
||||||
includeGroup("com.github.MilkBowl")
|
includeGroup("com.github.MilkBowl")
|
||||||
includeGroup("com.palmergames.bukkit.towny")
|
includeGroup("com.palmergames.bukkit.towny")
|
||||||
|
includeGroup("com.github.Gecolay.GSit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.jetbrains:annotations:24.0.1")
|
compileOnly("org.jetbrains:annotations:24.0.1")
|
||||||
|
|
||||||
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
|
||||||
implementation("space.arim.morepaperlib:morepaperlib:0.4.3")
|
implementation("space.arim.morepaperlib:morepaperlib:0.4.3")
|
||||||
@@ -55,11 +56,13 @@ dependencies {
|
|||||||
implementation("com.github.milkdrinkers:colorparser:2.0.0") {
|
implementation("com.github.milkdrinkers:colorparser:2.0.0") {
|
||||||
exclude(group = "net.kyori", module = "adventure-api")
|
exclude(group = "net.kyori", module = "adventure-api")
|
||||||
}
|
}
|
||||||
implementation("io.github.skytasul:guardianbeam:2.3.3")
|
implementation("io.github.skytasul:guardianbeam:2.3.3") {
|
||||||
|
isTransitive = false
|
||||||
|
}
|
||||||
|
|
||||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
|
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
|
||||||
|
|
||||||
compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.5") {
|
compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.7") {
|
||||||
exclude(group = "com.palmergames", module = "adventure")
|
exclude(group = "com.palmergames", module = "adventure")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +75,15 @@ dependencies {
|
|||||||
annotationProcessor("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") {
|
||||||
|
isTransitive = false
|
||||||
|
}
|
||||||
|
|
||||||
compileOnly("me.clip:placeholderapi:2.11.3") {
|
compileOnly("me.clip:placeholderapi:2.11.3") {
|
||||||
exclude(group = "me.clip.placeholderapi.libs", module = "kyori")
|
exclude(group = "me.clip.placeholderapi.libs", module = "kyori")
|
||||||
}
|
}
|
||||||
|
compileOnly(files("lib/Graves-4.9.jar"))
|
||||||
|
compileOnly("com.github.Gecolay.GSit:core:1.4.9")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -109,10 +116,8 @@ tasks {
|
|||||||
reloc("de.leonhard.storage", "storageapi")
|
reloc("de.leonhard.storage", "storageapi")
|
||||||
reloc("dev.jorel.commandapi", "commandapi")
|
reloc("dev.jorel.commandapi", "commandapi")
|
||||||
reloc("com.zaxxer.hikari", "hikaricp")
|
reloc("com.zaxxer.hikari", "hikaricp")
|
||||||
// reloc("org.xerial", "sqlite")
|
|
||||||
// reloc("com.mysql", "mysql")
|
|
||||||
reloc("org.mariadb.jdbc", "mariadb")
|
reloc("org.mariadb.jdbc", "mariadb")
|
||||||
reloc("io.github.skytasul", "guardianbeam")
|
reloc("fr.skytasul.guardianbeam", "guardianbeam")
|
||||||
}
|
}
|
||||||
|
|
||||||
runServer {
|
runServer {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.github.alathra.AlathranWars;
|
|||||||
import com.github.alathra.AlathranWars.commands.CommandManager;
|
import com.github.alathra.AlathranWars.commands.CommandManager;
|
||||||
import com.github.alathra.AlathranWars.data.ConfigManager;
|
import com.github.alathra.AlathranWars.data.ConfigManager;
|
||||||
import com.github.alathra.AlathranWars.data.DataManager;
|
import com.github.alathra.AlathranWars.data.DataManager;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.hooks.HookManager;
|
import com.github.alathra.AlathranWars.hooks.HookManager;
|
||||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||||
import com.github.alathra.AlathranWars.listeners.ListenerHandler;
|
import com.github.alathra.AlathranWars.listeners.ListenerHandler;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.github.alathra.AlathranWars.conflict.War;
|
|||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
|
import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
|
||||||
import com.github.alathra.AlathranWars.enums.CommandArgsWar;
|
import com.github.alathra.AlathranWars.enums.CommandArgsWar;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.hooks.TownyHook;
|
import com.github.alathra.AlathranWars.hooks.TownyHook;
|
||||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
@@ -35,8 +35,6 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.github.alathra.AlathranWars.enums.CommandArgsSiege.*;
|
|
||||||
|
|
||||||
public class CommandUtil {
|
public class CommandUtil {
|
||||||
/*public Argument<World> customWorldArgument(String nodeName) {
|
/*public Argument<World> customWorldArgument(String nodeName) {
|
||||||
|
|
||||||
@@ -580,6 +578,58 @@ public class CommandUtil {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Argument<String> warTargetCreateArgument(final String nodeName, final String warNodeName, final boolean isAdmin) {
|
||||||
|
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||||
|
final String argTargetName = info.input();
|
||||||
|
|
||||||
|
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||||
|
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").parseLegacy().build());
|
||||||
|
|
||||||
|
final boolean isNation = TownyAPI.getInstance().getNation(argTargetName) != null;
|
||||||
|
final boolean isTown = TownyAPI.getInstance().getTown(argTargetName) != null;
|
||||||
|
final boolean isPlayer = Bukkit.getPlayer(argTargetName) != null;
|
||||||
|
|
||||||
|
if (isNation && !war.getNations().stream().map(Nation::getName).toList().contains(argTargetName))
|
||||||
|
return argTargetName;
|
||||||
|
|
||||||
|
if (isTown && !war.getTowns().stream().map(Town::getName).toList().contains(argTargetName))
|
||||||
|
return argTargetName;
|
||||||
|
|
||||||
|
if (isPlayer && !war.getPlayers().stream().map(Player::getName).toList().contains(argTargetName))
|
||||||
|
return argTargetName;
|
||||||
|
|
||||||
|
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Invalid target.").build());
|
||||||
|
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> { // Returns list of every nation, town and player not in the war
|
||||||
|
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||||
|
return Collections.emptyList();
|
||||||
|
|
||||||
|
// Get all participants in war into list
|
||||||
|
final List<String> inWar = Stream.concat(
|
||||||
|
war.getPlayers().stream().map(Player::getName),
|
||||||
|
Stream.concat(
|
||||||
|
war.getNations().stream().map(Nation::getName),
|
||||||
|
war.getTowns().stream().map(Town::getName)
|
||||||
|
)
|
||||||
|
).toList();
|
||||||
|
|
||||||
|
// Make list of all nations, towns and player
|
||||||
|
final List<String> players = Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
|
||||||
|
final List<String> towns = TownyAPI.getInstance().getTowns().stream().map(Town::getName).toList();
|
||||||
|
final List<String> nations = TownyAPI.getInstance().getNations().stream().map(Nation::getName).toList();
|
||||||
|
|
||||||
|
return Stream.concat(
|
||||||
|
nations.stream(),
|
||||||
|
Stream.concat(
|
||||||
|
towns.stream(),
|
||||||
|
players.stream()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.filter(string -> !inWar.contains(string)) // Remove participants in te war
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player player to check
|
* @param player player to check
|
||||||
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
|
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package com.github.alathra.AlathranWars.commands;
|
package com.github.alathra.AlathranWars.commands;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.Main;
|
||||||
import com.github.alathra.AlathranWars.conflict.Side;
|
import com.github.alathra.AlathranWars.conflict.Side;
|
||||||
import com.github.alathra.AlathranWars.conflict.War;
|
import com.github.alathra.AlathranWars.conflict.War;
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
@@ -15,6 +16,7 @@ import dev.jorel.commandapi.arguments.PlayerArgument;
|
|||||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||||
import dev.jorel.commandapi.executors.CommandArguments;
|
import dev.jorel.commandapi.executors.CommandArguments;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
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;
|
||||||
@@ -48,7 +50,7 @@ public class SiegeCommands {
|
|||||||
|
|
||||||
public static CommandAPICommand commandStart(boolean asAdmin) {
|
public static CommandAPICommand commandStart(boolean asAdmin) {
|
||||||
return new CommandAPICommand("start")
|
return new CommandAPICommand("start")
|
||||||
.withPermission("AlathranWars.admin")
|
// .withPermission("AlathranWars.admin")
|
||||||
.withArguments(
|
.withArguments(
|
||||||
CommandUtil.warWarArgument(
|
CommandUtil.warWarArgument(
|
||||||
"war",
|
"war",
|
||||||
@@ -104,40 +106,69 @@ public class SiegeCommands {
|
|||||||
|
|
||||||
protected static void siegeStart(@NotNull Player sender, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException {
|
protected static void siegeStart(@NotNull Player sender, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException {
|
||||||
if (!(args.get("war") instanceof final @NotNull War war))
|
if (!(args.get("war") instanceof final @NotNull War war))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to specify a war.").build());
|
||||||
|
|
||||||
if (!(args.get("town") instanceof final @NotNull Town town))
|
if (!(args.get("town") instanceof final @NotNull Town town))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to specify a town.").build());
|
||||||
|
|
||||||
final @NotNull Player siegeLeader = (Player) args.getOptional("leader").orElse(sender);
|
final @NotNull Player siegeLeader = (Player) args.getOptional("leader").orElse(sender);
|
||||||
|
|
||||||
if (siegeLeader == null)
|
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You need to pick a valid leader.").build());
|
|
||||||
|
|
||||||
// Player participance check
|
// Player participance check
|
||||||
// @Nullable Town leaderTown = TownyAPI.getInstance().getResident(siegeLeader).getTownOrNull();
|
|
||||||
// @Nullable Side side = war.getTownSide(leaderTown);
|
|
||||||
@Nullable Side side = war.getPlayerSide(siegeLeader);
|
@Nullable Side side = war.getPlayerSide(siegeLeader);
|
||||||
if (side == null)
|
if (side == null)
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You are not in this war.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in this war.").build());
|
||||||
|
|
||||||
if (side.isPlayerSurrendered(siegeLeader))
|
if (side.isPlayerSurrendered(siegeLeader))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You have surrendered and cannot participate in this war.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You have surrendered and cannot participate in this war.").build());
|
||||||
|
|
||||||
|
if (side.isSiegeGraceActive() && !asAdmin)
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(
|
||||||
|
ColorParser.of("<red>Your side needs to wait <time> minutes before starting another siege.")
|
||||||
|
.parseMinimessagePlaceholder("time", String.valueOf(side.getSiegeGraceCooldown().toMinutes()))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
// Attacking own side
|
// Attacking own side
|
||||||
if (side.isTownOnSide(town)) {
|
if (side.isTownOnSide(town) && !side.isTownSurrendered(town)) {
|
||||||
if (asAdmin)
|
if (asAdmin)
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own side.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot attack your own side.").build());
|
||||||
else
|
else
|
||||||
siegeLeader.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
siegeLeader.sendMessage(ColorParser.of("<red>You cannot attack your own towns.").build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Location location = siegeLeader.getLocation();
|
||||||
|
final Location townLocation = town.getSpawnOrNull();
|
||||||
|
if (townLocation == null)
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>The town you are attacking doesn't have a spawn point set. Contact admin.").build());
|
||||||
|
|
||||||
|
if (!location.getWorld().equals(townLocation.getWorld()))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to be in the same world as the town you're attacking!").build());
|
||||||
|
|
||||||
|
if (location.distance(townLocation) >= Siege.BATTLEFIELD_START_MAX_RANGE)
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to be within <range> blocks of the town to start a siege!").parseMinimessagePlaceholder("range", String.valueOf(Siege.BATTLEFIELD_START_MAX_RANGE)).build());
|
||||||
|
|
||||||
|
if (location.distance(townLocation) <= Siege.BATTLEFIELD_START_MIN_RANGE)
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to be further than <range> blocks away from the town to start a siege!").parseMinimessagePlaceholder("range", String.valueOf(Siege.BATTLEFIELD_START_MIN_RANGE)).build());
|
||||||
|
|
||||||
|
if ((Main.econ.getBalance(siegeLeader) < Siege.SIEGE_VICTORY_MONEY))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to have $<amount> to start a siege!").parseMinimessagePlaceholder("amount", String.valueOf(Siege.SIEGE_VICTORY_MONEY)).build());
|
||||||
|
|
||||||
|
|
||||||
|
side.setSiegeGrace();
|
||||||
Siege siege = new Siege(war, town, siegeLeader);
|
Siege siege = new Siege(war, town, siegeLeader);
|
||||||
|
|
||||||
war.addSiege(siege);
|
war.addSiege(siege);
|
||||||
|
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
|
Bukkit.broadcast(
|
||||||
|
ColorParser.of(
|
||||||
|
"<prefix>The town of <town> has been put to siege by <side>!"
|
||||||
|
)
|
||||||
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
|
.parseMinimessagePlaceholder("town", town.getName())
|
||||||
|
.parseMinimessagePlaceholder("side", siege.getAttackerSide().getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
siege.start();
|
siege.start();
|
||||||
}
|
}
|
||||||
@@ -179,7 +210,7 @@ public class SiegeCommands {
|
|||||||
final boolean canKingSurrender = (res.hasNation() && town.hasNation() && res.getNationOrNull().equals(town.getNationOrNull()) && res.isKing());
|
final boolean canKingSurrender = (res.hasNation() && town.hasNation() && res.getNationOrNull().equals(town.getNationOrNull()) && res.isKing());
|
||||||
final boolean canMayorSurrender = (res.hasTown() && res.getTownOrNull().equals(town) && res.isMayor());
|
final boolean canMayorSurrender = (res.hasTown() && res.getTownOrNull().equals(town) && res.isMayor());
|
||||||
|
|
||||||
if (!asAdmin && (!canKingSurrender || !canMayorSurrender))
|
if (!asAdmin && !canKingSurrender && !canMayorSurrender)
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender this town.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender this town.").build());
|
||||||
|
|
||||||
Bukkit.broadcast(
|
Bukkit.broadcast(
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package com.github.alathra.AlathranWars.commands;
|
|||||||
|
|
||||||
import com.github.alathra.AlathranWars.conflict.Side;
|
import com.github.alathra.AlathranWars.conflict.Side;
|
||||||
import com.github.alathra.AlathranWars.conflict.War;
|
import com.github.alathra.AlathranWars.conflict.War;
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
|
||||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
@@ -82,9 +80,12 @@ public class WarCommands {
|
|||||||
.withArguments(
|
.withArguments(
|
||||||
CommandUtil.warWarArgument("war", asAdmin, asAdmin ? ALL_WARS : OUT_WAR, ""),
|
CommandUtil.warWarArgument("war", asAdmin, asAdmin ? ALL_WARS : OUT_WAR, ""),
|
||||||
CommandUtil.warSideCreateArgument("side", "war", asAdmin, !asAdmin, ""),
|
CommandUtil.warSideCreateArgument("side", "war", asAdmin, !asAdmin, ""),
|
||||||
new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin.join")
|
CommandUtil.warTargetCreateArgument("target", "war", asAdmin).setOptional(!asAdmin)
|
||||||
|
// new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin.join"),
|
||||||
|
// new PlayerArgument("nation").setOptional(true).withPermission("AlathranWars.admin.join"),
|
||||||
|
// new PlayerArgument("town").setOptional(true).withPermission("AlathranWars.admin.join")
|
||||||
)
|
)
|
||||||
.executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false));
|
.executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandAPICommand commandSurrender(boolean asAdmin) {
|
public static CommandAPICommand commandSurrender(boolean asAdmin) {
|
||||||
@@ -169,29 +170,103 @@ public class WarCommands {
|
|||||||
war.draw();
|
war.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void warJoinPlayer(Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException {
|
protected static void warJoin(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;
|
||||||
|
|
||||||
if (!(args.get("side") instanceof final @NotNull Side side))
|
if (!(args.get("side") instanceof final Side side))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||||
|
|
||||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
// The target or empty string
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
if (!(args.getOptional("target").orElse("") instanceof String targetString))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Invalid target name.").build());
|
||||||
|
|
||||||
if (war.isPlayerInWar(argPlayer))
|
// The target player or sender of the command
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
Player targetPlayer = args.getOptional("target").map(o -> Bukkit.getPlayer((String) o)).orElse(p);
|
||||||
|
|
||||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
|
// Get the player resident
|
||||||
side.addPlayer(argPlayer);
|
@Nullable Resident res = TownyAPI.getInstance().getResident(targetPlayer);
|
||||||
PlayerJoinListener.checkPlayer(argPlayer);
|
if (res == null)
|
||||||
for (@NotNull Siege siege : war.getSieges()) {
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Resident invalid.").build());
|
||||||
|
|
||||||
|
// Get nations and towns
|
||||||
|
@Nullable Nation nation = res.hasNation() ? res.getNationOrNull() : TownyAPI.getInstance().getNation(targetString);
|
||||||
|
@Nullable Town town = res.hasTown() ? res.getTownOrNull() : TownyAPI.getInstance().getTown(targetString);
|
||||||
|
|
||||||
|
final boolean isNation = nation != null;
|
||||||
|
final boolean isTown = town != null;
|
||||||
|
final boolean isPlayer = targetPlayer != null;
|
||||||
|
|
||||||
|
// If no valid targets
|
||||||
|
if ((!isNation && !isTown && !isPlayer))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid target.").build());
|
||||||
|
|
||||||
|
// Check if player can validly join or not
|
||||||
|
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(
|
||||||
|
"<prefix>The nation of <nation> joined the war of <war> on the side of <side>."
|
||||||
|
)
|
||||||
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
|
.parseMinimessagePlaceholder("nation", nation.getName())
|
||||||
|
.parseMinimessagePlaceholder("war", war.getLabel())
|
||||||
|
.parseMinimessagePlaceholder("side", side.getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (town == null && nation != null && (!canKingJoin || !asAdmin)) {
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>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(
|
||||||
|
"<prefix>The town of <town> joined the war of <war> on the side of <side>."
|
||||||
|
)
|
||||||
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
|
.parseMinimessagePlaceholder("town", town.getName())
|
||||||
|
.parseMinimessagePlaceholder("war", war.getLabel())
|
||||||
|
.parseMinimessagePlaceholder("side", side.getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (targetPlayer == null && town != null && !canMayorJoin) {
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Town is already in that war.").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join player into war
|
||||||
|
if (isPlayer && targetPlayer != null && !war.isPlayerInWar(targetPlayer) && asAdmin) {
|
||||||
|
targetPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||||
|
side.addPlayer(targetPlayer);
|
||||||
|
PlayerJoinListener.checkPlayer(targetPlayer);
|
||||||
|
return;
|
||||||
|
} else if (!asAdmin) {
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Players cannot individually join wars.").build());
|
||||||
|
} else {
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Player is already in that war.").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join player into war
|
||||||
|
// if (war.isPlayerInWar(player))
|
||||||
|
// throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are already in this war.").build());
|
||||||
|
|
||||||
|
|
||||||
|
/*for (@NotNull Siege siege : war.getSieges()) {
|
||||||
if (siege.getAttackerSide().equals(side)) {
|
if (siege.getAttackerSide().equals(side)) {
|
||||||
siege.addPlayer(argPlayer, BattleSide.ATTACKER);
|
siege.addPlayer(argPlayer, BattleSide.ATTACKER);
|
||||||
} else {
|
} else {
|
||||||
siege.addPlayer(argPlayer, BattleSide.DEFENDER);
|
siege.addPlayer(argPlayer, BattleSide.DEFENDER);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -199,7 +274,7 @@ public class WarCommands {
|
|||||||
if (war == null) return;
|
if (war == null) return;
|
||||||
|
|
||||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Player not found.").build());
|
||||||
|
|
||||||
// Towny Resident Object
|
// Towny Resident Object
|
||||||
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||||
@@ -218,29 +293,25 @@ public class WarCommands {
|
|||||||
final @Nullable Nation resNation = res.getNationOrNull();
|
final @Nullable Nation resNation = res.getNationOrNull();
|
||||||
final @Nullable Town resTown = res.getTownOrNull();
|
final @Nullable Town resTown = res.getTownOrNull();
|
||||||
|
|
||||||
// TODO Test if resTown is reached
|
if (resNation != null && (p.hasPermission("AlathranWars.nationsurrender") || res.isKing() || asAdmin)) {
|
||||||
if (resNation != null) {
|
// Has nation surrender permission
|
||||||
if (p.hasPermission("AlathranWars.nationsurrender") || res.isKing() || asAdmin) {
|
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resNation.getName() + ".").build());
|
||||||
// Has nation surrender permission
|
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The nation of " + resNation.getName() + " has surrendered!").build());
|
||||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resNation.getName() + ".").build());
|
war.surrenderNation(resNation);
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The nation of " + resNation.getName() + " has surrendered!").build());
|
} else if (resTown == null) {
|
||||||
side.surrenderNation(resNation);
|
// Cannot surrender nation involvement
|
||||||
side.processSurrenders();
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender for your nation.").build());
|
||||||
} else {
|
}
|
||||||
// Cannot surrender nation involvement
|
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender for your nation.").build());
|
if (resTown != null && (p.hasPermission("AlathranWars.townsurrender") || res.isMayor() || asAdmin)) {
|
||||||
}
|
// Is in indepdenent town & has surrender perms
|
||||||
} else if (resTown != null) {
|
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
||||||
if (p.hasPermission("AlathranWars.townsurrender") || res.isMayor() || asAdmin) {
|
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
||||||
// Is in indepdenent town & has surrender perms
|
war.cancelSieges(resTown);
|
||||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
war.surrenderTown(resTown);
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
} else {
|
||||||
side.surrenderTown(resTown); // TODO Process siege surrender here as well
|
// No perms
|
||||||
side.processSurrenders();
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender war for your town.").build());
|
||||||
} else {
|
|
||||||
// No perms
|
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.github.alathra.AlathranWars.conflict;
|
package com.github.alathra.AlathranWars.conflict;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.enums.ConflictType;
|
||||||
|
|
||||||
public class Conflict {
|
public class Conflict {
|
||||||
private ConflictType conflictType;
|
private ConflictType conflictType;
|
||||||
}
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.github.alathra.AlathranWars.conflict;
|
|
||||||
|
|
||||||
public enum ConflictType {
|
|
||||||
WAR
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.github.alathra.AlathranWars.conflict;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class Occupation {
|
||||||
|
public static boolean isOccupied(Town town) {
|
||||||
|
return town.isConquered();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeOccupied(Town town) {
|
||||||
|
if (!isOccupied(town)) return;
|
||||||
|
|
||||||
|
// final boolean hasPreviousNation = town.hasNation();
|
||||||
|
// final Nation previousNation = town.getNationOrNull();
|
||||||
|
// if (hasPreviousNation) {
|
||||||
|
// town.removeNation();
|
||||||
|
// }
|
||||||
|
|
||||||
|
town.setConquered(false);
|
||||||
|
|
||||||
|
town.save();
|
||||||
|
// if (hasPreviousNation) {
|
||||||
|
// previousNation.save();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setOccupied(Nation occupied, @Nullable Nation occupier) {
|
||||||
|
for (Town town : occupied.getTowns())
|
||||||
|
setOccupied(town, occupier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setOccupied(Town town, @Nullable Nation occupier) {
|
||||||
|
if (isOccupied(town)) return;
|
||||||
|
|
||||||
|
// Remove from current nation
|
||||||
|
final boolean hasPreviousNation = town.hasNation();
|
||||||
|
final boolean hasNewNation = occupier != null;
|
||||||
|
final Nation previousNation = town.getNationOrNull();
|
||||||
|
if (hasPreviousNation && hasNewNation && previousNation != occupier)
|
||||||
|
town.removeNation();
|
||||||
|
|
||||||
|
// Put town into occupiers nation
|
||||||
|
try {
|
||||||
|
if (hasNewNation)
|
||||||
|
town.setNation(occupier);
|
||||||
|
} catch (AlreadyRegisteredException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
town.setConquered(true);
|
||||||
|
|
||||||
|
town.save();
|
||||||
|
if (hasNewNation)
|
||||||
|
occupier.save();
|
||||||
|
|
||||||
|
if (hasPreviousNation && previousNation != occupier)
|
||||||
|
previousNation.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.github.alathra.AlathranWars.conflict;
|
package com.github.alathra.AlathranWars.conflict;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
|
||||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
@@ -21,14 +21,14 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Side {
|
public class Side {
|
||||||
private static final Duration SIEGE_COOLDOWN = Duration.ofMinutes(120);
|
private static final Duration SIEGE_COOLDOWN = Duration.ofMinutes(30);
|
||||||
private static final Duration RAID_COOLDOWN = Duration.ofMinutes(30);
|
private static final Duration RAID_COOLDOWN = Duration.ofMinutes(30);
|
||||||
private final UUID warUUID;
|
private final UUID warUUID;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final BattleSide side;
|
private final BattleSide side;
|
||||||
private final BattleTeam team;
|
private final BattleTeam team;
|
||||||
private final String name; // A town name
|
private final String name; // A town name
|
||||||
// TODO Use Town & Nation UUID's when saving to config
|
|
||||||
private final Town town; // The initiating town or capital of the nation
|
private final Town town; // The initiating town or capital of the nation
|
||||||
private final Set<Town> towns; // A list of participating Towns
|
private final Set<Town> towns; // A list of participating Towns
|
||||||
private final Set<Nation> nations; // A list of participating Nations
|
private final Set<Nation> nations; // A list of participating Nations
|
||||||
@@ -235,6 +235,26 @@ public class Side {
|
|||||||
nation.getTowns().forEach(this::surrenderTown);
|
nation.getTowns().forEach(this::surrenderTown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsurrenderTown(@NotNull Town town) {
|
||||||
|
if (!isTownSurrendered(town)) return;
|
||||||
|
|
||||||
|
addTown(town);
|
||||||
|
|
||||||
|
surrenderedTowns.remove(town);
|
||||||
|
|
||||||
|
town.getResidents().forEach((Resident resident) -> unsurrenderPlayer(resident.getUUID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsurrenderNation(@NotNull Nation nation) {
|
||||||
|
if (!isNationSurrendered(nation)) return;
|
||||||
|
|
||||||
|
addNation(nation);
|
||||||
|
|
||||||
|
surrenderedNations.remove(nation);
|
||||||
|
|
||||||
|
nation.getTowns().forEach(this::unsurrenderTown);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPlayerOnSide(@NotNull Player p) {
|
public boolean isPlayerOnSide(@NotNull Player p) {
|
||||||
return isPlayerOnSide(p.getUniqueId());
|
return isPlayerOnSide(p.getUniqueId());
|
||||||
}
|
}
|
||||||
@@ -264,6 +284,15 @@ public class Side {
|
|||||||
if (isPlayerOnSide(uuid)) return;
|
if (isPlayerOnSide(uuid)) return;
|
||||||
|
|
||||||
playersIncludingOffline.add(uuid);
|
playersIncludingOffline.add(uuid);
|
||||||
|
if (getWar() != null) { // We need to check this as on side creation War doesn't exist
|
||||||
|
for (@NotNull Siege siege : getWar().getSieges()) {
|
||||||
|
if (siege.getAttackerSide().equals(this)) {
|
||||||
|
siege.addPlayer(uuid, BattleSide.ATTACKER);
|
||||||
|
} else {
|
||||||
|
siege.addPlayer(uuid, BattleSide.DEFENDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||||
@@ -288,6 +317,15 @@ public class Side {
|
|||||||
if (!isPlayerOnSide(uuid)) return;
|
if (!isPlayerOnSide(uuid)) return;
|
||||||
|
|
||||||
playersIncludingOffline.remove(uuid);
|
playersIncludingOffline.remove(uuid);
|
||||||
|
if (getWar() != null) { // We need to check this as on side creation War doesn't exist
|
||||||
|
for (@NotNull Siege siege : getWar().getSieges()) {
|
||||||
|
if (siege.getAttackerSide().equals(this)) {
|
||||||
|
siege.removePlayer(uuid);
|
||||||
|
} else {
|
||||||
|
siege.removePlayer(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||||
@@ -311,6 +349,18 @@ public class Side {
|
|||||||
applyNameTags();
|
applyNameTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsurrenderPlayer(@NotNull Player p) {
|
||||||
|
unsurrenderPlayer(p.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsurrenderPlayer(@NotNull UUID uuid) {
|
||||||
|
if (!isPlayerSurrendered(uuid)) return;
|
||||||
|
|
||||||
|
addPlayer(uuid);
|
||||||
|
surrenderedPlayersIncludingOffline.remove(uuid);
|
||||||
|
applyNameTags();
|
||||||
|
}
|
||||||
|
|
||||||
public void calculateOnlinePlayers() {
|
public void calculateOnlinePlayers() {
|
||||||
final @NotNull Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
|
final @NotNull Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
|
||||||
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline())
|
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline())
|
||||||
@@ -335,31 +385,31 @@ public class Side {
|
|||||||
// Graces
|
// Graces
|
||||||
|
|
||||||
public Instant getSiegeGrace() {
|
public Instant getSiegeGrace() {
|
||||||
return this.siegeGrace;
|
return siegeGrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSiegeGrace() {
|
public void setSiegeGrace() {
|
||||||
this.siegeGrace = Instant.now().plus(SIEGE_COOLDOWN);
|
siegeGrace = Instant.now().plus(SIEGE_COOLDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSiegeGraceActive() {
|
public boolean isSiegeGraceActive() {
|
||||||
return this.siegeGrace.isAfter(Instant.now());
|
return siegeGrace.isAfter(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duration getSiegeGraceCooldown() {
|
public Duration getSiegeGraceCooldown() {
|
||||||
return Duration.between(Instant.now(), this.siegeGrace);
|
return Duration.between(Instant.now(), siegeGrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Instant getRaidGrace() {
|
public Instant getRaidGrace() {
|
||||||
return this.raidGrace;
|
return raidGrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRaidGrace() {
|
public void setRaidGrace() {
|
||||||
this.raidGrace = Instant.now().plus(RAID_COOLDOWN);
|
raidGrace = Instant.now().plus(RAID_COOLDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRaidGraceActive() {
|
public boolean isRaidGraceActive() {
|
||||||
return this.raidGrace.isAfter(Instant.now());
|
return raidGrace.isAfter(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duration getRaidGraceCooldown() {
|
public Duration getRaidGraceCooldown() {
|
||||||
@@ -402,8 +452,7 @@ public class Side {
|
|||||||
return this.uuid;
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Nullable
|
||||||
@SuppressWarnings({"all"})
|
|
||||||
public War getWar() {
|
public War getWar() {
|
||||||
return WarManager.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't
|
return WarManager.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't
|
||||||
}
|
}
|
||||||
@@ -414,30 +463,31 @@ public class Side {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void surrenderWar() {
|
private void surrenderWar() {
|
||||||
getWar().defeat(this);
|
War war = getWar();
|
||||||
|
if (war != null)
|
||||||
|
getWar().defeat(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldSurrender() {
|
private boolean shouldSurrender() {
|
||||||
return nations.isEmpty() && towns.isEmpty();
|
return nations.isEmpty() && towns.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldNationSurrender(Nation nation) {
|
||||||
|
final int townsQty = nation.getNumTowns();
|
||||||
|
// List<Town> towns = nation.getTowns();
|
||||||
|
|
||||||
|
final int surrenderedTownsQty = nation.getTowns().stream().filter(this::isTownSurrendered).mapToInt(value -> 1).sum();
|
||||||
|
|
||||||
|
/*int surrenderedTownsQty = 0;
|
||||||
|
for (Town town : towns) {
|
||||||
|
if (isTownSurrendered(town))
|
||||||
|
surrenderedTownsQty++;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return surrenderedTownsQty == townsQty;
|
||||||
|
}
|
||||||
|
|
||||||
public Town getTown() {
|
public Town getTown() {
|
||||||
return town;
|
return town;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Make object serializable
|
|
||||||
/*private void writeObject(ObjectOutputStream oos)
|
|
||||||
throws IOException {
|
|
||||||
oos.defaultWriteObject();
|
|
||||||
oos.writeObject(address.getHouseNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readObject(ObjectInputStream ois)
|
|
||||||
throws ClassNotFoundException, IOException {
|
|
||||||
ois.defaultReadObject();
|
|
||||||
Integer houseNumber = (Integer) ois.readObject();
|
|
||||||
Address a = new Address();
|
|
||||||
a.setHouseNumber(houseNumber);
|
|
||||||
this.setAddress(a);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
|
|||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.enums.ConflictType;
|
||||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||||
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
||||||
@@ -431,6 +431,76 @@ public class War extends Conflict {
|
|||||||
return getSide1().equals(sideName) || getSide2().equals(sideName);
|
return getSide1().equals(sideName) || getSide2().equals(sideName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelSieges() {
|
||||||
|
getTowns().forEach(this::cancelSieges);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelSieges(Town town) {
|
||||||
|
if (this != null) {
|
||||||
|
Side townSide = getTownSide(town);
|
||||||
|
|
||||||
|
if (townSide == null) return;
|
||||||
|
|
||||||
|
getSieges().forEach(siege -> { // TODO INFINITE LOOP, runs surrenderTown
|
||||||
|
if (siege.getTown().equals(town)) {
|
||||||
|
if (siege.getAttackerSide().equals(townSide)) {
|
||||||
|
siege.defendersWin();
|
||||||
|
} else {
|
||||||
|
siege.attackersWin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void surrenderNation(Nation nation) {
|
||||||
|
Side nationSide = getNationSide(nation);
|
||||||
|
if (nationSide == null) return;
|
||||||
|
|
||||||
|
final @Nullable Nation occupier = nationSide.equals(getSide1()) ? getSide2().getTown().getNationOrNull() : getSide1().getTown().getNationOrNull();
|
||||||
|
Occupation.setOccupied(nation, occupier);
|
||||||
|
|
||||||
|
nationSide.surrenderNation(nation);
|
||||||
|
// TODO Cancel in progress sieges for towns?
|
||||||
|
nationSide.processSurrenders();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void surrenderTown(Town town) {
|
||||||
|
Side townSide = getTownSide(town);
|
||||||
|
if (townSide == null) return;
|
||||||
|
|
||||||
|
final @Nullable Nation townNation = town.getNationOrNull();
|
||||||
|
final @Nullable Nation occupier = townSide.equals(getSide1()) ? getSide2().getTown().getNationOrNull() : getSide1().getTown().getNationOrNull();
|
||||||
|
Occupation.setOccupied(town, occupier);
|
||||||
|
townSide.surrenderTown(town);
|
||||||
|
|
||||||
|
if (townNation != null) {
|
||||||
|
if (townSide.shouldNationSurrender(townNation)) {
|
||||||
|
surrenderNation(townNation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Cancel in progress sieges for towns?
|
||||||
|
townSide.processSurrenders();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsurrenderNation(Nation nation) {
|
||||||
|
Side nationSide = getNationSide(nation);
|
||||||
|
if (nationSide == null) return;
|
||||||
|
|
||||||
|
nationSide.unsurrenderNation(nation);
|
||||||
|
nation.getTowns().forEach(this::unsurrenderTown);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsurrenderTown(Town town) {
|
||||||
|
Side townSide = getTownSide(town);
|
||||||
|
if (townSide == null) return;
|
||||||
|
|
||||||
|
Occupation.removeOccupied(town);
|
||||||
|
|
||||||
|
townSide.unsurrenderTown(town);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Town> getTowns() {
|
public Set<Town> getTowns() {
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
@@ -440,6 +510,18 @@ public class War extends Conflict {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Set<Town> getAllTowns() {
|
||||||
|
return Stream.concat(
|
||||||
|
getSide1().getTowns().stream(),
|
||||||
|
Stream.concat(
|
||||||
|
getSide2().getTowns().stream(),
|
||||||
|
getSurrenderedTowns().stream()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Nation> getNations() {
|
public Set<Nation> getNations() {
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
@@ -449,6 +531,18 @@ public class War extends Conflict {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Set<Nation> getAllNations() {
|
||||||
|
return Stream.concat(
|
||||||
|
getSide1().getNations().stream(),
|
||||||
|
Stream.concat(
|
||||||
|
getSide2().getNations().stream(),
|
||||||
|
getSurrenderedNations().stream()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Town> getSurrenderedTowns() {
|
public Set<Town> getSurrenderedTowns() {
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
@@ -485,15 +579,14 @@ public class War extends Conflict {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void end() {
|
public void end() {
|
||||||
// TODO Stop battles
|
|
||||||
getSieges().forEach(Siege::stop);
|
getSieges().forEach(Siege::stop);
|
||||||
// getRaids().forEach(Raid::stop);
|
getAllTowns().forEach(Occupation::removeOccupied);
|
||||||
|
|
||||||
SQLQueries.deleteWar(this);
|
SQLQueries.deleteWar(this);
|
||||||
WarManager.getInstance().removeWar(this);
|
WarManager.getInstance().removeWar(this);
|
||||||
|
|
||||||
// Run check after war is removed to cleanup player tags
|
// Run check after war is removed to cleanup player tags
|
||||||
this.getPlayers().forEach(PlayerJoinListener::checkPlayer);
|
getPlayers().forEach(PlayerJoinListener::checkPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void defeat(@NotNull Side loserSide) {
|
public void defeat(@NotNull Side loserSide) {
|
||||||
|
|||||||
+23
-13
@@ -1,7 +1,5 @@
|
|||||||
package com.github.alathra.AlathranWars.holder;
|
package com.github.alathra.AlathranWars.conflict;
|
||||||
|
|
||||||
import com.github.alathra.AlathranWars.conflict.Side;
|
|
||||||
import com.github.alathra.AlathranWars.conflict.War;
|
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
|
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||||
@@ -148,20 +146,18 @@ public class WarManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Siege> getSieges() {
|
public Set<Siege> getSieges() {
|
||||||
final @NotNull Set<Siege> sieges = new HashSet<>();
|
return getWars().stream()
|
||||||
|
.map(War::getSieges)
|
||||||
wars.forEach((War war) -> sieges.addAll(war.getSieges()));
|
.flatMap(Set::stream)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
return sieges;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Raid> getRaids() {
|
public Set<Raid> getRaids() {
|
||||||
final @NotNull Set<Raid> raids = new HashSet<>();
|
return getWars().stream()
|
||||||
|
.map(War::getRaids)
|
||||||
wars.forEach((War war) -> raids.addAll(war.getRaids()));
|
.flatMap(Set::stream)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
return raids;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerInAnySiege(@NotNull Player p) {
|
public boolean isPlayerInAnySiege(@NotNull Player p) {
|
||||||
@@ -185,4 +181,18 @@ public class WarManager {
|
|||||||
.filter(siege -> siege.isPlayerInSiege(uuid))
|
.filter(siege -> siege.isPlayerInSiege(uuid))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<Nation> getNationsAtWar() {
|
||||||
|
return getWars().stream()
|
||||||
|
.map(War::getNations)
|
||||||
|
.flatMap(Set::stream)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<Town> getTownsAtWar() {
|
||||||
|
return getWars().stream()
|
||||||
|
.map(War::getTowns)
|
||||||
|
.flatMap(Set::stream)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,11 @@ import com.github.alathra.AlathranWars.conflict.War;
|
|||||||
import com.github.alathra.AlathranWars.conflict.battle.Battle;
|
import com.github.alathra.AlathranWars.conflict.battle.Battle;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||||
|
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
|
||||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||||
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
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;
|
||||||
@@ -36,7 +34,10 @@ public class Siege extends Battle {
|
|||||||
public static final int MAX_SIEGE_PROGRESS = 60 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 1 point is added per second
|
public static final int MAX_SIEGE_PROGRESS = 60 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 1 point is added per second
|
||||||
public static final Duration ATTACKERS_MUST_TOUCH_END = Duration.ofMinutes(40); // If point is not touched in this much time, defenders win
|
public static final Duration ATTACKERS_MUST_TOUCH_END = Duration.ofMinutes(40); // If point is not touched in this much time, defenders win
|
||||||
public static final Duration ATTACKERS_MUST_TOUCH_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress begins reverting
|
public static final Duration ATTACKERS_MUST_TOUCH_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress begins reverting
|
||||||
public static final int BATTLEFIELD_RANGE = 300;
|
public static final int BATTLEFIELD_RANGE = 500;
|
||||||
|
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 @NotNull War war; // War which siege belongs to
|
||||||
private final @NotNull UUID uuid;
|
private final @NotNull UUID uuid;
|
||||||
@@ -61,6 +62,8 @@ public class Siege extends Battle {
|
|||||||
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
|
||||||
|
|
||||||
public Siege(final @NotNull War war, final Town town, Player siegeLeader) {
|
public Siege(final @NotNull War war, final Town town, Player siegeLeader) {
|
||||||
uuid = UUIDUtil.generateSiegeUUID();
|
uuid = UUIDUtil.generateSiegeUUID();
|
||||||
|
|
||||||
@@ -105,6 +108,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,77 +122,83 @@ public class Siege extends Battle {
|
|||||||
* Stops a siege
|
* Stops a siege
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
if (stopped) return;
|
||||||
|
stopped = true;
|
||||||
siegeRunnable.cancel();
|
siegeRunnable.cancel();
|
||||||
SQLQueries.deleteSiege(this);
|
SQLQueries.deleteSiege(this);
|
||||||
war.removeSiege(this);
|
war.removeSiege(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attackersWin() {
|
public void attackersWin() {
|
||||||
final @Nullable Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
Main.econ.depositPlayer(siegeLeader, SIEGE_VICTORY_MONEY);
|
||||||
// @Nullable Nation nation = null;
|
double amt;
|
||||||
// Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build());
|
|
||||||
|
|
||||||
// try {
|
if (town.getAccount().getHoldingBalance() > 10000.0) {
|
||||||
// nation = resident.getTown().getNation();
|
amt = Math.floor(town.getAccount().getHoldingBalance()) / 4.0;
|
||||||
// } catch (Exception ignored) {
|
town.getAccount().withdraw(amt, "Siege Defeat");
|
||||||
// }
|
} 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;
|
||||||
|
}*/
|
||||||
|
|
||||||
// if (nation != null) {
|
town.getAccount().withdraw(SIEGE_VICTORY_MONEY, "Siege Defeat");
|
||||||
// Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + town.getName()
|
amt = SIEGE_VICTORY_MONEY;
|
||||||
// + " has been placed under occupation by " + nation.getName() + "!").build());
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// TODO Re-enable prize
|
Main.econ.depositPlayer(siegeLeader, amt);
|
||||||
// Main.econ.depositPlayer(siegeLeader, 2500.0);
|
|
||||||
// double amt = 0.0;
|
|
||||||
// if (this.town.getAccount().getHoldingBalance() > 10000.0) {
|
|
||||||
// amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
|
|
||||||
// this.town.getAccount().withdraw(amt, "war loot");
|
|
||||||
// } else {
|
|
||||||
// if (this.town.getAccount().getHoldingBalance() < 2500.0) {
|
|
||||||
// amt = this.town.getAccount().getHoldingBalance();
|
|
||||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + this.town.getName()
|
|
||||||
// + " has been destroyed by " + this.getAttackerSide() + "!");
|
|
||||||
// TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
|
||||||
// Main.econ.depositPlayer(siegeLeader, amt);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// this.town.getAccount().withdraw(2500.0, "war loot");
|
|
||||||
// amt = 2500.0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
Bukkit.broadcast(ColorParser.of("<prefix>The town of <town> has been sacked and placed under occupation by the armies of <attacker>!")
|
||||||
+ ", valuing $" + amt);*/
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
|
.parseMinimessagePlaceholder("town", town.getName())
|
||||||
// TODO
|
.parseMinimessagePlaceholder("attacker", getAttackerSide().getName())
|
||||||
// "The town of <town> has been sacked and placed under occupation by the armies of <attacker>!"
|
.build());
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide().getName() + "!").build());
|
|
||||||
// Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
|
||||||
// + ", valuing $" + amt);
|
|
||||||
// Main.econ.depositPlayer(siegeLeader, amt);
|
|
||||||
|
|
||||||
if (side1AreAttackers) {
|
if (side1AreAttackers) {
|
||||||
war.getSide1().addScore(50);
|
war.getSide1().addScore(50);
|
||||||
|
war.getSide2().addScore(5);
|
||||||
} else {
|
} else {
|
||||||
|
war.getSide1().addScore(5);
|
||||||
war.getSide2().addScore(50);
|
war.getSide2().addScore(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void defendersWin() {
|
public void defendersWin() {
|
||||||
// this.town.getAccount().deposit(2500.0, "War chest");
|
town.getAccount().deposit(SIEGE_VICTORY_MONEY, "Siege Victory");
|
||||||
// "The siege of <town> has been lifted." TODO
|
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The defenders have won the siege of " + this.town.getName() + "!").build());
|
Bukkit.broadcast(
|
||||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.town.getName()
|
ColorParser.of("<prefix>The siege of <town> has been lifted by the defenders!")
|
||||||
// + " has recovered the attackers' war chest, valued at $2,500");
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
// Main.warLogger
|
.parseMinimessagePlaceholder("town", town.getName())
|
||||||
// .log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
if (side1AreAttackers) {
|
if (side1AreAttackers) {
|
||||||
war.getSide2().addScore(50);
|
war.getSide2().addScore(10);
|
||||||
} else {
|
} else {
|
||||||
war.getSide1().addScore(50);
|
war.getSide1().addScore(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
@@ -198,10 +208,12 @@ public class Siege extends Battle {
|
|||||||
* No winner declared
|
* No winner declared
|
||||||
*/
|
*/
|
||||||
public void noWinner() {
|
public void noWinner() {
|
||||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " has ended in a draw!").build());
|
Bukkit.broadcast(
|
||||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + "No money has been recovered.");
|
ColorParser.of("<prefix>The siege of <town> has ended in a draw!")
|
||||||
// Main.warLogger
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
// .log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
|
.parseMinimessagePlaceholder("town", town.getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +298,7 @@ public class Siege extends Battle {
|
|||||||
color = "<blue>";
|
color = "<blue>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case NONE -> activeBossBar.color(BossBar.Color.YELLOW);
|
case CONTESTED, UNCONTESTED -> activeBossBar.color(BossBar.Color.YELLOW);
|
||||||
case DOWN -> {
|
case DOWN -> {
|
||||||
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
|
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
|
||||||
activeBossBar.color(BossBar.Color.BLUE);
|
activeBossBar.color(BossBar.Color.BLUE);
|
||||||
@@ -422,7 +434,7 @@ public class Siege extends Battle {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getName() { // TODO Make better siegenames
|
public String getName() { // TODO Make better siegenames
|
||||||
return getWar().getName() + "-" + getTown();
|
return getTown().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SECTION Time management
|
// SECTION Time management
|
||||||
|
|||||||
+12
-16
@@ -2,6 +2,7 @@ package com.github.alathra.AlathranWars.conflict.battle.siege;
|
|||||||
|
|
||||||
import com.github.alathra.AlathranWars.Main;
|
import com.github.alathra.AlathranWars.Main;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
|
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
@@ -26,7 +27,7 @@ public class SiegeRunnable implements Runnable {
|
|||||||
private final @NotNull Siege siege;
|
private final @NotNull Siege siege;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
private @NotNull CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE;
|
private @NotNull CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.UNCONTESTED;
|
||||||
private Instant nextAnnouncement;
|
private Instant nextAnnouncement;
|
||||||
private ScheduledTask task;
|
private ScheduledTask task;
|
||||||
private @Nullable Laser beam;
|
private @Nullable Laser beam;
|
||||||
@@ -48,7 +49,7 @@ public class SiegeRunnable implements Runnable {
|
|||||||
|
|
||||||
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
|
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
|
||||||
|
|
||||||
siege.updateDisplayBar(CaptureProgressDirection.NONE);
|
siege.updateDisplayBar(CaptureProgressDirection.CONTESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,19 +70,15 @@ public class SiegeRunnable implements Runnable {
|
|||||||
|
|
||||||
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
|
task = Main.getPaperLib().scheduling().globalRegionalScheduler().runAtFixedRate(this, 0L, 20L);
|
||||||
|
|
||||||
siege.updateDisplayBar(CaptureProgressDirection.NONE);
|
siege.updateDisplayBar(CaptureProgressDirection.CONTESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
stopBeam();
|
stopBeam();
|
||||||
if (task.isCancelled()) return;
|
if (task.isCancelled()) return;
|
||||||
|
|
||||||
try {
|
task.cancel();
|
||||||
task.cancel();
|
siege.deleteDisplayBar();
|
||||||
siege.deleteDisplayBar();
|
|
||||||
} finally {
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,7 +103,7 @@ public class SiegeRunnable implements Runnable {
|
|||||||
|
|
||||||
// Siege is past max time or attackers haven't touched in time, defenders won
|
// Siege is past max time or attackers haven't touched in time, defenders won
|
||||||
if (
|
if (
|
||||||
!progressDirection.equals(CaptureProgressDirection.UP) &&
|
(!progressDirection.equals(CaptureProgressDirection.CONTESTED) && !progressDirection.equals(CaptureProgressDirection.UP)) &&
|
||||||
(Instant.now().isAfter(siege.getEndTime()) ||
|
(Instant.now().isAfter(siege.getEndTime()) ||
|
||||||
Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END)))
|
Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END)))
|
||||||
) {
|
) {
|
||||||
@@ -134,7 +131,7 @@ public class SiegeRunnable implements Runnable {
|
|||||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||||
.build()
|
.build()
|
||||||
));
|
));
|
||||||
case NONE -> {
|
case CONTESTED, UNCONTESTED -> {
|
||||||
/*if ()
|
/*if ()
|
||||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||||
ColorParser.of("<prefix>The home block is being contested.")
|
ColorParser.of("<prefix>The home block is being contested.")
|
||||||
@@ -155,7 +152,6 @@ public class SiegeRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Instant.now().isAfter(nextAnnouncement)) {
|
if (Instant.now().isAfter(nextAnnouncement)) {
|
||||||
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
||||||
|
|
||||||
@@ -199,21 +195,21 @@ public class SiegeRunnable implements Runnable {
|
|||||||
siege.setLastTouched(Instant.now());
|
siege.setLastTouched(Instant.now());
|
||||||
|
|
||||||
if (attackersAreOnPoint && defendersAreOnPoint) {
|
if (attackersAreOnPoint && defendersAreOnPoint) {
|
||||||
return CaptureProgressDirection.NONE;
|
return CaptureProgressDirection.CONTESTED;
|
||||||
} else if (attackersAreOnPoint && !defendersAreOnPoint) {
|
} else if (attackersAreOnPoint && !defendersAreOnPoint) {
|
||||||
if (siege.getSiegeProgress() == MAX_SIEGE_PROGRESS)
|
if (siege.getSiegeProgress() == MAX_SIEGE_PROGRESS)
|
||||||
return CaptureProgressDirection.NONE;
|
return CaptureProgressDirection.CONTESTED;
|
||||||
|
|
||||||
return CaptureProgressDirection.UP;
|
return CaptureProgressDirection.UP;
|
||||||
} else {
|
} else {
|
||||||
if (siege.getSiegeProgress() == 0)
|
if (siege.getSiegeProgress() == 0)
|
||||||
return CaptureProgressDirection.NONE;
|
return CaptureProgressDirection.UNCONTESTED;
|
||||||
|
|
||||||
// If the attackers haven't touched in a while, begin reverting progress
|
// If the attackers haven't touched in a while, begin reverting progress
|
||||||
if (Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_REVERT))) {
|
if (Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_REVERT))) {
|
||||||
return CaptureProgressDirection.DOWN;
|
return CaptureProgressDirection.DOWN;
|
||||||
} else {
|
} else {
|
||||||
return CaptureProgressDirection.NONE;
|
return CaptureProgressDirection.UNCONTESTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
private final Main instance;
|
private final Main instance;
|
||||||
private HikariConfig hikariConfig;
|
|
||||||
private HikariDataSource hikariDataSource;
|
private HikariDataSource hikariDataSource;
|
||||||
|
|
||||||
public DataManager(Main instance) {
|
public DataManager(Main instance) {
|
||||||
@@ -50,11 +49,11 @@ public class DataManager {
|
|||||||
return hikariDataSource;
|
return hikariDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openConnection() {
|
private void openConnection() {
|
||||||
if (hikariDataSource != null)
|
if (hikariDataSource != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hikariConfig = new HikariConfig();
|
HikariConfig hikariConfig = new HikariConfig();
|
||||||
|
|
||||||
final boolean mysqlEnabled = Config.get().getBoolean("mysql.enabled");
|
final boolean mysqlEnabled = Config.get().getBoolean("mysql.enabled");
|
||||||
|
|
||||||
@@ -89,39 +88,28 @@ public class DataManager {
|
|||||||
hikariConfig.setMaximumPoolSize(10);
|
hikariConfig.setMaximumPoolSize(10);
|
||||||
hikariConfig.setMinimumIdle(10);
|
hikariConfig.setMinimumIdle(10);
|
||||||
hikariConfig.setInitializationFailTimeout(-1); // We try to create tables after this anyways which will error if no connection
|
hikariConfig.setInitializationFailTimeout(-1); // We try to create tables after this anyways which will error if no connection
|
||||||
// hikariConfig.addDataSourceProperty("characterEncoding", "UTF-8");
|
|
||||||
|
|
||||||
// General optimizations (https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration)
|
|
||||||
// hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
||||||
// hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
||||||
// hikariConfig.addDataSourceProperty("useServerPrepStmts", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("useLocalSessionState", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("rewriteBatchedStatements", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("cacheServerConfiguration", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("maintainTimeStats", "false");
|
|
||||||
// hikariConfig.addDataSourceProperty("allowPublicKeyRetrieval", "true");
|
|
||||||
// hikariConfig.addDataSourceProperty("useSSL", "false");
|
|
||||||
|
|
||||||
hikariDataSource = new HikariDataSource(hikariConfig);
|
hikariDataSource = new HikariDataSource(hikariConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeDatabaseConnection() {
|
private void closeDatabaseConnection() {
|
||||||
instance.getLogger().info("Closing database connection...");
|
instance.getLogger().info("Closing database connection...");
|
||||||
|
|
||||||
if (hikariDataSource != null) {
|
if (hikariDataSource == null) {
|
||||||
if (!hikariDataSource.isClosed()) {
|
|
||||||
try {
|
|
||||||
hikariDataSource.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
instance.getLogger().severe("Error closing database connections:");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
instance.getLogger().info("Skipped closing database connection: connection is already closed.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
instance.getLogger().severe("Skipped closing database connection because the data source is null. Was there a previous error which needs to be fixed? Check your console logs!");
|
instance.getLogger().severe("Skipped closing database connection because the data source is null. Was there a previous error which needs to be fixed? Check your console logs!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hikariDataSource.isClosed()) {
|
||||||
|
instance.getLogger().info("Skipped closing database connection: connection is already closed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
hikariDataSource.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
instance.getLogger().severe("Error closing database connections:");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.github.alathra.AlathranWars.enums;
|
|
||||||
|
|
||||||
public enum AdminCommandFailEnum {
|
|
||||||
PERMISSIONS,
|
|
||||||
SYNTAX,
|
|
||||||
HELP
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,4 @@ package com.github.alathra.AlathranWars.enums;
|
|||||||
public enum BattleTeam {
|
public enum BattleTeam {
|
||||||
SIDE_1,
|
SIDE_1,
|
||||||
SIDE_2,
|
SIDE_2,
|
||||||
SURRENDERED,
|
|
||||||
NEUTRAL, // Not Participating
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
package com.github.alathra.AlathranWars.conflict.battle.siege;
|
package com.github.alathra.AlathranWars.enums;
|
||||||
|
|
||||||
public enum CaptureProgressDirection {
|
public enum CaptureProgressDirection {
|
||||||
UP,
|
UP,
|
||||||
NONE,
|
CONTESTED,
|
||||||
UNCONTESTED,
|
UNCONTESTED,
|
||||||
DOWN
|
DOWN
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.github.alathra.AlathranWars.enums;
|
||||||
|
|
||||||
|
public enum ConflictType {
|
||||||
|
WAR
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.github.alathra.AlathranWars.enums;
|
|
||||||
|
|
||||||
public enum TownWarState {
|
|
||||||
NOT_PARTICIPANT,
|
|
||||||
SURRENDERED,
|
|
||||||
SIDE1,
|
|
||||||
SIDE2,
|
|
||||||
}
|
|
||||||
@@ -48,11 +48,11 @@ public class TABHook {
|
|||||||
if (tabAPI.getTabListFormatManager() == null) return;
|
if (tabAPI.getTabListFormatManager() == null) return;
|
||||||
|
|
||||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||||
UtilsChat.color(" <red>[" + war.getSide1().getName() + "]<reset>")
|
UtilsChat.color(" &c[" + war.getSide1().getName() + "]&r")
|
||||||
);
|
);
|
||||||
|
|
||||||
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
||||||
unm.setPrefix(tabPlayer, "<red>");
|
unm.setPrefix(tabPlayer, "&c");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,10 +63,10 @@ public class TABHook {
|
|||||||
|
|
||||||
if (tabAPI.getTabListFormatManager() == null) return;
|
if (tabAPI.getTabListFormatManager() == null) return;
|
||||||
|
|
||||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, UtilsChat.color(" <blue>[") + war.getSide2().getName() + "]<reset>");
|
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, UtilsChat.color(" &9[") + war.getSide2().getName() + "]&r");
|
||||||
|
|
||||||
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
||||||
unm.setPrefix(tabPlayer, "<blue>");
|
unm.setPrefix(tabPlayer, "&9");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public class TABHook {
|
|||||||
if (tabAPI.getTabListFormatManager() == null) return;
|
if (tabAPI.getTabListFormatManager() == null) return;
|
||||||
|
|
||||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||||
UtilsChat.color(" <green>[M]<red>[") + war.getSide1() + "]<reset>");
|
UtilsChat.color(" &a[M]&c[") + war.getSide1() + "]&r");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assignSide2WarSuffixMerc(@NotNull Player p, @NotNull War war) {
|
public static void assignSide2WarSuffixMerc(@NotNull Player p, @NotNull War war) {
|
||||||
@@ -89,7 +89,7 @@ public class TABHook {
|
|||||||
if (tabAPI.getTabListFormatManager() == null) return;
|
if (tabAPI.getTabListFormatManager() == null) return;
|
||||||
|
|
||||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||||
UtilsChat.color(" <green>[M]<blue>[") + war.getSide2() + "]<reset>");
|
UtilsChat.color(" &a[M]&9[") + war.getSide2() + "]&r");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetSuffix(@NotNull Player p) {
|
public static void resetSuffix(@NotNull Player p) {
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import com.palmergames.bukkit.towny.TownyAPI;
|
|||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public class TownyHook {
|
public class TownyHook {
|
||||||
private static boolean enabled = false;
|
private static boolean enabled = false;
|
||||||
private static TownyAPI townyAPI;
|
private static TownyAPI townyAPI;
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class BlockBreakListener implements Listener {
|
|
||||||
private final static Set<Material> allowedBlocks = Set.of(
|
|
||||||
Material.TNT,
|
|
||||||
// Mortar & Cannons
|
|
||||||
Material.IRON_BLOCK,
|
|
||||||
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
|
||||||
Material.TORCH,
|
|
||||||
Material.STONE_BUTTON,
|
|
||||||
Material.BLACK_WOOL
|
|
||||||
);
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockBreak(final @NotNull BlockBreakEvent e) {
|
|
||||||
final @NotNull Block block = e.getBlock();
|
|
||||||
/*if (SiegeData.getSieges().isEmpty() *//*&& RaidData.getRaids().isEmpty()*//*) {
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (allowedBlocks.contains(block.getType())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.getPlayer().hasPermission("AlathranWars.break")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
if (siege.beaconLocations.contains(block.getLocation())) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
|
||||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
|
||||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break blocks during sieges").parseLegacy().build());
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
|
||||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
|
||||||
p.sendMessage(Helper.color("<red>You can not break blocks during raids"));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(final @NotNull BlockPlaceEvent event) {
|
|
||||||
final @NotNull Block block = event.getBlock();
|
|
||||||
/*if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
if (allowedBlocks.contains(block.getType())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull Player p = event.getPlayer();
|
|
||||||
if (p.hasPermission("AlathranWars.place")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
|
||||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
|
||||||
p.sendMessage(ColorParser.of("<red>You can not place blocks during sieges").parseLegacy().build());
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
|
||||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
|
||||||
p.sendMessage(Helper.color("<red>You can not place blocks during raids"));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners;
|
package com.github.alathra.AlathranWars.listeners;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.utility.Utils;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -10,10 +11,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public class CommandsListener implements Listener {
|
public class CommandsListener implements Listener {
|
||||||
|
|
||||||
final static String[] PREFIXES = new String[]{
|
final static String[] PREFIXES = new String[]{
|
||||||
"", "towny", "essentials", "wild", "minecraft"
|
"", "towny", "essentials", "wild", "minecraft"
|
||||||
};
|
};
|
||||||
@@ -151,86 +149,89 @@ public class CommandsListener implements Listener {
|
|||||||
/*
|
/*
|
||||||
Prevent players from teleporting during a siege
|
Prevent players from teleporting during a siege
|
||||||
*/
|
*/
|
||||||
for (@NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
//Only do this during regular phases, start and end ignored in case something breaks
|
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||||
if (siege.getEndTime().isAfter(Instant.now())) {
|
//payment check
|
||||||
//only do for active raiders and any defenders
|
if (args.length >= 2) {
|
||||||
if (siege.getAttackerPlayers().contains(p) || siege.getDefenderPlayers().contains(p)) {
|
//parse what we have, remove the starting sslash
|
||||||
//set spawn and properties
|
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||||
if (args.length >= 3) {
|
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
||||||
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
for (String cmd : PAYMENT) {
|
||||||
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
//check for each prefix
|
||||||
//payment check
|
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||||
for (String cmd : BLACKLISTED_X_LONG) {
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot withdraw money whilst in a siege!").parseLegacy().build());
|
||||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
event.setCancelled(true);
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot modify this property during a oldSiege!").parseLegacy().build());
|
return;
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Utils.isOnSiegeBattlefield(p, siege)) {
|
||||||
|
//set spawn and properties
|
||||||
|
if (args.length >= 3) {
|
||||||
|
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||||
|
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
||||||
|
//payment check
|
||||||
|
for (String cmd : BLACKLISTED_X_LONG) {
|
||||||
|
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||||
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot modify this property during a siege!").parseLegacy().build());
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//n spawn and t spawn
|
}
|
||||||
if (args.length >= 2) {
|
//n spawn and t spawn
|
||||||
//parse what we have, remove the starting sslash
|
if (args.length >= 2) {
|
||||||
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
//parse what we have, remove the starting sslash
|
||||||
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||||
//payment check
|
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
||||||
for (String cmd : PAYMENT) {
|
for (String cmd : BLACKLISTED_LONG) {
|
||||||
//check for each prefix
|
//check for each prefix
|
||||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot withdraw money whilst in a oldSiege!").parseLegacy().build());
|
//check if in spawn
|
||||||
event.setCancelled(true);
|
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||||
return;
|
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|
||||||
}
|
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
||||||
}
|
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
||||||
|
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
||||||
for (String cmd : BLACKLISTED_LONG) {
|
|
||||||
//check for each prefix
|
|
||||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
|
||||||
//check if in spawn
|
|
||||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
|
||||||
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|
|
||||||
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
|
||||||
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
|
||||||
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||||
//else
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//else
|
||||||
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//random tp commands
|
}
|
||||||
if (args.length >= 1) {
|
//random tp commands
|
||||||
//parse what we have, remove the starting slash
|
if (args.length >= 1) {
|
||||||
@NotNull String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
//parse what we have, remove the starting slash
|
||||||
for (@NotNull String prefix : PREFIXES) {
|
@NotNull String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||||
for (String cmd : BLACKLISTED_SHORT) {
|
for (@NotNull String prefix : PREFIXES) {
|
||||||
//check for each prefix
|
for (String cmd : BLACKLISTED_SHORT) {
|
||||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
//check for each prefix
|
||||||
//spawn world check
|
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
//spawn world check
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||||
event.setCancelled(true);
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,229 +0,0 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners;
|
|
||||||
|
|
||||||
import com.github.alathra.AlathranWars.utility.Utils;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public final class KillsListener implements Listener {
|
|
||||||
|
|
||||||
// public static final HashMap<UUID, OldRaid> respawnQueue = new HashMap<>();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerKilled(final @NotNull PlayerDeathEvent event) {
|
|
||||||
|
|
||||||
final @NotNull Player killed = event.getEntity();
|
|
||||||
final @Nullable Player killer = event.getEntity().getKiller();
|
|
||||||
@Nullable Town town = null;
|
|
||||||
try {
|
|
||||||
town = WorldCoord.parseWorldCoord(killed).getTownBlock().getTown();
|
|
||||||
} catch (NotRegisteredException ex2) {
|
|
||||||
ex2.printStackTrace();
|
|
||||||
}
|
|
||||||
boolean playerCloseToHomeBlockSiege = false;
|
|
||||||
boolean playerCloseToHomeBlockRaid = false;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
//OldRaid logic
|
|
||||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
|
||||||
final int homeBlockXCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
|
||||||
final int homeBlockZCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
|
||||||
// final int homeBlockXCoordGather = oldRaid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
|
||||||
// final int homeBlockZCoordGather = oldRaid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
|
|
||||||
//Carryover from sieges
|
|
||||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
|
||||||
playerCloseToHomeBlockRaid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldRaid.getDefenderPlayers().contains(killed.getName()) && ((town != null && town.equals(oldRaid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
|
||||||
//There is seperate behavior if combat hasnt started
|
|
||||||
if (oldRaid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
|
||||||
if (oldRaid.getActiveRaiders().contains(killer.getName())) {
|
|
||||||
this.raidKill(killed, event);
|
|
||||||
oldRaid.defenderKilledInCombat(event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//teleport back to raided spawn, without damaged gear
|
|
||||||
this.oocKill(killed, event);
|
|
||||||
oldRaid.defenderKilledOutofCombat(event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (oldRaid.getActiveRaiders().contains(killed.getName()) && ((town != null && town.equals(oldRaid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
|
||||||
//There is seperate behavior if combat hasnt started
|
|
||||||
if (oldRaid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
|
||||||
if (oldRaid.getDefenderPlayers().contains(killer.getName())) {
|
|
||||||
this.raidKill(killed, event);
|
|
||||||
oldRaid.raiderKilledInCombat(event);
|
|
||||||
respawnQueue.put(killed.getUniqueId(), oldRaid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (oldRaid.getPhase() != RaidPhase.COMBAT && killer != null) {
|
|
||||||
this.oocKill(killed, event);
|
|
||||||
oldRaid.raiderKilledOutofCombat(event);
|
|
||||||
respawnQueue.put(killed.getUniqueId(), oldRaid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//teleport back to gather town spawn, without damaged gear
|
|
||||||
//this is to disincentive people prekilling
|
|
||||||
this.oocKill(killed, event);
|
|
||||||
oldRaid.raiderKilledOutofCombat(event);
|
|
||||||
respawnQueue.put(killed.getUniqueId(), oldRaid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((town != null && town.equals(oldRaid.getRaidedTown()) || playerCloseToHomeBlockRaid)) {
|
|
||||||
this.raidKill(killed, event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*if (killer == null) return;
|
|
||||||
|
|
||||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
|
||||||
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
|
||||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
|
|
||||||
playerCloseToHomeBlockSiege = true;
|
|
||||||
}
|
|
||||||
if (siege.getAttackerPlayers().contains(killer) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
|
||||||
if (siege.getDefenderPlayers().contains(killed)) {
|
|
||||||
siege.addPointsToAttackers(20);
|
|
||||||
for (final Player p : siege.getAttackerPlayers()) {
|
|
||||||
try {
|
|
||||||
if (p != null)
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points").parseLegacy().build());
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
ignored.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (final Player p : siege.getDefenderPlayers()) {
|
|
||||||
try {
|
|
||||||
if (p != null)
|
|
||||||
p.sendMessage(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points");
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
ignored.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.siegeKill(killed, event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (siege.getDefenderPlayers().contains(killer) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
|
||||||
if (siege.getAttackerPlayers().contains(killed)) {
|
|
||||||
siege.addPointsToDefenders(20);
|
|
||||||
for (final Player p : siege.getAttackerPlayers()) {
|
|
||||||
try {
|
|
||||||
if (p != null)
|
|
||||||
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
|
|
||||||
} catch (NullPointerException ex3) {
|
|
||||||
ex3.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (final Player p : siege.getDefenderPlayers()) {
|
|
||||||
try {
|
|
||||||
if (p != null)
|
|
||||||
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
|
|
||||||
} catch (NullPointerException ex4) {
|
|
||||||
ex4.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.siegeKill(killed, event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege)) {
|
|
||||||
this.siegeKill(killed, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException | TownyException ignored) {
|
|
||||||
ignored.printStackTrace();
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs last so that it overrides everyone else!
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
/*@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onRespawn(PlayerRespawnEvent event) {
|
|
||||||
if (respawnQueue.containsKey(event.getPlayer().getUniqueId())) {
|
|
||||||
OldRaid oldRaid = respawnQueue.get(event.getPlayer().getUniqueId());
|
|
||||||
if (oldRaid == null) return;
|
|
||||||
if (oldRaid.getActiveRaiders().contains(event.getPlayer().getName())) {
|
|
||||||
//do raider respawn
|
|
||||||
try {
|
|
||||||
event.setRespawnLocation(oldRaid.getGatherTown().getSpawn());
|
|
||||||
event.getPlayer().sendMessage(UtilsChat.getPrefix() + "You died " + (oldRaid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
|
|
||||||
} catch (TownyException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
} else if (oldRaid.getDefenderSide().contains(event.getPlayer().getName())) {
|
|
||||||
//do defender respawn ?
|
|
||||||
} else {
|
|
||||||
//invalid code
|
|
||||||
}
|
|
||||||
respawnQueue.remove(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Damage all gear held by the player (and then send them to spawn?)
|
|
||||||
* They don't lose items from death.
|
|
||||||
*
|
|
||||||
* @param killed killed player
|
|
||||||
* @param event event
|
|
||||||
*/
|
|
||||||
private void siegeKill(final @NotNull Player killed, final @NotNull PlayerDeathEvent event) {
|
|
||||||
//Helper
|
|
||||||
Utils.damageAllGear(killed);
|
|
||||||
|
|
||||||
//Siege specific
|
|
||||||
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName()); // TODO Re enable?
|
|
||||||
event.setKeepInventory(true);
|
|
||||||
event.getDrops().clear();
|
|
||||||
event.setKeepLevel(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Damage all gear held by the player (and then send them to spawn?)
|
|
||||||
* They don't lose items from death.
|
|
||||||
*
|
|
||||||
* @param killed killed player
|
|
||||||
* @param event event
|
|
||||||
*/
|
|
||||||
private void raidKill(final @NotNull Player killed, final @NotNull PlayerDeathEvent event) {
|
|
||||||
//Helper
|
|
||||||
Utils.damageAllGear(killed);
|
|
||||||
|
|
||||||
//Siege specific
|
|
||||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
|
||||||
event.setKeepInventory(true);
|
|
||||||
event.getDrops().clear();
|
|
||||||
event.setKeepLevel(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dont damage items held by the player
|
|
||||||
* They don't lose items from death.
|
|
||||||
*
|
|
||||||
* @param killed killed player
|
|
||||||
* @param event event
|
|
||||||
*/
|
|
||||||
private void oocKill(final Player killed, final @NotNull PlayerDeathEvent event) {
|
|
||||||
//Siege specific
|
|
||||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
|
||||||
event.setKeepInventory(true);
|
|
||||||
event.getDrops().clear();
|
|
||||||
event.setKeepLevel(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import com.github.alathra.AlathranWars.Main;
|
|||||||
import com.github.alathra.AlathranWars.listeners.siege.BlockBreakPlaceListener;
|
import com.github.alathra.AlathranWars.listeners.siege.BlockBreakPlaceListener;
|
||||||
import com.github.alathra.AlathranWars.listeners.siege.PlayerDeathListener;
|
import com.github.alathra.AlathranWars.listeners.siege.PlayerDeathListener;
|
||||||
import com.github.alathra.AlathranWars.listeners.siege.PlayerQuitListener;
|
import com.github.alathra.AlathranWars.listeners.siege.PlayerQuitListener;
|
||||||
|
import com.github.alathra.AlathranWars.listeners.siege.PlayerSitListener;
|
||||||
import com.github.alathra.AlathranWars.listeners.war.NationListener;
|
import com.github.alathra.AlathranWars.listeners.war.NationListener;
|
||||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||||
import com.github.alathra.AlathranWars.listeners.war.TownListener;
|
import com.github.alathra.AlathranWars.listeners.war.TownListener;
|
||||||
@@ -28,19 +29,18 @@ public class ListenerHandler {
|
|||||||
instance.getServer().getPluginManager().registerEvents(new PlayerQuitListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new PlayerQuitListener(), instance);
|
||||||
instance.getServer().getPluginManager().registerEvents(new BlockBreakPlaceListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new BlockBreakPlaceListener(), instance);
|
||||||
instance.getServer().getPluginManager().registerEvents(new PlayerDeathListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new PlayerDeathListener(), instance);
|
||||||
|
instance.getServer().getPluginManager().registerEvents(new PlayerSitListener(), instance);
|
||||||
|
|
||||||
// Wars
|
// Wars
|
||||||
instance.getServer().getPluginManager().registerEvents(new NationListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new NationListener(), instance);
|
||||||
instance.getServer().getPluginManager().registerEvents(new TownListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new TownListener(), instance);
|
||||||
instance.getServer().getPluginManager().registerEvents(new TownListener(), instance);
|
|
||||||
instance.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), instance);
|
||||||
instance.getServer().getPluginManager().registerEvents(new com.github.alathra.AlathranWars.listeners.war.PlayerQuitListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new com.github.alathra.AlathranWars.listeners.war.PlayerQuitListener(), instance);
|
||||||
|
instance.getServer().getPluginManager().registerEvents(new NewDayListener(), instance);
|
||||||
|
|
||||||
|
|
||||||
// instance.getServer().getPluginManager().registerEvents(new BlockBreakListener(), instance);
|
|
||||||
instance.getServer().getPluginManager().registerEvents(new CommandsListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new CommandsListener(), instance);
|
||||||
// instance.getServer().getPluginManager().registerEvents(new KillsListener(), instance);
|
|
||||||
instance.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), instance);
|
instance.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), instance);
|
||||||
//instance.getServer().getPluginManager().registerEvents(new PlayerJoinListener(instance), instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners;
|
|||||||
|
|
||||||
import com.github.alathra.AlathranWars.Main;
|
import com.github.alathra.AlathranWars.Main;
|
||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
|
|||||||
+108
-45
@@ -1,18 +1,14 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners.siege;
|
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.holder.WarManager;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
|
import com.github.alathra.AlathranWars.utility.Utils;
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.event.actions.TownyBuildEvent;
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
import com.palmergames.bukkit.towny.event.actions.TownyDestroyEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -24,54 +20,121 @@ public class BlockBreakPlaceListener implements Listener {
|
|||||||
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
||||||
Material.TORCH,
|
Material.TORCH,
|
||||||
Material.STONE_BUTTON,
|
Material.STONE_BUTTON,
|
||||||
Material.BLACK_WOOL
|
Material.BLACK_WOOL,
|
||||||
|
// Beds
|
||||||
|
Material.WHITE_BED,
|
||||||
|
Material.YELLOW_BED,
|
||||||
|
Material.BLACK_BED,
|
||||||
|
Material.BLUE_BED,
|
||||||
|
Material.BROWN_BED,
|
||||||
|
Material.CYAN_BED,
|
||||||
|
Material.GRAY_BED,
|
||||||
|
Material.GREEN_BED,
|
||||||
|
Material.LIGHT_BLUE_BED,
|
||||||
|
Material.LIGHT_GRAY_BED,
|
||||||
|
Material.LIME_BED,
|
||||||
|
Material.MAGENTA_BED,
|
||||||
|
Material.ORANGE_BED,
|
||||||
|
Material.PINK_BED,
|
||||||
|
Material.PURPLE_BED,
|
||||||
|
Material.RED_BED
|
||||||
);
|
);
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onBlockBreak(@NotNull BlockBreakEvent e) {
|
public void onBlockBreak(TownyDestroyEvent e) {
|
||||||
final @NotNull Block block = e.getBlock();
|
Siege siege = Utils.getClosestSiege(e.getPlayer(), true);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
if (allowedBlocks.contains(block.getType()))
|
if (!Utils.isOnSiegeBattlefield(e.getPlayer(), siege)) return;
|
||||||
|
|
||||||
|
final boolean isInsideTownClaims = e.hasTownBlock();
|
||||||
|
final boolean isDefender = siege.getPlayerSideInSiege(e.getPlayer()).equals(BattleSide.DEFENDER);
|
||||||
|
|
||||||
|
if (
|
||||||
|
(isDefender || !isInsideTownClaims) && allowedBlocks.contains(e.getMaterial())
|
||||||
|
) {
|
||||||
|
e.setCancelled(false);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getPlayer().hasPermission("AlathranWars.break"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
final @Nullable Town town = WorldCoord.parseWorldCoord(block).getTownOrNull();
|
|
||||||
|
|
||||||
if (town == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (final @NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
if (siege.getTown().equals(town)) {
|
|
||||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break blocks during sieges.").build());
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.getPlayer().hasPermission("AlathranWars.break")) {
|
||||||
|
e.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.setCancelMessage("");
|
||||||
|
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break blocks during sieges.").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(@NotNull BlockPlaceEvent e) {
|
public void onBlockPlace(TownyBuildEvent e) {
|
||||||
final @NotNull Block block = e.getBlock();
|
Siege siege = Utils.getClosestSiege(e.getPlayer(), true);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
if (allowedBlocks.contains(block.getType()))
|
if (!Utils.isOnSiegeBattlefield(e.getPlayer(), siege)) return;
|
||||||
|
|
||||||
|
final boolean isInsideTownClaims = e.hasTownBlock();
|
||||||
|
final boolean isDefender = siege.getPlayerSideInSiege(e.getPlayer()).equals(BattleSide.DEFENDER);
|
||||||
|
|
||||||
|
if (
|
||||||
|
(isDefender || !isInsideTownClaims) && allowedBlocks.contains(e.getMaterial())
|
||||||
|
) {
|
||||||
|
e.setCancelled(false);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getPlayer().hasPermission("AlathranWars.place"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
final @Nullable Town town = WorldCoord.parseWorldCoord(block).getTownOrNull();
|
|
||||||
|
|
||||||
if (town == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (final @NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
|
||||||
if (siege.getTown().equals(town)) {
|
|
||||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not place blocks during sieges.").build());
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.getPlayer().hasPermission("AlathranWars.place")) {
|
||||||
|
e.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.setCancelMessage("");
|
||||||
|
e.getPlayer().sendMessage(ColorParser.of("<red>You can not place blocks during sieges.").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void onIteract(Towny)
|
||||||
|
|
||||||
|
/*@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockPlaceTowny(BlockBreakEvent e) {
|
||||||
|
Siege siege = Utils.getClosestSiege(e.getPlayer(), true);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
|
if (!Utils.isOnSiegeBattlefield(e.getPlayer(), siege)) return;
|
||||||
|
|
||||||
|
if (e.getPlayer().hasPermission("AlathranWars.break")) {
|
||||||
|
e.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowedBlocks.contains(e.getBlock().getType())) {
|
||||||
|
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break these blocks during sieges.").build());
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockPlaceTowny(BlockPlaceEvent e) {
|
||||||
|
Siege siege = Utils.getClosestSiege(e.getPlayer(), true);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
|
if (!Utils.isOnSiegeBattlefield(e.getPlayer(), siege)) return;
|
||||||
|
|
||||||
|
if (e.getPlayer().hasPermission("AlathranWars.place")) {
|
||||||
|
e.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowedBlocks.contains(e.getBlock().getType())) {
|
||||||
|
e.getPlayer().sendMessage(ColorParser.of("<red>You can not place these blocks during sieges.").build());
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(false);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
+50
-72
@@ -1,94 +1,74 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners.siege;
|
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.github.alathra.AlathranWars.utility.Utils;
|
||||||
|
import com.ranull.graves.event.GraveCreateEvent;
|
||||||
|
import dev.geco.gsit.api.event.PrePlayerPlayerSitEvent;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class PlayerDeathListener implements Listener {
|
public class PlayerDeathListener implements Listener {
|
||||||
private final static int BATTLE_RADIUS = 300;
|
@EventHandler
|
||||||
private final static int KILL_POINTS_OFF = 20; // Point for an offensive kill
|
private void onGraveCreate(GraveCreateEvent e) {
|
||||||
private final static int KILL_POINTS_DEF = 20; // Point for a defensive kill
|
if (!e.getEntityType().equals(EntityType.PLAYER)) return;
|
||||||
|
if (!(e.getEntity() instanceof Player p)) return;
|
||||||
|
|
||||||
/*@EventHandler
|
Siege siege = Utils.getClosestSiege(p, false);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
|
if (!Utils.isOnSiegeBattlefield(p, siege)) return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
private void onPlayerDeath(PlayerDeathEvent e) {
|
private void onPlayerDeath(PlayerDeathEvent e) {
|
||||||
final Player victim = e.getPlayer();
|
Player victim = e.getPlayer();
|
||||||
final Player attacker = e.getPlayer().getKiller();
|
Player attacker = e.getPlayer().getKiller();
|
||||||
|
if (attacker == null) return;
|
||||||
|
|
||||||
if (attacker == null)
|
Siege siege = Utils.getClosestSiege(victim, false);
|
||||||
return;
|
if (siege == null) return;
|
||||||
|
|
||||||
final @Nullable Town town = WorldCoord.parseWorldCoord(victim).getTownOrNull();
|
if (!Utils.isOnSiegeBattlefield(victim, siege)) return;
|
||||||
|
|
||||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
if (siege.isPlayerInSiege(victim) && siege.isPlayerInSiege(attacker)) {
|
||||||
boolean isPlayerInCombatZone = false;
|
siegeKill(e);
|
||||||
|
} else {
|
||||||
final TownBlock homeBlock = siege.getTown().getHomeBlockOrNull();
|
oocKill(e);
|
||||||
if (homeBlock == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
final int homeBlockXCoord = homeBlock.getCoord().getX() * 16;
|
|
||||||
final int homeBlockZCoord = homeBlock.getCoord().getZ() * 16;
|
|
||||||
|
|
||||||
if (victim.getLocation().distance(new Location(victim.getWorld(), homeBlockXCoord, victim.getLocation().getBlockY(), homeBlockZCoord)) <= BATTLE_RADIUS) {
|
|
||||||
// if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= BATTLE_RADIUS && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= BATTLE_RADIUS) {
|
|
||||||
isPlayerInCombatZone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (siege.getAttackerPlayers().contains(attacker) && (siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
|
||||||
if (siege.getDefenderPlayers().contains(victim)) {
|
|
||||||
siege.addPointsToAttackers(KILL_POINTS_OFF);
|
|
||||||
|
|
||||||
for (final Player p : siege.getAttackerPlayers()) {
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
|
||||||
}
|
|
||||||
for (final Player p : siege.getDefenderPlayers()) {
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.siegeKill(victim, e);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (siege.getDefenderPlayers().contains(attacker) && (siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
|
||||||
if (siege.getAttackerPlayers().contains(victim)) {
|
|
||||||
siege.addPointsToDefenders(KILL_POINTS_DEF);
|
|
||||||
|
|
||||||
for (final Player p : siege.getAttackerPlayers()) {
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
|
||||||
}
|
|
||||||
for (final Player p : siege.getDefenderPlayers()) {
|
|
||||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.siegeKill(victim, e);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
|
||||||
this.oocKill(victim, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onPlayerSuicide(PlayerDeathEvent e) {
|
||||||
|
Player victim = e.getPlayer();
|
||||||
|
Player attacker = e.getPlayer().getKiller();
|
||||||
|
if (attacker != null) return;
|
||||||
|
|
||||||
|
Siege siege = Utils.getClosestSiege(victim, false);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
|
if (!Utils.isOnSiegeBattlefield(victim, siege)) return;
|
||||||
|
|
||||||
|
if (siege.isPlayerInSiege(victim)) {
|
||||||
|
siegeKill(e);
|
||||||
|
} else {
|
||||||
|
oocKill(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Damage all gear held by the player (and then send them to spawn?)
|
* Damage all gear held by the player (and then send them to spawn?)
|
||||||
* They don't lose items from death.
|
* They don't lose items from death.
|
||||||
*
|
*
|
||||||
* @param victim killed player
|
|
||||||
* @param e event
|
* @param e event
|
||||||
*/
|
*/
|
||||||
private void siegeKill(@NotNull Player victim, @NotNull PlayerDeathEvent e) {
|
private void siegeKill(PlayerDeathEvent e) {
|
||||||
//Helper
|
|
||||||
Utils.damageAllGear(victim);
|
|
||||||
|
|
||||||
//Siege specific
|
|
||||||
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
||||||
|
// Utils.damageAllGear(e.getPlayer());
|
||||||
e.setKeepInventory(true);
|
e.setKeepInventory(true);
|
||||||
e.getDrops().clear();
|
e.getDrops().clear();
|
||||||
e.setKeepLevel(true);
|
e.setKeepLevel(true);
|
||||||
@@ -98,11 +78,9 @@ public class PlayerDeathListener implements Listener {
|
|||||||
* Dont damage items held by the player
|
* Dont damage items held by the player
|
||||||
* They don't lose items from death.
|
* They don't lose items from death.
|
||||||
*
|
*
|
||||||
* @param victim killed player
|
|
||||||
* @param e event
|
* @param e event
|
||||||
*/
|
*/
|
||||||
private void oocKill(Player victim, @NotNull PlayerDeathEvent e) {
|
private void oocKill(PlayerDeathEvent e) {
|
||||||
//Siege specific
|
|
||||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
||||||
e.setKeepInventory(true);
|
e.setKeepInventory(true);
|
||||||
e.getDrops().clear();
|
e.getDrops().clear();
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ 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.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ 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.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.github.alathra.AlathranWars.listeners.siege;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
|
import com.github.alathra.AlathranWars.utility.Utils;
|
||||||
|
import dev.geco.gsit.api.event.PreEntitySitEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class PlayerSitListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onSit2(PreEntitySitEvent e) {
|
||||||
|
if (!(e.getEntity() instanceof Player p)) return;
|
||||||
|
|
||||||
|
Siege siege = Utils.getClosestSiege(p, false);
|
||||||
|
if (siege == null) return;
|
||||||
|
|
||||||
|
if (!Utils.isOnSiegeBattlefield(p, siege)) return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,77 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners.war;
|
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.palmergames.bukkit.towny.event.NationAddTownEvent;
|
||||||
|
import com.palmergames.bukkit.towny.event.NationPreRenameEvent;
|
||||||
|
import com.palmergames.bukkit.towny.event.nation.NationPreMergeEvent;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
public class NationListener implements Listener {
|
public class NationListener implements Listener {
|
||||||
/*
|
|
||||||
* NationPreTownLeaveEvent, NationPreTownKickEvent, NationPreMergeEvent
|
|
||||||
*
|
|
||||||
* NationKingChangeEvent
|
|
||||||
* NationPreRenameEvent
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NationTownJoin (add to war)
|
|
||||||
* NationTownLeave (add to war)
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
// TODO Prevent nation rename during war, siege, raid
|
|
||||||
|
|
||||||
/*@EventHandler
|
/*@EventHandler
|
||||||
private void onNationKingChange(NationKingChangeEvent e) {
|
private void onNationKingChange(NationKingChangeEvent e) {
|
||||||
e.setCancelMessage("");
|
e.setCancelMessage("");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onRename(NationPreRenameEvent e) {
|
||||||
|
Nation nation = e.getNation();
|
||||||
|
|
||||||
|
if (WarManager.getInstance().isNationInAnyWars(nation)) {
|
||||||
|
e.setCancelMessage("You can't rename a nation while it's in a war.");
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onTownJoin(NationAddTownEvent e) {
|
||||||
|
Nation nation = e.getNation();
|
||||||
|
Town town = e.getTown();
|
||||||
|
|
||||||
|
// Add town to all nation wars
|
||||||
|
for (War war : WarManager.getInstance().getNationWars(nation)) {
|
||||||
|
Side side = war.getNationSide(nation);
|
||||||
|
if (side == null) continue;
|
||||||
|
|
||||||
|
side.addTown(town);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Add nation to towns' wars
|
||||||
|
for (War war : WarManager.getInstance().getTownWars(town)) {
|
||||||
|
Side side = war.getTownSide(town);
|
||||||
|
if (side == null) continue;
|
||||||
|
|
||||||
|
side.addNation(nation);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (War war : WarManager.getInstance().getNationWars(nation)) {
|
||||||
|
Side side = war.getNationSide(nation);
|
||||||
|
if (side == null) continue;
|
||||||
|
|
||||||
|
side.getPlayers().forEach(PlayerJoinListener::checkPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@EventHandler // Do nothing, leaving a nation should not let you escape nation wars
|
||||||
|
private void onTownLeave(NationTownLeaveEvent e) {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onMerge(NationPreMergeEvent e) {
|
||||||
|
Nation nation = e.getRemainingNation();
|
||||||
|
Nation nation1 = e.getNation();
|
||||||
|
|
||||||
|
if (WarManager.getInstance().isNationInAnyWars(nation) || WarManager.getInstance().isNationInAnyWars(nation1)) {
|
||||||
|
e.setCancelMessage("You can't merge nations while they are in a war.");
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Allow merging nations in war, literally just ensure that towns are added to sieges and sides
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
|
|||||||
|
|
||||||
import com.github.alathra.AlathranWars.conflict.Side;
|
import com.github.alathra.AlathranWars.conflict.Side;
|
||||||
import com.github.alathra.AlathranWars.conflict.War;
|
import com.github.alathra.AlathranWars.conflict.War;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.github.alathra.AlathranWars.hooks.TABHook;
|
import com.github.alathra.AlathranWars.hooks.TABHook;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
|
|||||||
|
|
||||||
import com.github.alathra.AlathranWars.conflict.Side;
|
import com.github.alathra.AlathranWars.conflict.Side;
|
||||||
import com.github.alathra.AlathranWars.conflict.War;
|
import com.github.alathra.AlathranWars.conflict.War;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -1,22 +1,124 @@
|
|||||||
package com.github.alathra.AlathranWars.listeners.war;
|
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.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.Town;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
public class TownListener implements Listener {
|
public class TownListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
private void onRename(TownPreRenameEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
|
||||||
|
if (WarManager.getInstance().isTownInAnyWars(town)) {
|
||||||
|
e.setCancelMessage("You can't rename a town while it's in a war.");
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Allow renaming in war, update some vars pretty much
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onPlayerJoin(TownAddResidentEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
Player p = e.getResident().getPlayer();
|
||||||
|
if (p == null) return;
|
||||||
|
|
||||||
|
for (War war : WarManager.getInstance().getTownWars(town)) {
|
||||||
|
Side side = war.getTownSide(town);
|
||||||
|
if (side == null) continue;
|
||||||
|
side.addPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerJoinListener.checkPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onPlayerLeave(TownLeaveEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
Player p = e.getResident().getPlayer();
|
||||||
|
if (p == null) return;
|
||||||
|
|
||||||
|
for (War war : WarManager.getInstance().getTownWars(town)) {
|
||||||
|
Side side = war.getTownSide(town);
|
||||||
|
if (side == null) continue;
|
||||||
|
side.removePlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerJoinListener.checkPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onPlayerKick(TownKickEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
Player p = e.getKickedResident().getPlayer();
|
||||||
|
if (p == null) return;
|
||||||
|
|
||||||
|
for (War war : WarManager.getInstance().getTownWars(town)) {
|
||||||
|
Side side = war.getTownSide(town);
|
||||||
|
if (side == null) continue;
|
||||||
|
side.removePlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerJoinListener.checkPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@EventHandler
|
||||||
|
private void onLeaderChange(TownMayorChangedEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
Resident newMayor = e.getNewMayor();
|
||||||
|
Resident oldMayor = e.getOldMayor();
|
||||||
|
|
||||||
|
if (e.isKingChange() && e.isNationCapital()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onLeaderChangeSuccession(TownMayorChosenBySuccessionEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
Resident newMayor = e.getNewMayor();
|
||||||
|
Resident oldMayor = e.getOldMayor();
|
||||||
|
|
||||||
|
if (e.isKingChange() && e.isNationCapital()) {
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onMerge(TownPreMergeEvent e) {
|
||||||
|
Town town = e.getRemainingTown();
|
||||||
|
Town town2 = e.getSuccumbingTown();
|
||||||
|
|
||||||
|
if (WarManager.getInstance().isTownInAnyWars(town) || WarManager.getInstance().isTownInAnyWars(town2)) {
|
||||||
|
e.setCancelMessage("You can't merge towns while they are in a war.");
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Allow merging towns in war, literally just ensure that players are added to sieges and sides
|
||||||
|
}
|
||||||
|
|
||||||
// TODO On town ruin, bow town out of any active wars, if leader of war surrender
|
// TODO On town ruin, bow town out of any active wars, if leader of war surrender
|
||||||
// TODO On town ruin, leave or cancel sieges where the town is present
|
// TODO On town ruin, leave or cancel sieges where the town is present
|
||||||
// TODO On town ruin, leave or cancel raids where the town is present
|
// TODO On town ruin, leave or cancel raids where the town is present
|
||||||
// TODO Prevent town rename during war, siege, raid
|
@EventHandler
|
||||||
|
private void onRuin(TownRuinedEvent e) {
|
||||||
|
Town town = e.getTown();
|
||||||
|
|
||||||
/*
|
for (War war : WarManager.getInstance().getTownWars(town)) {
|
||||||
TownMayorChangeEvent
|
Side side = war.getTownSide(town);
|
||||||
TownLeaveEvent
|
if (side == null) continue;
|
||||||
TownPreMergeEvent
|
war.unsurrenderTown(town);
|
||||||
TownPreRuinedEvent
|
side.removeTown(town);
|
||||||
TownPreRenameEvent
|
side.processSurrenders();
|
||||||
TownRemoveResidentEvent
|
}
|
||||||
|
}
|
||||||
PlayerJoinTown (add to war)
|
|
||||||
PlayerLeaveTown (add to war)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.github.alathra.AlathranWars.utility;
|
package com.github.alathra.AlathranWars.utility;
|
||||||
|
|
||||||
import com.github.alathra.AlathranWars.Main;
|
import com.github.alathra.AlathranWars.Main;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Config {
|
/**
|
||||||
public static de.leonhard.storage.Config get() {
|
* Convenience class for accessing {@link com.github.alathra.AlathranWars.data.ConfigManager}
|
||||||
|
*/
|
||||||
|
public abstract class Config {
|
||||||
|
public static @NotNull de.leonhard.storage.Config get() {
|
||||||
return Main.getInstance().getConfigManager().getConfig();
|
return Main.getInstance().getConfigManager().getConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience class for accessing {@link com.github.alathra.AlathranWars.data.DataManager }
|
||||||
|
*/
|
||||||
public abstract class DB {
|
public abstract class DB {
|
||||||
public static @NotNull Connection get() throws SQLException {
|
public static @NotNull Connection get() throws SQLException {
|
||||||
return Main.getInstance().getDataManager().getConnection();
|
return Main.getInstance().getDataManager().getConnection();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.github.alathra.AlathranWars.conflict.War;
|
|||||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
@@ -21,7 +21,10 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SQLQueries {
|
/**
|
||||||
|
* Convenience class for defining and executing SQL queries
|
||||||
|
*/
|
||||||
|
public abstract class SQLQueries {
|
||||||
public static void initDB() {
|
public static void initDB() {
|
||||||
try (final Statement statement = DB.get().createStatement()) {
|
try (final Statement statement = DB.get().createStatement()) {
|
||||||
statement.addBatch("""
|
statement.addBatch("""
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package com.github.alathra.AlathranWars.utility;
|
package com.github.alathra.AlathranWars.utility;
|
||||||
|
|
||||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UUIDUtil {
|
/**
|
||||||
|
* Convenience class for generating UUID for different things in the plugin
|
||||||
|
*/
|
||||||
|
public abstract class UUIDUtil {
|
||||||
public static @NotNull UUID generateWarUUID() {
|
public static @NotNull UUID generateWarUUID() {
|
||||||
@NotNull UUID uuid = UUID.randomUUID();
|
@NotNull UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.github.alathra.AlathranWars.utility;
|
package com.github.alathra.AlathranWars.utility;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||||
|
import com.github.alathra.AlathranWars.conflict.WarManager;
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -12,8 +15,10 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Utils {
|
public abstract class Utils {
|
||||||
private static final ArrayList<Material> weaponList = new ArrayList<>(List.of(
|
private static final ArrayList<Material> weaponList = new ArrayList<>(List.of(
|
||||||
Material.NETHERITE_SWORD,
|
Material.NETHERITE_SWORD,
|
||||||
Material.NETHERITE_AXE,
|
Material.NETHERITE_AXE,
|
||||||
@@ -191,6 +196,44 @@ public class Utils {
|
|||||||
itemStack.setItemMeta(damageable);
|
itemStack.setItemMeta(damageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Implement usage in siege commands to make siege optional argument
|
||||||
|
public static @Nullable Siege getClosestSiege(Player p, boolean checkIfInSiege) {
|
||||||
|
Set<Siege> sieges = checkIfInSiege
|
||||||
|
? WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(p)).collect(Collectors.toSet())
|
||||||
|
: WarManager.getInstance().getSieges();
|
||||||
|
|
||||||
|
@Nullable Siege siegeResult = null;
|
||||||
|
final Location playerLoc = p.getLocation();
|
||||||
|
double closestSiege = 100000000D;
|
||||||
|
|
||||||
|
for (Siege siege : sieges) {
|
||||||
|
final @Nullable Location location = siege.getTown().getSpawnOrNull();
|
||||||
|
|
||||||
|
if (location == null) continue;
|
||||||
|
if (!location.getWorld().equals(playerLoc.getWorld())) continue;
|
||||||
|
|
||||||
|
final double distance = location.distance(playerLoc);
|
||||||
|
if (distance < closestSiege) {
|
||||||
|
siegeResult = siege;
|
||||||
|
closestSiege = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return siegeResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOnSiegeBattlefield(Player p, Siege siege) {
|
||||||
|
if (siege == null) return false;
|
||||||
|
|
||||||
|
final Location pLocation = p.getLocation();
|
||||||
|
final Location siegeLocation = siege.getTownSpawn();
|
||||||
|
|
||||||
|
if (siegeLocation == null) return false;
|
||||||
|
if (!pLocation.getWorld().equals(siegeLocation.getWorld())) return false;
|
||||||
|
|
||||||
|
return (pLocation.distance(siegeLocation) <= Siege.BATTLEFIELD_RANGE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param worldCoord worldCoord
|
* @param worldCoord worldCoord
|
||||||
* @return List of connected chunks
|
* @return List of connected chunks
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.github.alathra.AlathranWars.utility;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class UtilsChat {
|
public abstract class UtilsChat {
|
||||||
public static @NotNull String getPrefix() {
|
public static @NotNull String getPrefix() {
|
||||||
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>]<reset> ";
|
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>]<reset> ";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user