mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
refactor: wip update 7
This commit is contained in:
50 files changed
+1546
-739
No files matched your search
+22
-8
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.github.alathra.AlathranWars"
|
||||
version = "3.0.1-SNAPSHOT"
|
||||
version = "3.0.2-SNAPSHOT"
|
||||
description = ""
|
||||
|
||||
java {
|
||||
@@ -50,23 +50,31 @@ dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
|
||||
|
||||
implementation("com.github.milkdrinkers:simplixstorage:3.2.7")
|
||||
implementation("com.github.milkdrinkers:colorparser:1.0.7")
|
||||
implementation("com.github.milkdrinkers:colorparser:2.0.0") {
|
||||
exclude(group = "net.kyori", module = "adventure-api")
|
||||
}
|
||||
implementation("io.github.skytasul:guardianbeam:2.3.3")
|
||||
|
||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
|
||||
|
||||
compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.0")
|
||||
compileOnly("com.palmergames.bukkit.towny:towny:0.99.5.5") {
|
||||
exclude(group = "com.palmergames", module = "adventure")
|
||||
}
|
||||
|
||||
compileOnly("me.neznamy:tab-api:4.0.0")
|
||||
|
||||
implementation("dev.jorel:commandapi-bukkit-shade:9.0.3")
|
||||
implementation("dev.jorel:commandapi-bukkit-shade:9.0.3") {
|
||||
exclude(group = "net.kyori", module = "adventure-api")
|
||||
}
|
||||
compileOnly("dev.jorel:commandapi-annotations:9.0.3")
|
||||
annotationProcessor("dev.jorel:commandapi-annotations:9.0.3")
|
||||
|
||||
implementation("com.zaxxer:HikariCP:5.0.1")
|
||||
implementation("org.mariadb.jdbc:mariadb-java-client:3.1.0")
|
||||
implementation("org.mariadb.jdbc:mariadb-java-client:3.1.4")
|
||||
|
||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||
compileOnly("me.clip:placeholderapi:2.11.3") {
|
||||
exclude(group = "me.clip.placeholderapi.libs", module = "kyori")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -98,12 +106,18 @@ tasks {
|
||||
reloc("de.leonhard.storage", "storageapi")
|
||||
reloc("dev.jorel.commandapi", "commandapi")
|
||||
reloc("com.zaxxer.hikari", "hikaricp")
|
||||
// reloc("org.xerial", "sqlite")
|
||||
// reloc("com.mysql", "mysql")
|
||||
reloc("org.mariadb.jdbc", "mariadb")
|
||||
reloc("io.github.skytasul", "guardianbeam")
|
||||
}
|
||||
|
||||
runServer {
|
||||
// Configure the Minecraft version for our task.
|
||||
minecraftVersion("1.20.1")
|
||||
minecraftVersion("1.19.4")
|
||||
jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005")
|
||||
systemProperty("terminal.jline", false)
|
||||
systemProperty("terminal.ansi", true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +130,7 @@ bukkit {
|
||||
prefix = "AlathranWars"
|
||||
version = "${project.version}"
|
||||
description = "${project.description}"
|
||||
authors = listOf("ShermansWorld", "NinjaMandalorian", "AubriTheHuman", "darksaid98")
|
||||
authors = listOf("darksaid98", "ShermansWorld", "NinjaMandalorian", "AubriTheHuman")
|
||||
contributors = listOf()
|
||||
apiVersion = "1.19"
|
||||
|
||||
|
||||
+44
-53
@@ -18,6 +18,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -147,9 +148,9 @@ public class AdminCommand {
|
||||
}*/
|
||||
|
||||
@NotNull
|
||||
private static StringBuilder getSurrenderedTowns(War war) {
|
||||
StringBuilder surrenderedTowns = new StringBuilder();
|
||||
for (Town t : war.getSurrenderedTowns()) {
|
||||
private static StringBuilder getSurrenderedTowns(@NotNull War war) {
|
||||
@NotNull StringBuilder surrenderedTowns = new StringBuilder();
|
||||
for (@NotNull Town t : war.getSurrenderedTowns()) {
|
||||
surrenderedTowns.append(t.getName());
|
||||
surrenderedTowns.append(", ");
|
||||
}
|
||||
@@ -160,17 +161,11 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
|
||||
private static boolean fail(CommandSender p, CommandArguments args, AdminCommandFailEnum type) throws WrapperCommandSyntaxException {
|
||||
private static boolean fail(CommandSender p, CommandArguments args, @NotNull AdminCommandFailEnum type) throws WrapperCommandSyntaxException {
|
||||
switch (type) {
|
||||
case PERMISSIONS -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You do not have permission to do this.").build());
|
||||
}
|
||||
case SYNTAX -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /alathranwarsadmin help").build());
|
||||
}
|
||||
default -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Something wrong. /alathranwarsadmin help").build());
|
||||
}
|
||||
case PERMISSIONS -> throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You do not have permission to do this.").build());
|
||||
case SYNTAX -> throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /alathranwarsadmin help").build());
|
||||
default -> throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Something wrong. /alathranwarsadmin help").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,9 +197,9 @@ public class AdminCommand {
|
||||
.executesPlayer((Player sender, CommandArguments args) -> {
|
||||
// Parse item
|
||||
if (!(args.get("item") instanceof String argItem))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid item argument.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Invalid item argument.").build());
|
||||
|
||||
ItemStack stack;
|
||||
@Nullable ItemStack stack;
|
||||
if (argItem.contains(Main.getInstance().getName().toLowerCase())) {
|
||||
stack = WarItemRegistry.getInstance().getOrNullNamespace(argItem);
|
||||
} else {
|
||||
@@ -212,7 +207,7 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
if (stack == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The item is not an AlathranWars item.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The item is not an AlathranWars item.").build());
|
||||
|
||||
// Parse amount
|
||||
int argAmount = (int) args.getOptional("amount").orElse(1);
|
||||
@@ -231,7 +226,7 @@ public class AdminCommand {
|
||||
argPlayer.getInventory().addItem(stack);
|
||||
|
||||
//log
|
||||
final Component name = stack.getItemMeta() == null ? new ColorParser(stack.toString()).build() : stack.getItemMeta().displayName();
|
||||
final @Nullable Component name = stack.getItemMeta() == null ? ColorParser.of(stack.toString()).build() : stack.getItemMeta().displayName();
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Gave " + stack.getAmount() + "x " + name + " to " + argPlayer.getName());
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Gave " + stack.getAmount() + "x " + name + " to " + argPlayer.getName());
|
||||
});
|
||||
@@ -268,7 +263,7 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
if (war.getName().equalsIgnoreCase(argWarName)) {
|
||||
@@ -292,9 +287,7 @@ public class AdminCommand {
|
||||
|
||||
private CommandAPICommand commandLoad() {
|
||||
return new CommandAPICommand("load")
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>Support for loading wars individually is currently unimplemented. Use /awa load-all instead").build());
|
||||
});
|
||||
.executes((CommandSender sender, CommandArguments args) -> sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>Support for loading wars individually is currently unimplemented. Use /awa load-all instead").build()));
|
||||
|
||||
/*if (args.length >= 3) {
|
||||
if(Boolean.parseBoolean(args[2])) {
|
||||
@@ -411,8 +404,8 @@ public class AdminCommand {
|
||||
.executesPlayer((Player p, CommandArguments args) -> SiegeCommand.siegeStart(p, args, true)),
|
||||
new CommandAPICommand("war")
|
||||
.withArguments(
|
||||
CommandUtil.customTownAndNationsArgument("side1", "war", true),
|
||||
CommandUtil.customTownAndNationsArgument("side2", "war", true),
|
||||
CommandUtil.customTownAndNationArgument("side1", "war", true),
|
||||
CommandUtil.customTownAndNationArgument("side2", "war", true),
|
||||
new GreedyStringArgument("warlabel")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||
@@ -424,9 +417,7 @@ public class AdminCommand {
|
||||
)
|
||||
.executesPlayer(WarCommand::warCreate)
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> {
|
||||
fail(p, args, AdminCommandFailEnum.SYNTAX);
|
||||
});
|
||||
.executesPlayer((Player p, CommandArguments args) -> fail(p, args, AdminCommandFailEnum.SYNTAX));
|
||||
}
|
||||
|
||||
private CommandAPICommand commandForce() {
|
||||
@@ -468,15 +459,15 @@ public class AdminCommand {
|
||||
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldSiege") instanceof final String argSiegeName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
|
||||
final Siege oldSiege = SiegeData.getSiege(argSiegeName);
|
||||
if (oldSiege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
|
||||
final War war = oldSiege.getWar();
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
|
||||
final String argSide = (String) args.getOptional("victor").orElse("none");
|
||||
|
||||
@@ -537,15 +528,15 @@ public class AdminCommand {
|
||||
)
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldRaid") instanceof final String argRaidName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
|
||||
final War war = oldRaid.getWar();
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
|
||||
final String argSide = (String) args.getOptional("victor").orElse("none");
|
||||
|
||||
@@ -730,12 +721,12 @@ public class AdminCommand {
|
||||
)
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war!").build());
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war!").build());
|
||||
|
||||
// final War war = WarManager.getInstance().getWar(argWarName);
|
||||
// if (war == null)
|
||||
// throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That war does not exist!").build());
|
||||
// throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>That war does not exist!").build());
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for war: " + war.getName());
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
@@ -747,14 +738,14 @@ public class AdminCommand {
|
||||
// sender.sendMessage(UtilsChat.getPrefix() + "Last Raid for Side 1: " + new Timestamp(((long) war.getLastRaidTimeSide1()) * 1000L)); // TODO
|
||||
// sender.sendMessage(UtilsChat.getPrefix() + "Last Raid for Side 2: " + new Timestamp(((long) war.getLastRaidTimeSide2()) * 1000L));
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
StringBuilder side1Towns = new StringBuilder();
|
||||
StringBuilder side1Players = new StringBuilder();
|
||||
@NotNull StringBuilder side1Towns = new StringBuilder();
|
||||
@NotNull StringBuilder side1Players = new StringBuilder();
|
||||
|
||||
for (Town town : war.getSide1().getTowns()) {
|
||||
for (@NotNull Town town : war.getSide1().getTowns()) {
|
||||
side1Towns.append(town.getName());
|
||||
side1Towns.append(", ");
|
||||
}
|
||||
for (Player player : war.getSide1().getPlayers()) {
|
||||
for (@NotNull Player player : war.getSide1().getPlayers()) {
|
||||
side1Players.append(player.getName());
|
||||
side1Players.append(", ");
|
||||
}
|
||||
@@ -768,8 +759,8 @@ public class AdminCommand {
|
||||
sender.sendMessage(UtilsChat.getPrefix() + war.getSide1() + " Players: " + side1Players);
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
StringBuilder side2Towns = new StringBuilder();
|
||||
StringBuilder side2Players = new StringBuilder();
|
||||
@NotNull StringBuilder side2Towns = new StringBuilder();
|
||||
@NotNull StringBuilder side2Players = new StringBuilder();
|
||||
|
||||
for (Town town : war.getSide2().getTowns()) {
|
||||
side2Towns.append(town);
|
||||
@@ -789,7 +780,7 @@ public class AdminCommand {
|
||||
sender.sendMessage(UtilsChat.getPrefix() + war.getSide2() + " Players: " + side2Players);
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
final StringBuilder surrenderedTowns = getSurrenderedTowns(war);
|
||||
final @NotNull StringBuilder surrenderedTowns = getSurrenderedTowns(war);
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Surrendered Towns: " + surrenderedTowns);
|
||||
}
|
||||
)/*,
|
||||
@@ -804,11 +795,11 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> { // TODO Needed
|
||||
if (!(args.get("oldSiege") instanceof final String argSiegeName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
|
||||
final Siege oldSiege = SiegeData.getSiege(argSiegeName);
|
||||
if (oldSiege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for oldSiege: " + oldSiege.getName());
|
||||
@@ -855,11 +846,11 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldRaid") instanceof final String argRaidName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for oldRaid: " + oldRaid.getName());
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
@@ -947,17 +938,17 @@ public class AdminCommand {
|
||||
),
|
||||
new IntegerArgument("amount", 1, 10000)
|
||||
).executesPlayer((Player p, CommandArguments args) -> {
|
||||
if (!(args.get("action") instanceof final String argAction))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify an action.").build());
|
||||
if (!(args.get("action") instanceof final @NotNull String argAction))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify an action.").build());
|
||||
|
||||
if (!List.of("add", "subtract", "set").contains(argAction))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid action.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Invalid action.").build());
|
||||
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
|
||||
if (!(args.get("side") instanceof final Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").build());
|
||||
if (!(args.get("side") instanceof final @NotNull Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The side does not exist.").build());
|
||||
|
||||
final int amount = (int) args.get("amount");
|
||||
|
||||
+63
-61
@@ -18,6 +18,8 @@ import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@@ -36,7 +38,7 @@ public class SiegeCommand {
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
@@ -117,23 +119,23 @@ public class SiegeCommand {
|
||||
}
|
||||
|
||||
|
||||
protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
protected static void siegeStart(@NotNull Player sender, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
if (!(args.get("town") instanceof final @NotNull Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
//if this is admin mode use the forth arg instad of sender.
|
||||
//if player is null after this then force end
|
||||
final Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
|
||||
final @NotNull Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
|
||||
|
||||
if (siegeOwner == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("You need to pick a valid leader.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You need to pick a valid leader.").build());
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
|
||||
Side side = war.getTownSide(leaderTown);
|
||||
@Nullable Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
|
||||
@Nullable Side side = war.getTownSide(leaderTown);
|
||||
|
||||
// TODO DEBUG PRINT
|
||||
// Main.warLogger.log("Leader Town: " + leaderTown.getName());
|
||||
@@ -152,12 +154,12 @@ public class SiegeCommand {
|
||||
}*/
|
||||
|
||||
if (!war.isTownInWar(leaderTown)) {
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
if (admin) sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
siegeOwner.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
if (admin) sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
return;
|
||||
} else if (side.isTownSurrendered(leaderTown)) {
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
if (admin) sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
siegeOwner.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
if (admin) sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,19 +203,19 @@ public class SiegeCommand {
|
||||
|
||||
// Attacking own side
|
||||
if (side.isTownOnSide(town)) {
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
siegeOwner.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
if (admin)
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
Siege siege = new Siege(war, town, siegeOwner);
|
||||
@NotNull Siege siege = new Siege(war, town, siegeOwner);
|
||||
war.addSiege(siege);
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
|
||||
|
||||
if (admin)
|
||||
sender.sendMessage(new ColorParser("<red>Forcefully started siege from the console.").build());
|
||||
sender.sendMessage(ColorParser.of("<red>Forcefully started siege from the console.").build());
|
||||
|
||||
siege.start();
|
||||
// TODO Debug logs...
|
||||
@@ -221,39 +223,39 @@ public class SiegeCommand {
|
||||
// sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
|
||||
}
|
||||
|
||||
private static void siegeStop(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
private static void siegeStop(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
if (!(args.get("town") instanceof final @NotNull Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
final Set<Siege> sieges = war.getSieges();
|
||||
final @NotNull Set<Siege> sieges = war.getSieges();
|
||||
if (sieges.isEmpty())
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress!").build());
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
for (@NotNull Siege siege : sieges) {
|
||||
if (siege.getTown().getUUID().equals(town.getUUID()) && siege.getWar().equals(war)) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "siege cancelled.").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin.").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "siege cancelled.").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin.").build());
|
||||
siege.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "A siege could not be found with this town name! Type /siege list to view current sieges").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "A siege could not be found with this town name! Type /siege list to view current sieges").build());
|
||||
}
|
||||
|
||||
private static void siegeAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
private static void siegeAbandon(Player p, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
if (!(args.get("town") instanceof final @NotNull Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
Siege siege = null;
|
||||
@Nullable Siege siege = null;
|
||||
|
||||
for (Siege siegeVar : war.getSieges()) {
|
||||
for (@NotNull Siege siegeVar : war.getSieges()) {
|
||||
if (siegeVar.getTown().getUUID().equals(town.getUUID())) {
|
||||
siege = siegeVar;
|
||||
break;
|
||||
@@ -261,59 +263,59 @@ public class SiegeCommand {
|
||||
}
|
||||
|
||||
if (siege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid siege").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid siege").build());
|
||||
|
||||
OfflinePlayer oPlayer = siege.getSiegeLeader();
|
||||
@NotNull OfflinePlayer oPlayer = siege.getSiegeLeader();
|
||||
if (oPlayer != p) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not the leader of this siege.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You are not the leader of this siege.").build());
|
||||
}
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been abandoned.").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been abandoned.").build());
|
||||
// Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
|
||||
siege.defendersWin();
|
||||
}
|
||||
|
||||
private static void siegeList(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<War> wars = WarManager.getInstance().getWars();
|
||||
private static void siegeList(@NotNull Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
@NotNull Set<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
Set<Siege> sieges = new HashSet<>();
|
||||
@NotNull Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
for (War war : wars) {
|
||||
for (@NotNull War war : wars) {
|
||||
sieges.addAll(war.getSieges());
|
||||
}
|
||||
|
||||
if (sieges.isEmpty())
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress.").build());
|
||||
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
War war = siege.getWar();
|
||||
for (@NotNull Siege siege : sieges) {
|
||||
@NotNull War war = siege.getWar();
|
||||
|
||||
final String color = (siege.getSide1AreAttackers() && (war.getTownSide(siege.getTown()).getTeam().equals(BattleTeam.SIDE_1))) ? "<red>" : "<blue>";
|
||||
final @NotNull String color = (siege.getSide1AreAttackers() && (war.getTownSide(siege.getTown()).getTeam().equals(BattleTeam.SIDE_1))) ? "<red>" : "<blue>";
|
||||
|
||||
sender.sendMessage(
|
||||
new ColorParser(
|
||||
ColorParser.of(
|
||||
color + siege.getTown().getName() + " <gray>- Progress: <progress> - Time: <time>min"
|
||||
)
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutes()))
|
||||
.build()
|
||||
);
|
||||
// sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); // TODO Fix info
|
||||
// sender.sendMessage(new ColorParser(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints())).build());
|
||||
// sender.sendMessage(new ColorParser(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints())).build());
|
||||
// sender.sendMessage(new ColorParser("Time Left: " + (siege.getMaxSiegeTicks() - siege.getSiegeTicks()) / 1200 + " minutes").build());
|
||||
// sender.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
// sender.sendMessage(ColorParser.of(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); // TODO Fix info
|
||||
// sender.sendMessage(ColorParser.of(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints())).build());
|
||||
// sender.sendMessage(ColorParser.of(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints())).build());
|
||||
// sender.sendMessage(ColorParser.of("Time Left: " + (siege.getMaxSiegeTicks() - siege.getSiegeTicks()) / 1200 + " minutes").build());
|
||||
// sender.sendMessage(ColorParser.of("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
}
|
||||
}
|
||||
|
||||
private static void siegeHelp(Player sender, CommandArguments args) {
|
||||
private static void siegeHelp(@NotNull Player sender, CommandArguments args) {
|
||||
if (sender.hasPermission("AlathranWars.admin")) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege stop [war] [town]").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "/siege stop [war] [town]").build());
|
||||
}
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege start [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege abandon [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege list").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "/siege start [war] [town]").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "/siege abandon [war] [town]").build());
|
||||
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "/siege list").build());
|
||||
}
|
||||
}
|
||||
+60
-58
@@ -23,11 +23,13 @@ import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WarCommand {
|
||||
public WarCommand() {
|
||||
@@ -43,7 +45,7 @@ public class WarCommand {
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
@@ -52,8 +54,8 @@ public class WarCommand {
|
||||
return new CommandAPICommand("create")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.customTownAndNationsArgument("side1", "war", false),
|
||||
CommandUtil.customTownAndNationsArgument("side2", "war", false),
|
||||
CommandUtil.customTownAndNationArgument("side1", "war", false),
|
||||
CommandUtil.customTownAndNationArgument("side2", "war", false),
|
||||
new GreedyStringArgument("warlabel")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||
@@ -114,15 +116,15 @@ public class WarCommand {
|
||||
.executesPlayer(WarCommand::warHelp);
|
||||
}
|
||||
|
||||
protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("warlabel") instanceof final String argLabel))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war label.").build());
|
||||
protected static void warCreate(CommandSender p, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("warlabel") instanceof final @NotNull String argLabel))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war label.").build());
|
||||
|
||||
if (Objects.equals(args.get("side1"), args.get("side2")))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
||||
|
||||
String townName1 = (String) args.get("side1");
|
||||
String townName2 = (String) args.get("side2");
|
||||
@Nullable UUID townName1 = (UUID) args.get("side1");
|
||||
@Nullable UUID townName2 = (UUID) args.get("side2");
|
||||
|
||||
// Create new war depending on what argument was specified
|
||||
@Nullable Town town1 = TownyAPI.getInstance().getTown(townName1);
|
||||
@@ -173,30 +175,30 @@ public class WarCommand {
|
||||
|
||||
}
|
||||
|
||||
private static void warDelete(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
private static void warDelete(Player p, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
@Nullable War war = (War) args.get("war");
|
||||
|
||||
war.draw();
|
||||
// Main.warLogger.log(p.getName() + " deleted " + argWarName);
|
||||
}
|
||||
|
||||
protected static void warJoinPlayer(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
protected static void warJoinPlayer(Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
if (!(args.get("side") instanceof final Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
if (!(args.get("side") instanceof final @NotNull Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
if (war.isPlayerInWar(argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
||||
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||
side.addPlayer(argPlayer);
|
||||
PlayerJoinListener.checkPlayer(argPlayer);
|
||||
for (Siege siege : war.getSieges()) {
|
||||
for (@NotNull Siege siege : war.getSieges()) {
|
||||
if (siege.getAttackerSide().equals(side)) {
|
||||
siege.addPlayer(argPlayer, BattleSide.ATTACKER);
|
||||
} else {
|
||||
@@ -210,23 +212,23 @@ public class WarCommand {
|
||||
* @param args
|
||||
* @param admin - admin behavior
|
||||
*/
|
||||
protected static void warJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
protected static void warJoin(@NotNull Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
if (!(args.get("side") instanceof final Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
if (!(args.get("side") instanceof final @NotNull Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
// Towny Resident Object, if admin then dont use command runner, use declared player
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
@Nullable Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(ChatColor.RED + "You are not in a town.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(ChatColor.RED + "You are not in a town.").build());
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
@@ -271,7 +273,7 @@ public class WarCommand {
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + side.getName() + "!");
|
||||
} else {
|
||||
// Cannot declare nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (res.getPlayer().hasPermission("AlathranWars.townjoin") || res.isMayor()) {
|
||||
@@ -282,88 +284,88 @@ public class WarCommand {
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + side.getName() + "!");
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void warSurrender(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
protected static void warSurrender(@NotNull Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
@Nullable War war = (War) args.get("war");
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
// Towny Resident Object
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
if (res == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>Resident invalid.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Resident invalid.").build());
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
@Nullable Town town = res.getTownOrNull();
|
||||
if (town == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>You are not in a town.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in a town.").build());
|
||||
|
||||
Side side = war.getTownSide(town);
|
||||
@Nullable Side side = war.getTownSide(town);
|
||||
if (side == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>You are not in the war.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in the war.").build());
|
||||
|
||||
final Nation resNation = res.getNationOrNull();
|
||||
final Town resTown = res.getTownOrNull();
|
||||
final @Nullable Nation resNation = res.getNationOrNull();
|
||||
final @Nullable Town resTown = res.getTownOrNull();
|
||||
|
||||
if (resNation != null) {
|
||||
if (p.hasPermission("AlathranWars.nationsurrender") || res.isKing() || admin) {
|
||||
// Has nation surrender permission
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have surrendered the war for " + resNation.getName() + ".").build());
|
||||
Bukkit.broadcast(new ColorParser(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());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The nation of " + resNation.getName() + " has surrendered!").build());
|
||||
side.surrenderNation(resNation);
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// Cannot surrender nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your nation.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender war for your nation.").build());
|
||||
}
|
||||
} else if (resTown != null) {
|
||||
if (p.hasPermission("AlathranWars.townsurrender") || res.isMayor() || admin) {
|
||||
// Is in indepdenent town & has surrender perms
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
||||
side.surrenderTown(resTown);
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void warList(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<War> wars = WarManager.getInstance().getWars();
|
||||
private static void warList(@NotNull Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
@NotNull Set<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
if (wars.isEmpty()) {
|
||||
p.sendMessage(new ColorParser("There are no wars at the moment, the world is at peace.").build());
|
||||
p.sendMessage(ColorParser.of("There are no wars at the moment, the world is at peace.").build());
|
||||
} else {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Wars:").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Wars:").build());
|
||||
|
||||
for (War war : wars) {
|
||||
p.sendMessage(new ColorParser(war.getName() + " - " + war.getSide1().getName() + " (" + war.getSide1().getScore() + ") vs. " + war.getSide2().getName() + " (" + war.getSide2().getScore() + ")").build());
|
||||
for (@NotNull War war : wars) {
|
||||
p.sendMessage(ColorParser.of(war.getName() + " - " + war.getSide1().getName() + " (" + war.getSide1().getScore() + ") vs. " + war.getSide2().getName() + " (" + war.getSide2().getScore() + ")").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*private static void warInfo(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (args.count() < 1) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/war info [Player]").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "/war info [Player]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("player") instanceof Player argsPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Specify a player.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("Specify a player.").build());
|
||||
|
||||
Resident res = TownyAPI.getInstance().getResident(argsPlayer);
|
||||
if (res == null || res.getTownOrNull() == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid town resident.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid town resident.").build());
|
||||
}
|
||||
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + p.getName() + "'s wars:").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + p.getName() + "'s wars:").build());
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
TownWarState side = war.getState(res.getTownOrNull());
|
||||
if (side != TownWarState.NOT_PARTICIPANT) {
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,8 @@
|
||||
package com.github.alathra.AlathranWars;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -8,9 +10,9 @@ import java.util.Date;
|
||||
|
||||
public class AlathranWarsLogger {
|
||||
|
||||
final File logsFolder;
|
||||
final File log;
|
||||
PrintWriter output = null;
|
||||
final @NotNull File logsFolder;
|
||||
final @NotNull File log;
|
||||
@Nullable PrintWriter output = null;
|
||||
|
||||
public AlathranWarsLogger() {
|
||||
logsFolder = new File("plugins" + File.separator + "AlathranWars" + File.separator + "logs");
|
||||
@@ -35,10 +37,10 @@ public class AlathranWarsLogger {
|
||||
private void initFileWriter() {
|
||||
// init file writer
|
||||
try {
|
||||
FileWriter fw = new FileWriter(
|
||||
@NotNull FileWriter fw = new FileWriter(
|
||||
"plugins" + File.separator + "AlathranWars" + File.separator + "logs" + File.separator + "log.txt",
|
||||
true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
@NotNull BufferedWriter bw = new BufferedWriter(fw);
|
||||
output = new PrintWriter(bw);
|
||||
} catch (IOException e1) {
|
||||
Bukkit.getLogger().warning("[AlathranWars] Error in AlathranWarsLogger - could not initialize file writer");
|
||||
@@ -52,9 +54,9 @@ public class AlathranWarsLogger {
|
||||
}
|
||||
|
||||
initFileWriter();
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
||||
String logMsg = "[" + format.format(date) + "] " + msg;
|
||||
@NotNull Date date = new Date();
|
||||
@NotNull SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
||||
@NotNull String logMsg = "[" + format.format(date) + "] " + msg;
|
||||
output.println(logMsg);
|
||||
output.close();
|
||||
}
|
||||
|
||||
@@ -12,11 +12,12 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
public static Economy econ;
|
||||
public static @Nullable Economy econ;
|
||||
public static AlathranWarsLogger warLogger;
|
||||
private static Main instance;
|
||||
private static @Nullable Main instance;
|
||||
|
||||
static {
|
||||
instance = null;
|
||||
@@ -67,7 +68,7 @@ public class Main extends JavaPlugin {
|
||||
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked") final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
|
||||
@SuppressWarnings("unchecked") final @Nullable RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
|
||||
.getServicesManager().getRegistration((Class) Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
|
||||
@@ -19,10 +19,10 @@ public class CommandManager {
|
||||
CommandAPI.onEnable();
|
||||
|
||||
// Register commands
|
||||
new WarCommand();
|
||||
new SiegeCommand();
|
||||
new WarCommands();
|
||||
new SiegeCommands();
|
||||
// new RaidCommand();
|
||||
new AdminCommand();
|
||||
// new AdminCommand();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
|
||||
import com.github.alathra.AlathranWars.enums.CommandArgsWar;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.hooks.TownyHook;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
@@ -14,23 +16,28 @@ 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.TownyObject;
|
||||
import dev.jorel.commandapi.SuggestionInfo;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.CustomArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CommandUtil {
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsSiege.*;
|
||||
|
||||
public class CommandUtil {
|
||||
/*public Argument<World> customWorldArgument(String nodeName) {
|
||||
|
||||
// Construct our CustomArgument that takes in a String input and returns a World object
|
||||
@@ -54,11 +61,11 @@ public class CommandUtil {
|
||||
final String argNationName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getNation(argNationName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
return TownyAPI.getInstance().getNation(argNationName);
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nationNames = TownyHook.getNations()
|
||||
final @NotNull List<String> nationNames = TownyHook.getNations()
|
||||
.stream()
|
||||
.map(Nation::getName)
|
||||
.sorted()
|
||||
@@ -73,11 +80,11 @@ public class CommandUtil {
|
||||
final String argTownName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getTown(argTownName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
return TownyAPI.getInstance().getTown(argTownName);
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> townNames = TownyHook.getTowns()
|
||||
final @NotNull List<String> townNames = TownyHook.getTowns()
|
||||
.stream()
|
||||
.map(Town::getName)
|
||||
.sorted()
|
||||
@@ -92,28 +99,28 @@ public class CommandUtil {
|
||||
final String argNationName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getNation(argNationName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
if (!hideNationsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return TownyAPI.getInstance().getNation(argNationName);
|
||||
|
||||
Nation nation = TownyAPI.getInstance().getNation(argNationName);
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(argNationName);
|
||||
|
||||
if (war.getNations().contains(nation) || war.getSurrenderedNations().contains(nation))
|
||||
return nation;
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation is already at war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation is already at war!").parseLegacy().build());
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nationNames = TownyHook.getNations()
|
||||
final @NotNull List<String> nationNames = TownyHook.getNations()
|
||||
.stream()
|
||||
.map(Nation::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
final List<String> townNames = TownyHook.getTowns()
|
||||
final @NotNull List<String> townNames = TownyHook.getTowns()
|
||||
.stream()
|
||||
.map(Town::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
nationNames.addAll(townNames);
|
||||
|
||||
@@ -121,7 +128,7 @@ public class CommandUtil {
|
||||
if (!hideNationsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return nationNames;
|
||||
|
||||
final List<String> removeNames = Stream.concat( // Create a list of all nations in war
|
||||
final @NotNull List<String> removeNames = Stream.concat( // Create a list of all nations in war
|
||||
war.getNations().stream().map(Nation::getName),
|
||||
war.getSurrenderedNations().stream().map(Nation::getName)
|
||||
).toList();
|
||||
@@ -137,19 +144,19 @@ public class CommandUtil {
|
||||
final String argTownName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getTown(argTownName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return TownyAPI.getInstance().getTown(argTownName);
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown(argTownName);
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(argTownName);
|
||||
|
||||
if (war.getTowns().contains(town) || war.getSurrenderedTowns().contains(town))
|
||||
return town;
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is already at war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is already at war!").parseLegacy().build());
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> townNames = TownyHook.getTowns()
|
||||
final @NotNull List<String> townNames = TownyHook.getTowns()
|
||||
.stream()
|
||||
.map(Town::getName)
|
||||
.sorted()
|
||||
@@ -159,7 +166,7 @@ public class CommandUtil {
|
||||
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return townNames;
|
||||
|
||||
final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
|
||||
final @NotNull List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
|
||||
war.getTowns().stream().map(Town::getName),
|
||||
war.getSurrenderedTowns().stream().map(Town::getName)
|
||||
).toList();
|
||||
@@ -173,15 +180,15 @@ public class CommandUtil {
|
||||
static public Argument<Nation> customNationInWarArgument(String nodeName, String warNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Nation nation = TownyAPI.getInstance().getNation(info.input());
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(info.input());
|
||||
|
||||
if (nation == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isNationInWar(nation))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation is not in that war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation is not in that war!").parseLegacy().build());
|
||||
|
||||
return nation;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -198,15 +205,15 @@ public class CommandUtil {
|
||||
static public Argument<Town> customTownInWarArgument(String nodeName, String warNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
|
||||
if (town == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isTownInWar(town))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
|
||||
return town;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -227,33 +234,38 @@ public class CommandUtil {
|
||||
* @param nodeName the node name
|
||||
* @param warNodeName the war node name
|
||||
* @param hideTownsInWar the hide towns in war
|
||||
* @return the argument
|
||||
* @return the town or nation UUID
|
||||
*/
|
||||
static public Argument<String> customTownAndNationsArgument(String nodeName, String warNodeName, boolean hideTownsInWar) {
|
||||
static public Argument<UUID> customTownAndNationArgument(String nodeName, String warNodeName, boolean hideTownsInWar) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
final String argTownOrNationName = info.input();
|
||||
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(argTownOrNationName);
|
||||
|
||||
if (town != null)
|
||||
return town.getName();
|
||||
return town.getUUID();
|
||||
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(argTownOrNationName);
|
||||
if (nation != null)
|
||||
return nation.getName();
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town or nation does not exist!").parseLegacy().build());
|
||||
if (nation != null)
|
||||
return nation.getUUID();
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(
|
||||
ColorParser.of(UtilsChat.getPrefix() + "<red>The town or nation <name> does not exist!")
|
||||
.parseMinimessagePlaceholder("name", argTownOrNationName)
|
||||
.build()
|
||||
);
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nationNames = TownyHook.getNations()
|
||||
final @NotNull List<String> nationNames = TownyHook.getNations()
|
||||
.stream()
|
||||
.map(Nation::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
final List<String> townNames = TownyHook.getTowns()
|
||||
final @NotNull List<String> townNames = TownyHook.getTowns()
|
||||
.stream()
|
||||
.map(Town::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
nationNames.addAll(townNames);
|
||||
|
||||
@@ -261,7 +273,7 @@ public class CommandUtil {
|
||||
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return nationNames;
|
||||
|
||||
final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
|
||||
final @NotNull List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
|
||||
war.getNations().stream().map(Nation::getName),
|
||||
Stream.concat(
|
||||
war.getSurrenderedNations().stream().map(Nation::getName),
|
||||
@@ -278,51 +290,23 @@ public class CommandUtil {
|
||||
}));
|
||||
}
|
||||
|
||||
/*static public Argument<String> warSideCreateArgument(String nodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
final String argSideName = info.input();
|
||||
|
||||
return argSideName;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<Nation> nations = TownyHook.getNations();
|
||||
final List<Town> towns = TownyHook.getTowns();
|
||||
|
||||
final List<String> nationNames = new ArrayList<>();
|
||||
final List<String> townNames = new ArrayList<>();
|
||||
|
||||
for (Nation nation : nations)
|
||||
nationNames.add(nation.getName());
|
||||
|
||||
for (Town town : towns)
|
||||
townNames.add(town.getName());
|
||||
|
||||
Collections.sort(nationNames);
|
||||
Collections.sort(townNames);
|
||||
nationNames.addAll(townNames);
|
||||
|
||||
return nationNames;
|
||||
}));
|
||||
}*/
|
||||
|
||||
public static Argument<Town> customSiegeAttackableTownArgument(String nodeName, String warNodeName, final boolean checkIfIn, final boolean checkIfSieged) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
|
||||
if (town == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isTownInWar(town))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
|
||||
if (checkIfSieged) {
|
||||
for (War war2 : WarManager.getInstance().getWars()) {
|
||||
for (Siege siege : war2.getSieges()) {
|
||||
if (siege.getTown().getUUID() == town.getUUID())
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is already under siege!").parseLegacy().build());
|
||||
}
|
||||
for (@NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown().getUUID() == town.getUUID())
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is already under siege!").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +315,7 @@ public class CommandUtil {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return Collections.emptyList();
|
||||
|
||||
final List<String> townNames = new ArrayList<>();
|
||||
final @NotNull List<String> townNames = new ArrayList<>();
|
||||
|
||||
if (info.sender() instanceof Player p) {
|
||||
if (war.getSide1().isPlayerOnSide(p)) {
|
||||
@@ -339,14 +323,14 @@ public class CommandUtil {
|
||||
.stream()
|
||||
.map(TownyObject::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
.toList()
|
||||
);
|
||||
} else if (war.getSide2().isPlayerOnSide(p)) {
|
||||
townNames.addAll(war.getSide1().getTowns()
|
||||
.stream()
|
||||
.map(TownyObject::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -355,88 +339,211 @@ public class CommandUtil {
|
||||
}));
|
||||
}
|
||||
|
||||
public static Argument<Siege> siegeSiegeArgument(String nodeName, final boolean isAdmin, final CommandArgsSiege checkSiege, final String playerNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
final String argSiegeName = info.input();
|
||||
|
||||
public static Argument<War> warWarArgument(String nodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
|
||||
@Nullable UUID siegeUUID = null;
|
||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getName().equals(argSiegeName)) {
|
||||
siegeUUID = siege.getUUID();
|
||||
}
|
||||
}
|
||||
|
||||
final @Nullable Siege siege = WarManager.getInstance().getSiege(siegeUUID);
|
||||
if (siege == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The siege <siege> does not exist!").parseMinimessagePlaceholder("siege", argSiegeName).build());
|
||||
|
||||
switch (checkSiege) {
|
||||
case IN_SIEGE -> {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player does not exist!").build());
|
||||
|
||||
if (!siege.isPlayerInSiege(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player is already in that war.").build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").build());
|
||||
|
||||
if (!siege.isPlayerInSiege(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
||||
}
|
||||
}
|
||||
case OUT_SIEGE -> {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player does not exist!").build());
|
||||
|
||||
if (siege.isPlayerInSiege(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player is not in that war.").build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").build());
|
||||
|
||||
if (siege.isPlayerInSiege(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are not in that war.").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return siege;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> switch (checkSiege) {
|
||||
case ALL_SIEGES -> siegeAll(info, isAdmin);
|
||||
case IN_SIEGE -> siegeInside(info, isAdmin, playerNodeName);
|
||||
case OUT_SIEGE -> siegeOutside(info, isAdmin, playerNodeName);
|
||||
}));
|
||||
}
|
||||
|
||||
private static List<String> siegeAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) {
|
||||
return WarManager.getInstance().getSieges().stream().map(Siege::getName).toList();
|
||||
}
|
||||
|
||||
private static List<String> siegeOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
|
||||
List<String> siegeNames = new ArrayList<>();
|
||||
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
|
||||
}
|
||||
}
|
||||
|
||||
return siegeNames;
|
||||
}
|
||||
|
||||
private static List<String> siegeInside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
|
||||
List<String> siegeNames = new ArrayList<>();
|
||||
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
|
||||
}
|
||||
}
|
||||
|
||||
return siegeNames;
|
||||
}
|
||||
|
||||
public static Argument<War> warWarArgument(String nodeName, final boolean isAdmin, final CommandArgsWar checkWar, final String playerNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
final String argWarName = info.input();
|
||||
|
||||
final War war = WarManager.getInstance().getWar(argWarName);
|
||||
final @Nullable War war = WarManager.getInstance().getWar(argWarName);
|
||||
if (war == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war <war> does not exist!").parseLegacy().parseMinimessagePlaceholder("war", argWarName).build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war <war> does not exist!").parseMinimessagePlaceholder("war", argWarName).build());
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
switch (checkWar) {
|
||||
case IN_WAR -> {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player is already in that war.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
if (!war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player is already in that war.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already in this war.").parseLegacy().build());
|
||||
if (!war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
case OUT_WAR -> {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player is not in that war.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are not in that war.").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return war;
|
||||
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> warNames = new ArrayList<>();
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
for (String name : WarManager.getInstance().getWarNames()) {
|
||||
if (WarManager.getInstance().getWar(name) != null && !WarManager.getInstance().getWar(name).isPlayerInWar(player))
|
||||
warNames.add(name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
for (String name : WarManager.getInstance().getWarNames()) {
|
||||
if (WarManager.getInstance().getWar(name) != null && !WarManager.getInstance().getWar(name).isPlayerInWar(player))
|
||||
warNames.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warNames.addAll(WarManager.getInstance().getWarNames());
|
||||
}
|
||||
|
||||
return warNames;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> switch (checkWar) {
|
||||
case ALL_WARS -> warsAll(info, isAdmin);
|
||||
case IN_WAR -> warsInside(info, isAdmin, playerNodeName);
|
||||
case OUT_WAR -> warsOutside(info, isAdmin, playerNodeName);
|
||||
}));
|
||||
}
|
||||
|
||||
private static List<String> warsAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) {
|
||||
return WarManager.getInstance().getWarNames();
|
||||
}
|
||||
|
||||
private static List<String> warsOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
|
||||
List<String> warNames = new ArrayList<>();
|
||||
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
warNames = WarManager.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
warNames = WarManager.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
|
||||
}
|
||||
}
|
||||
|
||||
return warNames;
|
||||
}
|
||||
|
||||
private static List<String> warsInside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
|
||||
List<String> warNames = new ArrayList<>();
|
||||
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
warNames = WarManager.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
warNames = WarManager.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
|
||||
}
|
||||
}
|
||||
|
||||
return warNames;
|
||||
}
|
||||
|
||||
public static Argument<Side> warSideCreateArgument(final String nodeName, final String warNodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").parseLegacy().build());
|
||||
|
||||
final String argSideName = info.input();
|
||||
|
||||
if (!war.isSideValid(argSideName))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The side does not exist.").parseLegacy().build());
|
||||
|
||||
final Side side = war.getSide(argSideName);
|
||||
final @Nullable Side side = war.getSide(argSideName);
|
||||
|
||||
if (side == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side is invalid.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The side is invalid.").parseLegacy().build());
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
|
||||
if (side.getPlayers().contains(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player is already on that side.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The player is already on that side.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
|
||||
if (side.getPlayers().contains(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already on that side.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already on that side.").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,19 +552,19 @@ public class CommandUtil {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return Collections.emptyList();
|
||||
|
||||
final List<String> sideNames = new ArrayList<>();
|
||||
final @NotNull List<String> sideNames = new ArrayList<>();
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
|
||||
for (Side side : war.getSides()) {
|
||||
for (@NotNull Side side : war.getSides()) {
|
||||
if (!side.getPlayers().contains(player))
|
||||
sideNames.add(side.getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (info.sender() instanceof Player player) {
|
||||
for (Side side : war.getSides()) {
|
||||
for (@NotNull Side side : war.getSides()) {
|
||||
if (!side.getPlayers().contains(player))
|
||||
sideNames.add(side.getName());
|
||||
}
|
||||
@@ -478,7 +585,7 @@ public class CommandUtil {
|
||||
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
|
||||
*/
|
||||
public static int isPlayerMinuteman(String player) {
|
||||
Resident res = TownyAPI.getInstance().getResident(player);
|
||||
@Nullable Resident res = TownyAPI.getInstance().getResident(player);
|
||||
if (res != null) {
|
||||
//getInstance registration time
|
||||
long regTime = res.getRegistered();
|
||||
@@ -505,7 +612,7 @@ public class CommandUtil {
|
||||
*
|
||||
* @return list of all alathranwars items namespaced
|
||||
*/
|
||||
public static List<String> getWarItems() {
|
||||
public static @NotNull List<String> getWarItems() {
|
||||
return new ArrayList<>(WarItemRegistry.getInstance().getItemRegistry().keySet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsSiege.ALL_SIEGES;
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsSiege.IN_SIEGE;
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsWar.ALL_WARS;
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsWar.IN_WAR;
|
||||
|
||||
public class SiegeCommands {
|
||||
public SiegeCommands() {
|
||||
new CommandAPICommand("siege")
|
||||
.withSubcommands(
|
||||
commandStart(false),
|
||||
commandStop(false),
|
||||
commandAbandon(false),
|
||||
commandSurrender(false),
|
||||
commandList()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStart(boolean asAdmin) {
|
||||
return new CommandAPICommand("start")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument(
|
||||
"war",
|
||||
asAdmin,
|
||||
asAdmin ? ALL_WARS : IN_WAR,
|
||||
""
|
||||
),
|
||||
CommandUtil.customSiegeAttackableTownArgument(
|
||||
"town",
|
||||
"war",
|
||||
false,
|
||||
true
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(!asAdmin)
|
||||
.withPermission("AlathranWars.admin")/*,
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathranWars.admin")*/
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStop(boolean asAdmin) {
|
||||
return new CommandAPICommand("stop")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.siegeSiegeArgument("siege", asAdmin, asAdmin ? ALL_SIEGES : IN_SIEGE, "player")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeStop(p, args, asAdmin));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandAbandon(boolean asAdmin) {
|
||||
return new CommandAPICommand("abandon")
|
||||
.withArguments(
|
||||
CommandUtil.siegeSiegeArgument("siege", asAdmin, asAdmin ? ALL_SIEGES : IN_SIEGE, "player")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeAbandon(p, args, asAdmin));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandSurrender(boolean asAdmin) {
|
||||
return new CommandAPICommand("surrender")
|
||||
.withArguments(
|
||||
CommandUtil.siegeSiegeArgument("siege", asAdmin, asAdmin ? ALL_SIEGES : IN_SIEGE, "player")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeSurrender(p, args, asAdmin));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(SiegeCommands::siegeList);
|
||||
}
|
||||
|
||||
protected static void siegeStart(@NotNull Player sender, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final @NotNull War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final @NotNull Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
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
|
||||
// @Nullable Town leaderTown = TownyAPI.getInstance().getResident(siegeLeader).getTownOrNull();
|
||||
// @Nullable Side side = war.getTownSide(leaderTown);
|
||||
@Nullable Side side = war.getPlayerSide(siegeLeader);
|
||||
if (side == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You are not in this war.").build());
|
||||
|
||||
if (side.isPlayerSurrendered(siegeLeader))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You have surrendered and cannot participate in this war.").build());
|
||||
|
||||
// Attacking own side
|
||||
if (side.isTownOnSide(town)) {
|
||||
if (admin)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own side.").build());
|
||||
else
|
||||
siegeLeader.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
Siege siege = new Siege(war, town, siegeLeader);
|
||||
|
||||
war.addSiege(siege);
|
||||
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
|
||||
|
||||
siege.start();
|
||||
}
|
||||
|
||||
private static void siegeStop(@NotNull Player sender, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("siege") instanceof final @NotNull Siege siege))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid siege.").build());
|
||||
|
||||
siege.noWinner();
|
||||
}
|
||||
|
||||
private static void siegeAbandon(Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("siege") instanceof final @NotNull Siege siege))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid siege.").build());
|
||||
|
||||
@NotNull OfflinePlayer siegeLeader = siege.getSiegeLeader();
|
||||
if (siegeLeader != p && !admin)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not the leader of this siege.").build());
|
||||
|
||||
Bukkit.broadcast(
|
||||
ColorParser.of("<prefix>The siege at <town> has been abandoned.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("town", siege.getTown().getName())
|
||||
.build()
|
||||
);
|
||||
siege.defendersWin();
|
||||
}
|
||||
|
||||
private static void siegeSurrender(Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("siege") instanceof final @NotNull Siege siege))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid siege.").build());
|
||||
|
||||
Town town = siege.getTown();
|
||||
|
||||
@Nullable Resident res = TownyAPI.getInstance().getResident(p);
|
||||
if (res == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Resident invalid.").build());
|
||||
|
||||
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());
|
||||
|
||||
if (!admin && (!canKingSurrender || !canMayorSurrender))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender this town.").build());
|
||||
|
||||
Bukkit.broadcast(
|
||||
ColorParser.of("<prefix>The town of <town> has surrendered.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("town", siege.getTown().getName())
|
||||
.build()
|
||||
);
|
||||
siege.attackersWin();
|
||||
}
|
||||
|
||||
private static void siegeList(@NotNull Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<Siege> sieges = WarManager.getInstance().getSieges();
|
||||
|
||||
if (sieges.isEmpty()) {
|
||||
sender.sendMessage(ColorParser.of("<red>There are no sieges at the moment.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
msg.append("\n<white><bold>%s<reset>".formatted(siege.getName()));
|
||||
msg.append("\n <grey>Progress: <white>%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100));
|
||||
msg.append("\n <grey>Remaining: <white>%s minutes".formatted(String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutesPart())));
|
||||
msg.append("\n");
|
||||
}
|
||||
|
||||
sender.sendMessage(
|
||||
ColorParser.of(
|
||||
msg.toString()
|
||||
).build()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
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.utility.UtilsChat;
|
||||
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 dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.github.alathra.AlathranWars.enums.CommandArgsWar.*;
|
||||
|
||||
public class WarCommands {
|
||||
public WarCommands() {
|
||||
new CommandAPICommand("war")
|
||||
.withSubcommands(
|
||||
commandCreate(false),
|
||||
commandDelete(false),
|
||||
commandJoin(false),
|
||||
commandSurrender(false),
|
||||
commandList(),
|
||||
commandInfo()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandCreate(boolean asAdmin) {
|
||||
return new CommandAPICommand("create")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.customTownAndNationArgument("side1", "war", false),
|
||||
CommandUtil.customTownAndNationArgument("side2", "war", false),
|
||||
new GreedyStringArgument("warlabel")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||
"Nations War of Conquest",
|
||||
"Nations War for Survival",
|
||||
"Nations War of Liberation"
|
||||
))
|
||||
)
|
||||
)
|
||||
.executesPlayer(WarCommands::warCreate);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandDelete(boolean asAdmin) {
|
||||
return new CommandAPICommand("delete")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", asAdmin, ALL_WARS, "")
|
||||
)
|
||||
.executesPlayer(WarCommands::warDelete);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandJoin(boolean asAdmin) {
|
||||
return new CommandAPICommand("join")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", asAdmin, asAdmin ? ALL_WARS : OUT_WAR, ""),
|
||||
CommandUtil.warSideCreateArgument("side", "war", asAdmin, !asAdmin, ""),
|
||||
new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin.join")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandSurrender(boolean asAdmin) {
|
||||
return new CommandAPICommand("surrender")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", asAdmin, asAdmin ? ALL_WARS : IN_WAR, "player"),
|
||||
new PlayerArgument("player")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathranWars.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warSurrender(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(WarCommands::warList);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandInfo() {
|
||||
return new CommandAPICommand("info")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", false, ALL_WARS, "player")
|
||||
)
|
||||
.executesPlayer(WarCommands::warInfo);
|
||||
}
|
||||
|
||||
protected static void warCreate(CommandSender p, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("warlabel") instanceof final String argLabel))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a war label.").build());
|
||||
|
||||
if (Objects.equals(args.get("side1"), args.get("side2")))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
||||
|
||||
final UUID uuid1 = (UUID) args.get("side1");
|
||||
final UUID uuid2 = (UUID) args.get("side2");
|
||||
|
||||
// Create new war depending on what argument was specified
|
||||
@Nullable Town town1 = TownyAPI.getInstance().getTown(uuid1);
|
||||
@Nullable Town town2 = TownyAPI.getInstance().getTown(uuid2);
|
||||
|
||||
// Automatically escalate to nation level if possible
|
||||
@Nullable Nation nation1 = town1 == null ? TownyAPI.getInstance().getNation(uuid1) : town1.getNationOrNull();
|
||||
@Nullable Nation nation2 = town2 == null ? TownyAPI.getInstance().getNation(uuid2) : town2.getNationOrNull();
|
||||
|
||||
// Implement permission checking here if this is ever going to be exposed to players
|
||||
|
||||
// Create war depending on what args have been passed, attempt to create nation wars first
|
||||
if (nation1 != null) {
|
||||
if (nation2 != null) { // Nation vs Nation
|
||||
|
||||
// Allow civil wars
|
||||
if (nation2.getUUID() != nation1.getUUID()) {
|
||||
new War(argLabel, nation1, nation2);
|
||||
} else {
|
||||
new War(argLabel, town1, town2);
|
||||
}
|
||||
|
||||
} else if (town2 != null) { // Nation vs Town
|
||||
|
||||
new War(argLabel, nation1, town2);
|
||||
|
||||
}
|
||||
} else if (town1 != null) {
|
||||
|
||||
if (town2 != null) { // Town vs Town
|
||||
|
||||
new War(argLabel, town1, town2);
|
||||
|
||||
} else if (nation2 != null) { // Nation vs Town
|
||||
|
||||
new War(argLabel, town1, nation2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void warDelete(Player p, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
if (war == null) return;
|
||||
|
||||
war.draw();
|
||||
}
|
||||
|
||||
protected static void warJoinPlayer(Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
if (war == null) return;
|
||||
|
||||
if (!(args.get("side") instanceof final @NotNull Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
if (war.isPlayerInWar(argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
||||
|
||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||
side.addPlayer(argPlayer);
|
||||
PlayerJoinListener.checkPlayer(argPlayer);
|
||||
for (@NotNull Siege siege : war.getSieges()) {
|
||||
if (siege.getAttackerSide().equals(side)) {
|
||||
siege.addPlayer(argPlayer, BattleSide.ATTACKER);
|
||||
} else {
|
||||
siege.addPlayer(argPlayer, BattleSide.DEFENDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void warSurrender(@NotNull Player p, @NotNull CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
if (war == null) return;
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
// Towny Resident Object
|
||||
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
if (res == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Resident invalid.").build());
|
||||
|
||||
// Town check
|
||||
@Nullable Town town = res.getTownOrNull();
|
||||
if (town == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in a town.").build());
|
||||
|
||||
@Nullable Side side = war.getTownSide(town);
|
||||
if (side == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in that war.").build());
|
||||
|
||||
final @Nullable Nation resNation = res.getNationOrNull();
|
||||
final @Nullable Town resTown = res.getTownOrNull();
|
||||
|
||||
// TODO Test if resTown is reached
|
||||
if (resNation != null) {
|
||||
if (p.hasPermission("AlathranWars.nationsurrender") || res.isKing() || admin) {
|
||||
// Has nation surrender permission
|
||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resNation.getName() + ".").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The nation of " + resNation.getName() + " has surrendered!").build());
|
||||
side.surrenderNation(resNation);
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// Cannot surrender nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender for your nation.").build());
|
||||
}
|
||||
} else if (resTown != null) {
|
||||
if (p.hasPermission("AlathranWars.townsurrender") || res.isMayor() || admin) {
|
||||
// Is in indepdenent town & has surrender perms
|
||||
argPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
||||
side.surrenderTown(resTown); // TODO Process siege surrender here as well
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warList(@NotNull Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
if (wars.isEmpty()) {
|
||||
p.sendMessage(ColorParser.of("<red>There are no wars at the moment, the world is at peace.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
|
||||
for (War war : wars) {
|
||||
msg.append("\n<white><bold>%s<reset>".formatted(war.getLabel()));
|
||||
msg.append("\n <grey>Sides: <white>%s <grey>vs <white>%s".formatted(war.getSide1().getName(), war.getSide2().getName()));
|
||||
msg.append("\n <grey>Score: <white>%s <grey>vs <white>%s".formatted(war.getSide1().getScore(), war.getSide2().getScore()));
|
||||
msg.append("\n");
|
||||
}
|
||||
|
||||
p.sendMessage(
|
||||
ColorParser.of(
|
||||
msg.toString()
|
||||
).build()
|
||||
);
|
||||
}
|
||||
|
||||
private static void warInfo(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
if (war == null) return;
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
|
||||
for (Side side : war.getSides()) {
|
||||
msg.append("\n<white><bold>%s<reset>".formatted(side.getName()));
|
||||
msg.append("\n <grey>Score: <green>%s".formatted(side.getScore()));
|
||||
msg.append("\n <grey>Nations: <green>%s<grey>/<red>%s".formatted(side.getNations().size(), side.getNations().size() + side.getSurrenderedNations().size()));
|
||||
msg.append("\n <grey>Towns: <green>%s<grey>/<red>%s".formatted(side.getTowns().size(), side.getTowns().size() + side.getSurrenderedTowns().size()));
|
||||
msg.append("\n <grey>Players: <green>%s<grey>/<red>%s".formatted(side.getPlayersIncludingOffline().size(), side.getPlayersIncludingOffline().size() + side.getSurrenderedPlayersIncludingOffline().size()));
|
||||
msg.append("\n");
|
||||
}
|
||||
|
||||
p.sendMessage(
|
||||
ColorParser.of(
|
||||
msg.toString()
|
||||
).build()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@@ -32,7 +33,7 @@ public class Side {
|
||||
private final Set<Town> towns; // A list of participating Towns
|
||||
private final Set<Nation> nations; // A list of participating Nations
|
||||
private final Set<UUID> playersIncludingOffline; // A list of all participating player UUID, (Online & Offline)
|
||||
private final Set<Player> players; // A list of the players who are currently online
|
||||
private final @NotNull Set<Player> players; // A list of the players who are currently online
|
||||
private final Set<Town> surrenderedTowns;
|
||||
private final Set<Nation> surrenderedNations;
|
||||
private final Set<UUID> surrenderedPlayersIncludingOffline;
|
||||
@@ -102,7 +103,7 @@ public class Side {
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
public Side(UUID warUUID, UUID uuid, Nation nation, BattleSide side, BattleTeam team) {
|
||||
public Side(UUID warUUID, UUID uuid, @NotNull Nation nation, BattleSide side, BattleTeam team) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = uuid;
|
||||
this.side = side;
|
||||
@@ -148,7 +149,7 @@ public class Side {
|
||||
return playersIncludingOffline;
|
||||
}
|
||||
|
||||
public Set<Player> getPlayers() {
|
||||
public @NotNull Set<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ public class Side {
|
||||
return surrenderedNations.contains(nation);
|
||||
}
|
||||
|
||||
public void addTown(Town town) {
|
||||
public void addTown(@NotNull Town town) {
|
||||
if (isTownOnSide(town)) return;
|
||||
|
||||
towns.add(town);
|
||||
@@ -190,7 +191,7 @@ public class Side {
|
||||
town.getResidents().forEach((Resident resident) -> addPlayer(resident.getUUID()));
|
||||
}
|
||||
|
||||
public void addNation(Nation nation) {
|
||||
public void addNation(@NotNull Nation nation) {
|
||||
if (isNationOnSide(nation)) return;
|
||||
|
||||
nations.add(nation);
|
||||
@@ -198,7 +199,7 @@ public class Side {
|
||||
nation.getTowns().forEach(this::addTown);
|
||||
}
|
||||
|
||||
public void removeTown(Town town) {
|
||||
public void removeTown(@NotNull Town town) {
|
||||
if (!isTownOnSide(town)) return;
|
||||
|
||||
towns.remove(town);
|
||||
@@ -206,7 +207,7 @@ public class Side {
|
||||
town.getResidents().forEach((Resident resident) -> removePlayer(resident.getUUID()));
|
||||
}
|
||||
|
||||
public void removeNation(Nation nation) {
|
||||
public void removeNation(@NotNull Nation nation) {
|
||||
if (!isNationOnSide(nation)) return;
|
||||
|
||||
nations.remove(nation);
|
||||
@@ -214,7 +215,7 @@ public class Side {
|
||||
nation.getTowns().forEach(this::removeTown);
|
||||
}
|
||||
|
||||
public void surrenderTown(Town town) {
|
||||
public void surrenderTown(@NotNull Town town) {
|
||||
if (isTownSurrendered(town)) return;
|
||||
|
||||
removeTown(town);
|
||||
@@ -224,7 +225,7 @@ public class Side {
|
||||
town.getResidents().forEach((Resident resident) -> surrenderPlayer(resident.getUUID()));
|
||||
}
|
||||
|
||||
public void surrenderNation(Nation nation) {
|
||||
public void surrenderNation(@NotNull Nation nation) {
|
||||
if (isNationSurrendered(nation)) return;
|
||||
|
||||
removeNation(nation);
|
||||
@@ -234,7 +235,7 @@ public class Side {
|
||||
nation.getTowns().forEach(this::surrenderTown);
|
||||
}
|
||||
|
||||
public boolean isPlayerOnSide(Player p) {
|
||||
public boolean isPlayerOnSide(@NotNull Player p) {
|
||||
return isPlayerOnSide(p.getUniqueId());
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ public class Side {
|
||||
return playersIncludingOffline.contains(uuid) || surrenderedPlayersIncludingOffline.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isPlayerSurrendered(Player p) {
|
||||
public boolean isPlayerSurrendered(@NotNull Player p) {
|
||||
return isPlayerSurrendered(p.getUniqueId());
|
||||
}
|
||||
|
||||
@@ -250,22 +251,22 @@ public class Side {
|
||||
return surrenderedPlayersIncludingOffline.contains(uuid);
|
||||
}
|
||||
|
||||
public void addPlayer(Player p) {
|
||||
public void addPlayer(@NotNull Player p) {
|
||||
addPlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(OfflinePlayer offlinePlayer) {
|
||||
public void addPlayer(@NotNull OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
addPlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid) {
|
||||
public void addPlayer(@NotNull UUID uuid) {
|
||||
if (isPlayerOnSide(uuid)) return;
|
||||
|
||||
playersIncludingOffline.add(uuid);
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||
addOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
@@ -274,22 +275,22 @@ public class Side {
|
||||
players.add(p);
|
||||
}
|
||||
|
||||
public void removePlayer(Player p) {
|
||||
public void removePlayer(@NotNull Player p) {
|
||||
removePlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(OfflinePlayer offlinePlayer) {
|
||||
public void removePlayer(@NotNull OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
removePlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
public void removePlayer(@NotNull UUID uuid) {
|
||||
if (!isPlayerOnSide(uuid)) return;
|
||||
|
||||
playersIncludingOffline.remove(uuid);
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||
removeOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
@@ -298,11 +299,11 @@ public class Side {
|
||||
players.remove(p);
|
||||
}
|
||||
|
||||
public void surrenderPlayer(Player p) {
|
||||
public void surrenderPlayer(@NotNull Player p) {
|
||||
surrenderPlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void surrenderPlayer(UUID uuid) {
|
||||
public void surrenderPlayer(@NotNull UUID uuid) {
|
||||
if (isPlayerSurrendered(uuid)) return;
|
||||
|
||||
removePlayer(uuid);
|
||||
@@ -311,7 +312,7 @@ public class Side {
|
||||
}
|
||||
|
||||
public void calculateOnlinePlayers() {
|
||||
final Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
|
||||
final @NotNull Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
|
||||
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -385,11 +386,11 @@ public class Side {
|
||||
return this.uuid.equals(uuid);
|
||||
}
|
||||
|
||||
public boolean equals(War war) {
|
||||
public boolean equals(@NotNull War war) {
|
||||
return this.warUUID.equals(war.getUUID());
|
||||
}
|
||||
|
||||
public boolean equals(Side side) {
|
||||
public boolean equals(@NotNull Side side) {
|
||||
return getUUID().equals(side.getUUID());
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class War extends Conflict {
|
||||
private final String label;
|
||||
private final ConflictType conflictType = ConflictType.WAR;
|
||||
|
||||
private final Side side1;
|
||||
private final @NotNull Side side1;
|
||||
private final Side side2;
|
||||
private final Side attacker; // Reference variable to side1 or side2
|
||||
private final Side defender; // Reference variable to side1 or side2
|
||||
@@ -47,7 +47,7 @@ public class War extends Conflict {
|
||||
UUID uuid,
|
||||
String name,
|
||||
String label,
|
||||
Side side1,
|
||||
@NotNull Side side1,
|
||||
Side side2,
|
||||
Set<Siege> sieges,
|
||||
Set<Raid> raids
|
||||
@@ -75,16 +75,16 @@ public class War extends Conflict {
|
||||
* @param aggressor the side 1
|
||||
* @param victim the side 2
|
||||
*/
|
||||
public War(final String label, Town aggressor, Town victim) throws WrapperCommandSyntaxException {
|
||||
public War(final String label, @NotNull Town aggressor, @NotNull Town victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
final @NotNull UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final @NotNull UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
|
||||
|
||||
@@ -96,16 +96,16 @@ public class War extends Conflict {
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
public War(final String label, @NotNull Nation aggressor, @NotNull Nation victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
final @NotNull UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final @NotNull UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
|
||||
|
||||
@@ -117,16 +117,16 @@ public class War extends Conflict {
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Town aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
public War(final String label, @NotNull Town aggressor, @NotNull Nation victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
final @NotNull UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final @NotNull UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
|
||||
|
||||
@@ -138,16 +138,16 @@ public class War extends Conflict {
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Town victim) throws WrapperCommandSyntaxException {
|
||||
public War(final String label, @NotNull Nation aggressor, @NotNull Town victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>A war already exists with that name!").build());
|
||||
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
final @NotNull UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final @NotNull UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
|
||||
|
||||
@@ -199,7 +199,7 @@ public class War extends Conflict {
|
||||
* @param war the war
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean equals(War war) {
|
||||
public boolean equals(@NotNull War war) {
|
||||
return this.uuid.equals(war.getUUID());
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class War extends Conflict {
|
||||
|
||||
@NotNull
|
||||
public Set<Side> getSides() {
|
||||
final Set<Side> sides = new HashSet<>();
|
||||
final @NotNull Set<Side> sides = new HashSet<>();
|
||||
sides.add(getSide1());
|
||||
sides.add(getSide2());
|
||||
return sides;
|
||||
@@ -295,7 +295,7 @@ public class War extends Conflict {
|
||||
|
||||
@Nullable
|
||||
public Siege getSiege(UUID uuid) {
|
||||
for (Siege siege : sieges) {
|
||||
for (@NotNull Siege siege : sieges) {
|
||||
if (siege.equals(uuid))
|
||||
return siege;
|
||||
}
|
||||
@@ -316,6 +316,11 @@ public class War extends Conflict {
|
||||
sieges.remove(siege);
|
||||
}
|
||||
|
||||
public void setSieges(Set<Siege> sieges) {
|
||||
this.sieges = sieges;
|
||||
this.sieges.forEach(Siege::resume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets raids.
|
||||
*
|
||||
@@ -362,7 +367,7 @@ public class War extends Conflict {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public boolean isPlayerInWar(Player p) {
|
||||
public boolean isPlayerInWar(@NotNull Player p) {
|
||||
return side1.isPlayerOnSide(p) || side2.isPlayerOnSide(p);
|
||||
}
|
||||
|
||||
@@ -371,7 +376,7 @@ public class War extends Conflict {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Side getPlayerSide(Player p) {
|
||||
public Side getPlayerSide(@NotNull Player p) {
|
||||
if (side1.isPlayerOnSide(p))
|
||||
return getSide1();
|
||||
|
||||
@@ -463,7 +468,7 @@ public class War extends Conflict {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has started between <attacker> and <defender>.")
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The war of <war> has started between <attacker> and <defender>.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.parseMinimessagePlaceholder("attacker", getAttacker().getName())
|
||||
.parseMinimessagePlaceholder("defender", getDefender().getName())
|
||||
@@ -491,11 +496,11 @@ public class War extends Conflict {
|
||||
this.getPlayers().forEach(PlayerJoinListener::checkPlayer);
|
||||
}
|
||||
|
||||
public void defeat(Side loserSide) {
|
||||
Side loser = loserSide.equals(getSide1()) ? getSide1() : getSide2();
|
||||
Side winner = loserSide.equals(getSide1()) ? getSide2() : getSide1();
|
||||
public void defeat(@NotNull Side loserSide) {
|
||||
@NotNull Side loser = loserSide.equals(getSide1()) ? getSide1() : getSide2();
|
||||
@NotNull Side winner = loserSide.equals(getSide1()) ? getSide2() : getSide1();
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has ended. <red><winner> <reset>has triumphed against <red><loser><reset>.")
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The war of <war> has ended. <red><winner> <reset>has triumphed against <red><loser><reset>.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.parseMinimessagePlaceholder("winner", winner.getName())
|
||||
.parseMinimessagePlaceholder("loser", loser.getName())
|
||||
@@ -507,7 +512,7 @@ public class War extends Conflict {
|
||||
|
||||
// White defeat/force end war
|
||||
public void draw() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has ended with a white peace.")
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The war of <war> has ended with a white peace.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.build()
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.alathra.AlathranWars.conflict.battle.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.Battle;
|
||||
@@ -25,21 +26,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Siege extends Battle {
|
||||
public static final int MAX_SIEGE_TICKS = 72000; // 60 minute tick constant
|
||||
public static final Duration SIEGE_DURATION = Duration.ofMinutes(60);
|
||||
public static final int MAX_SIEGE_PROGRESS_MINUTES = 8;
|
||||
public static final int MAX_SIEGE_PROGRESS_MINUTES = 8; // How many minutes attackers will need to be on point uncontested for to reach 100%
|
||||
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_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress reverts
|
||||
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;
|
||||
|
||||
private final UUID uuid;
|
||||
private @NotNull War war; // War which siege belongs to
|
||||
private final @NotNull UUID uuid;
|
||||
private final Set<Player> attackers = new HashSet<>(); // Players inside battlefield
|
||||
private final Set<Player> defenders = new HashSet<>(); // Players inside battlefield
|
||||
private final Set<Player> attackerPlayers = new HashSet<>();
|
||||
@@ -53,7 +53,6 @@ public class Siege extends Battle {
|
||||
|
||||
private SiegeRunnable siegeRunnable;
|
||||
|
||||
private War war; // War which siege belongs to
|
||||
private Town town; // Town of the siege
|
||||
private boolean side1AreAttackers; // bool of if side1 being attacker
|
||||
|
||||
@@ -62,7 +61,7 @@ public class Siege extends Battle {
|
||||
private @Nullable Location townSpawn = null;
|
||||
private @Nullable BossBar activeBossBar = null;
|
||||
|
||||
public Siege(final War war, final Town town, Player siegeLeader) {
|
||||
public Siege(final @NotNull War war, final Town town, Player siegeLeader) {
|
||||
uuid = UUIDUtil.generateSiegeUUID();
|
||||
|
||||
endTime = Instant.now().plus(SIEGE_DURATION);
|
||||
@@ -84,6 +83,23 @@ public class Siege extends Battle {
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
// Construct when loading from DB
|
||||
public Siege(War war, @NotNull UUID uuid, Town town, OfflinePlayer siegeLeader, Instant endTime, Instant lastTouched, int siegeProgress, Set<UUID> attackerPlayersIncludingOffline, Set<UUID> defenderPlayersIncludingOffline) {
|
||||
this.war = war;
|
||||
this.uuid = uuid;
|
||||
this.town = town;
|
||||
this.siegeLeader = siegeLeader;
|
||||
this.endTime = endTime;
|
||||
this.lastTouched = lastTouched;
|
||||
this.siegeProgress = siegeProgress;
|
||||
this.attackerPlayersIncludingOffline.addAll(attackerPlayersIncludingOffline);
|
||||
this.defenderPlayersIncludingOffline.addAll(defenderPlayersIncludingOffline);
|
||||
|
||||
side1AreAttackers = war.getTownSide(town).getTeam().equals(BattleTeam.SIDE_2);
|
||||
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a siege
|
||||
*/
|
||||
@@ -94,8 +110,8 @@ public class Siege extends Battle {
|
||||
/**
|
||||
* Resumes a siege (after a server restart e.t.c.)
|
||||
*/
|
||||
public void resume(int resumeTick) {
|
||||
siegeRunnable = new SiegeRunnable(this, resumeTick);
|
||||
public void resume() {
|
||||
siegeRunnable = new SiegeRunnable(this, getSiegeProgress());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,21 +123,22 @@ public class Siege extends Battle {
|
||||
war.removeSiege(this);
|
||||
}
|
||||
|
||||
public void attackersWin(final OfflinePlayer siegeLeader) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
||||
Nation nation = null;
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build());
|
||||
public void attackersWin() {
|
||||
final @Nullable Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
||||
// @Nullable Nation nation = null;
|
||||
// Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build());
|
||||
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
// try {
|
||||
// nation = resident.getTown().getNation();
|
||||
// } catch (Exception ignored) {
|
||||
// }
|
||||
|
||||
if (nation != null) {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The town of " + town.getName()
|
||||
+ " has been placed under occupation by " + nation.getName() + "!").build());
|
||||
}
|
||||
// if (nation != null) {
|
||||
// Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The town of " + town.getName()
|
||||
// + " has been placed under occupation by " + nation.getName() + "!").build());
|
||||
// }
|
||||
|
||||
// TODO Re-enable prize
|
||||
// Main.econ.depositPlayer(siegeLeader, 2500.0);
|
||||
// double amt = 0.0;
|
||||
// if (this.town.getAccount().getHoldingBalance() > 10000.0) {
|
||||
@@ -142,7 +159,10 @@ public class Siege extends Battle {
|
||||
|
||||
/*Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + amt);*/
|
||||
Bukkit.broadcast(new ColorParser("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide().getName() + "!").build());
|
||||
|
||||
// TODO
|
||||
// "The town of <town> has been sacked and placed under occupation by the armies of <attacker>!"
|
||||
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);
|
||||
@@ -154,12 +174,12 @@ public class Siege extends Battle {
|
||||
}
|
||||
|
||||
stop();
|
||||
//clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
// this.town.getAccount().deposit(2500.0, "War chest");
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The defenders have won the siege of " + this.town.getName() + "!").build());
|
||||
// "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.broadcastMessage(UtilsChat.getPrefix() + this.town.getName()
|
||||
// + " has recovered the attackers' war chest, valued at $2,500");
|
||||
// Main.warLogger
|
||||
@@ -172,14 +192,13 @@ public class Siege extends Battle {
|
||||
}
|
||||
|
||||
stop();
|
||||
//clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winner declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " has ended in a draw!").build());
|
||||
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " has ended in a draw!").build());
|
||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + "No money has been recovered.");
|
||||
// Main.warLogger
|
||||
// .log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
|
||||
@@ -243,29 +262,20 @@ public class Siege extends Battle {
|
||||
|
||||
// SECTION Display Bar
|
||||
|
||||
public void updateDisplayBar(CaptureProgressDirection progressDirection) {
|
||||
public void updateDisplayBar(@NotNull CaptureProgressDirection progressDirection) {
|
||||
if (activeBossBar == null)
|
||||
createNewDisplayBar();
|
||||
|
||||
/*for (BossBarViewer viewer : activeBossBar.viewers()) { // TODO Better perf
|
||||
|
||||
}*/
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
for (@NotNull Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.hideBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
for (Player p : this.getAttackers()) {
|
||||
if (p != null)
|
||||
p.showBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
for (Player p : this.getDefenders()) {
|
||||
for (@Nullable Player p : this.getPlayersOnBattlefield()) {
|
||||
if (p != null)
|
||||
p.showBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
String color = "<yellow>";
|
||||
|
||||
switch (progressDirection) {
|
||||
case UP -> {
|
||||
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
|
||||
@@ -290,21 +300,21 @@ public class Siege extends Battle {
|
||||
|
||||
if (Instant.now().isBefore(getEndTime())) {
|
||||
activeBossBar.name(
|
||||
new ColorParser("<gray>Capture Progress: %s<progress> <gray>Time: %s<time>min".formatted(color, color))
|
||||
ColorParser.of("<gray>Capture Progress: %s<progress> <gray>Time: %s<time>min".formatted(color, color))
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), getEndTime()).toMinutes()))
|
||||
.build()
|
||||
);
|
||||
} else {
|
||||
activeBossBar.name(
|
||||
new ColorParser("%sOVERTIME".formatted(color)).build()
|
||||
ColorParser.of("%sOVERTIME".formatted(color)).build()
|
||||
);
|
||||
}
|
||||
activeBossBar.progress(getSiegeProgressPercentage());
|
||||
}
|
||||
|
||||
public void createNewDisplayBar() {
|
||||
final Component text = new ColorParser("<gray>Capture Progress: <yellow><progress> <gray>Time: <yellow><time>min")
|
||||
final @NotNull Component text = ColorParser.of("<gray>Capture Progress: <yellow><progress> <gray>Time: <yellow><time>min")
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), getEndTime()).toMinutesPart()))
|
||||
.build();
|
||||
@@ -314,7 +324,7 @@ public class Siege extends Battle {
|
||||
|
||||
public void deleteDisplayBar() {
|
||||
if (activeBossBar != null) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
for (@NotNull Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.hideBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
@@ -324,7 +334,7 @@ public class Siege extends Battle {
|
||||
|
||||
// SECTION UUID
|
||||
|
||||
public UUID getUUID() {
|
||||
public @NotNull UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@@ -344,7 +354,7 @@ public class Siege extends Battle {
|
||||
* @param siege the siege
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean equals(Siege siege) {
|
||||
public boolean equals(@NotNull Siege siege) {
|
||||
return getUUID().equals(siege.getUUID());
|
||||
}
|
||||
|
||||
@@ -376,6 +386,11 @@ public class Siege extends Battle {
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getPlayersOnBattlefield() {
|
||||
return Stream.concat(attackers.stream(), defenders.stream()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getAttackers() {
|
||||
return attackers;
|
||||
@@ -427,11 +442,11 @@ public class Siege extends Battle {
|
||||
return attackerPlayersIncludingOffline.contains(uuid) || defenderPlayersIncludingOffline.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isPlayerInSiege(Player p) {
|
||||
public boolean isPlayerInSiege(@NotNull Player p) {
|
||||
return isPlayerInSiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public BattleSide getPlayerSideInSiege(UUID uuid) {
|
||||
public @NotNull BattleSide getPlayerSideInSiege(UUID uuid) {
|
||||
if (attackerPlayersIncludingOffline.contains(uuid))
|
||||
return BattleSide.ATTACKER;
|
||||
|
||||
@@ -441,20 +456,20 @@ public class Siege extends Battle {
|
||||
return BattleSide.SPECTATOR;
|
||||
}
|
||||
|
||||
public BattleSide getPlayerSideInSiege(Player p) {
|
||||
public @NotNull BattleSide getPlayerSideInSiege(@NotNull Player p) {
|
||||
return getPlayerSideInSiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(Player p, BattleSide side) {
|
||||
public void addPlayer(@NotNull Player p, @NotNull BattleSide side) {
|
||||
addPlayer(p.getUniqueId(), side);
|
||||
}
|
||||
|
||||
public void addPlayer(OfflinePlayer offlinePlayer, BattleSide side) {
|
||||
public void addPlayer(@NotNull OfflinePlayer offlinePlayer, @NotNull BattleSide side) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
addPlayer(offlinePlayer.getUniqueId(), side);
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid, BattleSide side) {
|
||||
public void addPlayer(@NotNull UUID uuid, @NotNull BattleSide side) {
|
||||
if (isPlayerInSiege(uuid)) return;
|
||||
|
||||
switch (side) {
|
||||
@@ -463,31 +478,31 @@ public class Siege extends Battle {
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||
addOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnlinePlayer(Player p, BattleSide side) {
|
||||
public void addOnlinePlayer(Player p, @NotNull BattleSide side) {
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayers.add(p);
|
||||
case DEFENDER -> defenderPlayers.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(Player p) {
|
||||
public void removePlayer(@NotNull Player p) {
|
||||
removePlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(OfflinePlayer offlinePlayer) {
|
||||
public void removePlayer(@NotNull OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
removePlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
public void removePlayer(@NotNull UUID uuid) {
|
||||
if (!isPlayerInSiege(uuid)) return;
|
||||
|
||||
final BattleSide side = getPlayerSideInSiege(uuid);
|
||||
final @NotNull BattleSide side = getPlayerSideInSiege(uuid);
|
||||
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayersIncludingOffline.remove(uuid);
|
||||
@@ -495,20 +510,28 @@ public class Siege extends Battle {
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
final @Nullable Player p = Bukkit.getPlayer(uuid);
|
||||
removeOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnlinePlayer(Player p, BattleSide side) {
|
||||
public void removeOnlinePlayer(Player p, @NotNull BattleSide side) {
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayers.remove(p);
|
||||
case DEFENDER -> defenderPlayers.remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<UUID> getAttackerPlayersIncludingOffline() {
|
||||
return attackerPlayersIncludingOffline;
|
||||
}
|
||||
|
||||
public Set<UUID> getDefenderPlayersIncludingOffline() {
|
||||
return defenderPlayersIncludingOffline;
|
||||
}
|
||||
|
||||
public void calculateOnlinePlayers() {
|
||||
final Set<Player> onlineAttackers = attackerPlayersIncludingOffline.stream()
|
||||
final @NotNull Set<Player> onlineAttackers = attackerPlayersIncludingOffline.stream()
|
||||
.filter(uuid1 -> Bukkit.getOfflinePlayer(uuid1).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -516,7 +539,7 @@ public class Siege extends Battle {
|
||||
attackerPlayers.clear();
|
||||
attackerPlayers.addAll(onlineAttackers);
|
||||
|
||||
final Set<Player> onlineDefenders = defenderPlayersIncludingOffline.stream()
|
||||
final @NotNull Set<Player> onlineDefenders = defenderPlayersIncludingOffline.stream()
|
||||
.filter(uuid1 -> Bukkit.getOfflinePlayer(uuid1).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -525,8 +548,8 @@ public class Siege extends Battle {
|
||||
defenderPlayers.addAll(onlineDefenders);
|
||||
}
|
||||
|
||||
public void calculateBattlefieldPlayers(Location location) {
|
||||
final Set<Player> attackersOnBattlefield = attackerPlayers.stream()
|
||||
public void calculateBattlefieldPlayers(@NotNull Location location) {
|
||||
final @NotNull Set<Player> attackersOnBattlefield = attackerPlayers.stream()
|
||||
.filter(OfflinePlayer::isOnline)
|
||||
.filter(p -> location.getWorld().equals(p.getLocation().getWorld()))
|
||||
.filter(p -> location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
|
||||
@@ -535,7 +558,7 @@ public class Siege extends Battle {
|
||||
attackers.clear();
|
||||
attackers.addAll(attackersOnBattlefield);
|
||||
|
||||
final Set<Player> defendersOnBattlefield = defenderPlayers.stream()
|
||||
final @NotNull Set<Player> defendersOnBattlefield = defenderPlayers.stream()
|
||||
.filter(OfflinePlayer::isOnline)
|
||||
.filter(p -> location.getWorld().equals(p.getLocation().getWorld()))
|
||||
.filter(p -> location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
|
||||
|
||||
+34
-53
@@ -10,6 +10,8 @@ import fr.skytasul.guardianbeam.Laser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@@ -21,19 +23,20 @@ public class SiegeRunnable implements Runnable {
|
||||
private static final Duration ANNOUNCEMENT_COOLDOWN = Duration.ofMinutes(5);
|
||||
private final static int CAPTURE_MAX_ELEVATION = 10;
|
||||
private final static int CAPTURE_RANGE = 10;
|
||||
private final Siege siege;
|
||||
private final @NotNull Siege siege;
|
||||
|
||||
// Variables
|
||||
private CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE;
|
||||
private @NotNull CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE;
|
||||
private Instant nextAnnouncement;
|
||||
private int taskId = -1;
|
||||
private Laser beam;
|
||||
private @Nullable Laser beam;
|
||||
|
||||
/**
|
||||
* Start a siege
|
||||
*
|
||||
* @param siege the siege
|
||||
*/
|
||||
public SiegeRunnable(Siege siege) {
|
||||
public SiegeRunnable(@NotNull Siege siege) {
|
||||
this.siege = siege;
|
||||
|
||||
siege.setSiegeProgress(0);
|
||||
@@ -54,7 +57,7 @@ public class SiegeRunnable implements Runnable {
|
||||
* @param siege the siege
|
||||
* @param siegeProgress the siege ticks
|
||||
*/
|
||||
public SiegeRunnable(Siege siege, int siegeProgress) {
|
||||
public SiegeRunnable(@NotNull Siege siege, int siegeProgress) {
|
||||
this.siege = siege;
|
||||
|
||||
siege.setSiegeProgress(siegeProgress);
|
||||
@@ -83,9 +86,9 @@ public class SiegeRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Town town = siege.getTown();
|
||||
final TownBlock homeBlock = siege.getHomeBlock();
|
||||
final Location townSpawn = siege.getTownSpawn();
|
||||
final @NotNull Town town = siege.getTown();
|
||||
final @Nullable TownBlock homeBlock = siege.getHomeBlock();
|
||||
final @Nullable Location townSpawn = siege.getTownSpawn();
|
||||
|
||||
if (homeBlock != null && townSpawn != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
@@ -99,7 +102,7 @@ public class SiegeRunnable implements Runnable {
|
||||
siege.calculateBattlefieldPlayers(townSpawn.toCenterLocation());
|
||||
|
||||
// Progress the siege
|
||||
final CaptureProgressDirection progressDirection = getSiegeProgressDirection(townSpawn);
|
||||
final @NotNull CaptureProgressDirection progressDirection = getSiegeProgressDirection(townSpawn);
|
||||
|
||||
// Siege is past max time or attackers haven't touched in time, defenders won
|
||||
if (
|
||||
@@ -115,7 +118,7 @@ public class SiegeRunnable implements Runnable {
|
||||
// Attackers captured the town
|
||||
if (siege.getSiegeProgress() >= MAX_SIEGE_PROGRESS) {
|
||||
cancel();
|
||||
siege.attackersWin(siege.getSiegeLeader());
|
||||
siege.attackersWin();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,43 +129,29 @@ public class SiegeRunnable implements Runnable {
|
||||
|
||||
if (oldProgressDirection != progressDirection) {
|
||||
switch (progressDirection) {
|
||||
case UP -> {
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Attackers are capturing the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Attackers are capturing the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
}
|
||||
case UP -> siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
|
||||
ColorParser.of("<prefix>The Attackers are capturing the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
case NONE -> {
|
||||
/*if ()
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The home block is being contested.")
|
||||
ColorParser.of("<prefix>The home block is being contested.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The home block is being contested.")
|
||||
ColorParser.of("<prefix>The home block is being contested.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));*/
|
||||
}
|
||||
case DOWN -> {
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Defenders re-secured the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Defenders re-secured the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
}
|
||||
case DOWN -> siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
|
||||
ColorParser.of("<prefix>The Defenders re-secured the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,14 +159,8 @@ public class SiegeRunnable implements Runnable {
|
||||
if (Instant.now().isAfter(nextAnnouncement)) {
|
||||
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
||||
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>Siege time remaining: <time> minutes.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutesPart()))
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>Siege time remaining: <time> minutes.")
|
||||
siege.getPlayersOnBattlefield().forEach(p -> p.sendMessage(
|
||||
ColorParser.of("<prefix>Siege time remaining: <time> minutes.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutesPart()))
|
||||
.build()
|
||||
@@ -188,14 +171,14 @@ public class SiegeRunnable implements Runnable {
|
||||
oldProgressDirection = progressDirection;
|
||||
}
|
||||
|
||||
public int getPeopleOnPoint(Location townSpawn, BattleSide battleSide) {
|
||||
public int getPeopleOnPoint(@NotNull Location townSpawn, @NotNull BattleSide battleSide) {
|
||||
int onPoint = 0;
|
||||
|
||||
for (final Player p : (battleSide.equals(BattleSide.ATTACKER) ? siege.getAttackers() : siege.getDefenders())) {
|
||||
for (final @NotNull Player p : (battleSide.equals(BattleSide.ATTACKER) ? siege.getAttackers() : siege.getDefenders())) {
|
||||
if (p.isDead())
|
||||
continue;
|
||||
|
||||
if (townSpawn.getWorld().equals(p.getLocation().getWorld()))
|
||||
if (!townSpawn.getWorld().equals(p.getLocation().getWorld()))
|
||||
continue;
|
||||
|
||||
if (townSpawn.distance(p.getLocation()) <= CAPTURE_RANGE) {
|
||||
@@ -206,7 +189,7 @@ public class SiegeRunnable implements Runnable {
|
||||
return onPoint;
|
||||
}
|
||||
|
||||
public CaptureProgressDirection getSiegeProgressDirection(Location townSpawn) {
|
||||
public @NotNull CaptureProgressDirection getSiegeProgressDirection(@NotNull Location townSpawn) {
|
||||
int attackersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.ATTACKER);
|
||||
int defendersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.DEFENDER);
|
||||
final boolean attackersAreOnPoint = attackersOnPoint > 0;
|
||||
@@ -222,9 +205,7 @@ public class SiegeRunnable implements Runnable {
|
||||
return CaptureProgressDirection.NONE;
|
||||
|
||||
return CaptureProgressDirection.UP;
|
||||
} /*else if (!attackersAreOnPoint && !defendersAreOnPoint) {
|
||||
return CaptureProgressDirection.UNCONTESTED;
|
||||
}*/ else {
|
||||
} else {
|
||||
if (siege.getSiegeProgress() == 0)
|
||||
return CaptureProgressDirection.NONE;
|
||||
|
||||
@@ -242,8 +223,8 @@ public class SiegeRunnable implements Runnable {
|
||||
return;
|
||||
|
||||
try {
|
||||
Location loc1 = siege.getTownSpawn();
|
||||
Location loc2 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY() + 350D, loc1.getZ());
|
||||
@Nullable Location loc1 = siege.getTownSpawn();
|
||||
@NotNull Location loc2 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY() + 350D, loc1.getZ());
|
||||
|
||||
beam = new Laser.CrystalLaser(loc1, loc2, -1, -1);
|
||||
beam.start(Main.getInstance());
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.github.alathra.AlathranWars.Main;
|
||||
import de.leonhard.storage.Config;
|
||||
|
||||
public class ConfigManager {
|
||||
private Main instance;
|
||||
private final Main instance;
|
||||
private Config cfg;
|
||||
|
||||
public ConfigManager(Main instance) {
|
||||
|
||||
@@ -13,27 +13,14 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DataManager {
|
||||
private Main instance;
|
||||
// private static DataManager instance;
|
||||
private final Main instance;
|
||||
private HikariConfig hikariConfig;
|
||||
private HikariDataSource hikariDataSource;
|
||||
|
||||
public DataManager(Main instance) {
|
||||
/*if (instance != null)
|
||||
Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton");
|
||||
|
||||
main = Main.getInstance();*/
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/*@NotNull
|
||||
public static DataManager getInstance() {
|
||||
if (instance == null)
|
||||
instance = new DataManager();
|
||||
|
||||
return instance;
|
||||
}*/
|
||||
|
||||
public void onLoad() {
|
||||
openConnection();
|
||||
SQLQueries.initDB();
|
||||
@@ -73,10 +60,6 @@ public class DataManager {
|
||||
|
||||
if (mysqlEnabled) {
|
||||
hikariConfig.setDataSourceClassName("org.mariadb.jdbc.MariaDbDataSource");
|
||||
hikariConfig.setJdbcUrl("jdbc:mariadb://%s/%s".formatted(
|
||||
Config.get().get("mysql.host", "127.0.0.1:3306"),
|
||||
Config.get().get("mysql.database", "database")
|
||||
));
|
||||
hikariConfig.addDataSourceProperty("url", "jdbc:mariadb://%s/%s".formatted(
|
||||
Config.get().get("mysql.host", "127.0.0.1:3306"),
|
||||
Config.get().get("mysql.database", "database")
|
||||
@@ -86,14 +69,14 @@ public class DataManager {
|
||||
hikariConfig.setConnectionTimeout(5000);
|
||||
hikariConfig.setKeepaliveTime(0);
|
||||
} else {
|
||||
File dataFolder = new File(instance.getDataFolder(), "database.db");
|
||||
@NotNull File dataFolder = new File(instance.getDataFolder(), "database.db");
|
||||
|
||||
if (!dataFolder.exists()) {
|
||||
try {
|
||||
if (!dataFolder.createNewFile())
|
||||
instance.getLogger().severe("File write error: database.db (1)");
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().severe("File write error: database.db (2) - " + e.getMessage());
|
||||
instance.getLogger().severe("File write error: database.db (2) - %s".formatted(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.github.alathra.AlathranWars.data;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
GATHER(1, 0),
|
||||
@@ -27,8 +30,8 @@ public enum RaidPhase {
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByName(String name) {
|
||||
for (RaidPhase p : RaidPhase.values()) {
|
||||
public static @Nullable RaidPhase getByName(String name) {
|
||||
for (@NotNull RaidPhase p : RaidPhase.values()) {
|
||||
if (p.name().equalsIgnoreCase(name)) return p;
|
||||
}
|
||||
return null;
|
||||
@@ -40,14 +43,14 @@ public enum RaidPhase {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByID(int id) {
|
||||
for (RaidPhase p : RaidPhase.values()) {
|
||||
public static @Nullable RaidPhase getByID(int id) {
|
||||
for (@NotNull RaidPhase p : RaidPhase.values()) {
|
||||
if (p.id == id) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RaidPhase getNext(RaidPhase phase) {
|
||||
public static @Nullable RaidPhase getNext(@NotNull RaidPhase phase) {
|
||||
switch (phase) {
|
||||
case START -> {
|
||||
return GATHER;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum CommandArgsSiege {
|
||||
IN_SIEGE,
|
||||
OUT_SIEGE,
|
||||
ALL_SIEGES,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum CommandArgsWar {
|
||||
IN_WAR,
|
||||
OUT_WAR,
|
||||
ALL_WARS,
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import java.util.stream.Collectors;
|
||||
@Singleton
|
||||
public class WarManager {
|
||||
private static WarManager instance;
|
||||
private Set<War> wars = new HashSet<>();
|
||||
private @NotNull Set<War> wars = new HashSet<>();
|
||||
|
||||
private WarManager() {
|
||||
if (instance != null)
|
||||
@@ -45,7 +45,7 @@ public class WarManager {
|
||||
|
||||
@Nullable
|
||||
public War getWar(String warName) {
|
||||
for (War war : wars)
|
||||
for (@NotNull War war : wars)
|
||||
if (war.equals(warName)) return war;
|
||||
|
||||
return null;
|
||||
@@ -53,7 +53,7 @@ public class WarManager {
|
||||
|
||||
@Nullable
|
||||
public War getWar(UUID uuid) {
|
||||
for (War war : wars)
|
||||
for (@NotNull War war : wars)
|
||||
if (war.equals(uuid)) return war;
|
||||
|
||||
return null;
|
||||
@@ -61,7 +61,7 @@ public class WarManager {
|
||||
|
||||
@Nullable
|
||||
public Side getSide(UUID uuid) {
|
||||
for (War war : wars)
|
||||
for (@NotNull War war : wars)
|
||||
if (war.getSide(uuid) != null) return war.getSide(uuid);
|
||||
|
||||
return null;
|
||||
@@ -69,7 +69,7 @@ public class WarManager {
|
||||
|
||||
@Nullable
|
||||
public Siege getSiege(UUID uuid) {
|
||||
for (War war : wars)
|
||||
for (@NotNull War war : wars)
|
||||
if (war.getSiege(uuid) != null) return war.getSiege(uuid);
|
||||
|
||||
return null;
|
||||
@@ -84,30 +84,52 @@ public class WarManager {
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnyWars(UUID uuid) {
|
||||
for (War war : wars) {
|
||||
for (@NotNull War war : wars) {
|
||||
if (war.isPlayerInWar(uuid)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnyWars(Player p) {
|
||||
public boolean isPlayerInAnyWars(@NotNull Player p) {
|
||||
return isPlayerInAnyWars(p.getUniqueId());
|
||||
}
|
||||
|
||||
public @NotNull Set<War> getPlayerWars(@NotNull Player p) {
|
||||
return getPlayerWars(p.getUniqueId());
|
||||
}
|
||||
|
||||
public @NotNull Set<War> getPlayerWars(UUID uuid) {
|
||||
return wars.stream()
|
||||
.filter(war -> war.isPlayerInWar(uuid))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public boolean isTownInAnyWars(Town town) {
|
||||
for (War war : wars) {
|
||||
for (@NotNull War war : wars) {
|
||||
if (war.isTownInWar(town)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public @NotNull Set<War> getTownWars(Town town) {
|
||||
return wars.stream()
|
||||
.filter(war -> war.isTownInWar(town))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public boolean isNationInAnyWars(Nation nation) {
|
||||
for (War war : wars) {
|
||||
for (@NotNull War war : wars) {
|
||||
if (war.isNationInWar(nation)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public @NotNull Set<War> getNationWars(Nation nation) {
|
||||
return wars.stream()
|
||||
.filter(war -> war.isNationInWar(nation))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getWarNames() {
|
||||
return wars.stream()
|
||||
@@ -126,7 +148,7 @@ public class WarManager {
|
||||
|
||||
@NotNull
|
||||
public Set<Siege> getSieges() {
|
||||
final Set<Siege> sieges = new HashSet<>();
|
||||
final @NotNull Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
wars.forEach((War war) -> sieges.addAll(war.getSieges()));
|
||||
|
||||
@@ -135,40 +157,32 @@ public class WarManager {
|
||||
|
||||
@NotNull
|
||||
public Set<Raid> getRaids() {
|
||||
final Set<Raid> raids = new HashSet<>();
|
||||
final @NotNull Set<Raid> raids = new HashSet<>();
|
||||
|
||||
wars.forEach((War war) -> raids.addAll(war.getRaids()));
|
||||
|
||||
return raids;
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnySiege(Player p) {
|
||||
public boolean isPlayerInAnySiege(@NotNull Player p) {
|
||||
return isPlayerInAnySiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnySiege(UUID uuid) {
|
||||
for (Siege siege : getSieges()) {
|
||||
for (@NotNull Siege siege : getSieges()) {
|
||||
if (siege.isPlayerInSiege(uuid)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<Siege> getPlayerSieges(Player p) {
|
||||
public @NotNull Set<Siege> getPlayerSieges(@NotNull Player p) {
|
||||
return getPlayerSieges(p.getUniqueId());
|
||||
}
|
||||
|
||||
public Set<Siege> getPlayerSieges(UUID uuid) {
|
||||
if (!isPlayerInAnySiege(uuid))
|
||||
return Collections.emptySet();
|
||||
|
||||
Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
for (Siege siege : getSieges()) {
|
||||
if (siege.isPlayerInSiege(uuid))
|
||||
sieges.add(siege);
|
||||
}
|
||||
|
||||
return sieges;
|
||||
public @NotNull Set<Siege> getPlayerSieges(UUID uuid) {
|
||||
return getSieges().stream()
|
||||
.filter(siege -> siege.isPlayerInSiege(uuid))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import me.neznamy.tab.api.nametag.UnlimitedNameTagManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TABHook {
|
||||
private static boolean enabled = false;
|
||||
@@ -28,20 +30,20 @@ public class TABHook {
|
||||
private static void registerPlayerLoadListener() {
|
||||
if (!enabled) return;
|
||||
|
||||
EventBus eventBus = tabAPI.getEventBus();
|
||||
@Nullable EventBus eventBus = tabAPI.getEventBus();
|
||||
if (eventBus == null) return;
|
||||
|
||||
eventBus.register(PlayerLoadEvent.class, e -> {
|
||||
TabPlayer tabPlayer = e.getPlayer();
|
||||
@NotNull TabPlayer tabPlayer = e.getPlayer();
|
||||
if (tabPlayer.getPlayer() instanceof Player p)
|
||||
PlayerJoinListener.checkPlayer(p);
|
||||
});
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffix(Player p, War war) {
|
||||
public static void assignSide1WarSuffix(@NotNull Player p, @NotNull War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -54,10 +56,10 @@ public class TABHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffix(Player p, War war) {
|
||||
public static void assignSide2WarSuffix(@NotNull Player p, @NotNull War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -68,10 +70,10 @@ public class TABHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffixMerc(Player p, War war) {
|
||||
public static void assignSide1WarSuffixMerc(@NotNull Player p, @NotNull War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -79,10 +81,10 @@ public class TABHook {
|
||||
UtilsChat.color(" <green>[M]<red>[") + war.getSide1() + "]<reset>");
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffixMerc(Player p, War war) {
|
||||
public static void assignSide2WarSuffixMerc(@NotNull Player p, @NotNull War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -90,25 +92,25 @@ public class TABHook {
|
||||
UtilsChat.color(" <green>[M]<blue>[") + war.getSide2() + "]<reset>");
|
||||
}
|
||||
|
||||
public static void resetSuffix(Player p) {
|
||||
public static void resetSuffix(@NotNull Player p) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, null);
|
||||
}
|
||||
|
||||
public static void resetSuffix(String username) {
|
||||
public static void resetSuffix(@NotNull String username) {
|
||||
if (!enabled) return;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotNull
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
|
||||
|
||||
try {
|
||||
if (offlinePlayer.isOnline()) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(username);
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(username);
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -118,10 +120,10 @@ public class TABHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetPrefix(Player p) {
|
||||
public static void resetPrefix(@NotNull Player p) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -132,14 +134,14 @@ public class TABHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetPrefix(String playername) {
|
||||
public static void resetPrefix(@NotNull String playername) {
|
||||
if (!enabled) return;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotNull
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playername);
|
||||
try {
|
||||
if (offlinePlayer.isOnline()) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(playername);
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(playername);
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
@@ -149,10 +151,10 @@ public class TABHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeColorPrefix(Player p, String prefix) {
|
||||
public static void removeColorPrefix(@NotNull Player p, @NotNull String prefix) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@Nullable TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (prefix.length() > 2) {
|
||||
prefix = prefix.substring(0, prefix.length() - 2);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.github.alathra.AlathranWars.items;
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.items.item.RamItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -40,11 +41,11 @@ public class WarItemRegistry {
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public static String registryName(String item) {
|
||||
public static @NotNull String registryName(String item) {
|
||||
return namespace + ":" + item;
|
||||
}
|
||||
|
||||
public Map<String, ItemStack> getItemRegistry() {
|
||||
public @NotNull Map<String, ItemStack> getItemRegistry() {
|
||||
return itemRegistry.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() != null)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.alathra.AlathranWars.items;
|
||||
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@@ -24,14 +25,14 @@ public class WarRecipeRegistry {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void register(String name, Set<Recipe> recipes) {
|
||||
public void register(String name, @NotNull Set<Recipe> recipes) {
|
||||
for (Recipe recipe : recipes) {
|
||||
// Bukkit.getServer().addRecipe(recipe);
|
||||
recipeRegistry.put(name, recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, Recipe> getRecipeRegistry() {
|
||||
public @NotNull HashMap<String, Recipe> getRecipeRegistry() {
|
||||
return recipeRegistry;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,18 +11,20 @@ import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RamItem implements IWarItem {
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
public @NotNull ItemStack getItemStack() {
|
||||
|
||||
ItemStack ram = new ItemStack(Material.WOODEN_HOE);
|
||||
@NotNull ItemStack ram = new ItemStack(Material.WOODEN_HOE);
|
||||
ItemMeta meta = ram.getItemMeta();
|
||||
|
||||
meta.setDisplayName("Door Ram");
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
@NotNull ArrayList<String> lore = new ArrayList<>();
|
||||
meta.setLore(lore);
|
||||
meta.setCustomModelData(14700);
|
||||
|
||||
@@ -32,10 +34,10 @@ public class RamItem implements IWarItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
ItemStack output = WarItemRegistry.getInstance().getOrNull("ram");
|
||||
NamespacedKey key = new NamespacedKey(Main.getInstance(), "ram");
|
||||
ShapedRecipe recipe = new ShapedRecipe(key, output);
|
||||
public @NotNull Recipe getRecipe() {
|
||||
@Nullable ItemStack output = WarItemRegistry.getInstance().getOrNull("ram");
|
||||
@NotNull NamespacedKey key = new NamespacedKey(Main.getInstance(), "ram");
|
||||
@NotNull ShapedRecipe recipe = new ShapedRecipe(key, output);
|
||||
recipe.shape("$@$", "B##");
|
||||
recipe.setIngredient('@', Material.STICK);
|
||||
recipe.setIngredient('$', Material.IRON_INGOT);
|
||||
|
||||
@@ -8,6 +8,7 @@ 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;
|
||||
|
||||
@@ -23,8 +24,8 @@ public class BlockBreakListener implements Listener {
|
||||
);
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
public void onBlockBreak(final @NotNull BlockBreakEvent e) {
|
||||
final @NotNull Block block = e.getBlock();
|
||||
/*if (SiegeData.getSieges().isEmpty() *//*&& RaidData.getRaids().isEmpty()*//*) {
|
||||
return;
|
||||
}*/
|
||||
@@ -47,7 +48,7 @@ public class BlockBreakListener implements Listener {
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not break blocks during sieges").parseLegacy().build());
|
||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break blocks during sieges").parseLegacy().build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -64,8 +65,8 @@ public class BlockBreakListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
public void onBlockPlace(final @NotNull BlockPlaceEvent event) {
|
||||
final @NotNull Block block = event.getBlock();
|
||||
/*if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}*/
|
||||
@@ -73,7 +74,7 @@ public class BlockBreakListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = event.getPlayer();
|
||||
@NotNull Player p = event.getPlayer();
|
||||
if (p.hasPermission("AlathranWars.place")) {
|
||||
return;
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class BlockBreakListener implements Listener {
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(new ColorParser("<red>You can not place blocks during sieges").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of("<red>You can not place blocks during sieges").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@@ -45,14 +46,14 @@ public class CommandsListener implements Listener {
|
||||
};
|
||||
|
||||
@EventHandler
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
public void onCommandSend(final @NotNull PlayerCommandPreprocessEvent event) {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
@NotNull Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
// if (p.hasPermission("!AlathranWars.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
String @NotNull [] args = event.getMessage().split(" ");
|
||||
|
||||
/*
|
||||
Prevent any teleport command events from occurring
|
||||
@@ -150,19 +151,19 @@ public class CommandsListener implements Listener {
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
||||
for (@NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (siege.getEndTime().isAfter(Instant.now())) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p) || siege.getDefenderPlayers().contains(p)) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : PREFIXES_TOWNY) {
|
||||
@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(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot modify this property during a oldSiege!").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot modify this property during a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -172,13 +173,13 @@ public class CommandsListener implements Listener {
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : PREFIXES_TOWNY) {
|
||||
@NotNull String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (@NotNull String prefix : PREFIXES_TOWNY) {
|
||||
//payment check
|
||||
for (String cmd : PAYMENT) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot withdraw money whilst in a oldSiege!").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot withdraw money whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -193,17 +194,17 @@ public class CommandsListener implements Listener {
|
||||
|| 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(new ColorParser(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());
|
||||
return;
|
||||
}
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||
p.sendMessage(new ColorParser(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());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -213,20 +214,20 @@ public class CommandsListener implements Listener {
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : PREFIXES) {
|
||||
@NotNull String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (@NotNull String prefix : PREFIXES) {
|
||||
for (String cmd : BLACKLISTED_SHORT) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||
p.sendMessage(new ColorParser(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());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,17 +8,19 @@ 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 PlayerDeathEvent event) {
|
||||
public void onPlayerKilled(final @NotNull PlayerDeathEvent event) {
|
||||
|
||||
final Player killed = event.getEntity();
|
||||
final Player killer = event.getEntity().getKiller();
|
||||
Town town = null;
|
||||
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) {
|
||||
@@ -96,7 +98,7 @@ public final class KillsListener implements Listener {
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
if (p != null)
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points").parseLegacy().build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points").parseLegacy().build());
|
||||
} catch (NullPointerException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
@@ -180,7 +182,7 @@ public final class KillsListener implements Listener {
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
private void siegeKill(final @NotNull Player killed, final @NotNull PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Utils.damageAllGear(killed);
|
||||
|
||||
@@ -198,7 +200,7 @@ public final class KillsListener implements Listener {
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void raidKill(final Player killed, final PlayerDeathEvent event) {
|
||||
private void raidKill(final @NotNull Player killed, final @NotNull PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Utils.damageAllGear(killed);
|
||||
|
||||
@@ -216,7 +218,7 @@ public final class KillsListener implements Listener {
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void oocKill(final Player killed, final PlayerDeathEvent event) {
|
||||
private void oocKill(final Player killed, final @NotNull PlayerDeathEvent event) {
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
|
||||
+25
-23
@@ -21,6 +21,8 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
@@ -47,7 +49,7 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
|
||||
//map of broken doors
|
||||
public Map<Location, Long> brokenDoors = new HashMap<>();
|
||||
public final @NotNull Map<Location, Long> brokenDoors = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param event event
|
||||
@@ -55,22 +57,22 @@ public class PlayerInteractListener implements Listener {
|
||||
* @author AubriTheHuman
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
public void onPlayerInteract(final @NotNull PlayerInteractEvent event) {
|
||||
@NotNull Player player = event.getPlayer();
|
||||
@NotNull Action action = event.getAction();
|
||||
|
||||
if (action == Action.LEFT_CLICK_BLOCK) {
|
||||
Block clicked = event.getClickedBlock();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
@Nullable Block clicked = event.getClickedBlock();
|
||||
@NotNull ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (clicked != null) {
|
||||
if (doors.contains(clicked.getType())) { // left click + any door types
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
@NotNull Door door = (Door) clicked.getBlockData();
|
||||
// lock door in the opposite position
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for (Siege s : WarManager.getInstance().getSieges()) {
|
||||
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
for (@NotNull Siege s : WarManager.getInstance().getSieges()) {
|
||||
for (@NotNull TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
@@ -97,18 +99,18 @@ public class PlayerInteractListener implements Listener {
|
||||
|
||||
// Returns if already broken.
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>The door is already broken!").parseLegacy().build());
|
||||
player.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>The door is already broken!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>Break it down alright!").parseLegacy().build());
|
||||
player.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<yellow>Break it down alright!").parseLegacy().build());
|
||||
brokenDoors.put(getDoorPos(clicked, door), System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
|
||||
door.setOpen(!door.isOpen());
|
||||
clicked.setBlockData(door);
|
||||
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
|
||||
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation());
|
||||
} else {
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>This item can only be used in a siege or raid!").parseLegacy().build());
|
||||
player.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "<red>This item can only be used in a siege or raid!").parseLegacy().build());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -118,8 +120,8 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRClick(final PlayerItemDamageEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
public void onPlayerRClick(final @NotNull PlayerItemDamageEvent event) {
|
||||
@NotNull ItemStack item = event.getItem();
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -132,17 +134,17 @@ public class PlayerInteractListener implements Listener {
|
||||
* @author AubriTheHuman
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerRClick(final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
Block clicked = event.getClickedBlock();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
public void onPlayerRClick(final @NotNull PlayerInteractEvent event) {
|
||||
@NotNull Player player = event.getPlayer();
|
||||
@NotNull Action action = event.getAction();
|
||||
@Nullable Block clicked = event.getClickedBlock();
|
||||
@NotNull ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (action == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (clicked != null) {
|
||||
if (doors.contains(clicked.getType())) {
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
@NotNull Door door = (Door) clicked.getBlockData();
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Door is broken!").parseLegacy().build());
|
||||
player.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Door is broken!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
@@ -164,7 +166,7 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private Location getDoorPos(Block clicked, Door door) {
|
||||
private @NotNull Location getDoorPos(@NotNull Block clicked, @NotNull Door door) {
|
||||
if (door.getHalf() == Bisected.Half.BOTTOM) {
|
||||
return clicked.getLocation().clone();
|
||||
} else if (door.getHalf() == Bisected.Half.TOP) {
|
||||
@@ -173,7 +175,7 @@ public class PlayerInteractListener implements Listener {
|
||||
return clicked.getLocation().clone();
|
||||
}
|
||||
|
||||
private boolean doorBroken(@Nonnull Block clicked, Door door) {
|
||||
private boolean doorBroken(@Nonnull Block clicked, @NotNull Door door) {
|
||||
if (door.getHalf() == Bisected.Half.BOTTOM) {
|
||||
if (brokenDoors.get(clicked.getLocation()) != null) {
|
||||
return brokenDoors.get(clicked.getLocation()) > System.currentTimeMillis();
|
||||
|
||||
+9
-8
@@ -11,6 +11,7 @@ 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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -27,8 +28,8 @@ public class BlockBreakPlaceListener implements Listener {
|
||||
);
|
||||
|
||||
@EventHandler
|
||||
private void onBlockBreak(BlockBreakEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
private void onBlockBreak(@NotNull BlockBreakEvent e) {
|
||||
final @NotNull Block block = e.getBlock();
|
||||
|
||||
if (allowedBlocks.contains(block.getType()))
|
||||
return;
|
||||
@@ -41,9 +42,9 @@ public class BlockBreakPlaceListener implements Listener {
|
||||
if (town == null)
|
||||
return;
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
for (final @NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown().equals(town)) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not break blocks during sieges.").build());
|
||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not break blocks during sieges.").build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -51,8 +52,8 @@ public class BlockBreakPlaceListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
public void onBlockPlace(@NotNull BlockPlaceEvent e) {
|
||||
final @NotNull Block block = e.getBlock();
|
||||
|
||||
if (allowedBlocks.contains(block.getType()))
|
||||
return;
|
||||
@@ -65,9 +66,9 @@ public class BlockBreakPlaceListener implements Listener {
|
||||
if (town == null)
|
||||
return;
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
for (final @NotNull Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown().equals(town)) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not place blocks during sieges.").build());
|
||||
e.getPlayer().sendMessage(ColorParser.of("<red>You can not place blocks during sieges.").build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-6
@@ -4,6 +4,7 @@ import com.github.alathra.AlathranWars.utility.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerDeathListener implements Listener {
|
||||
private final static int BATTLE_RADIUS = 300;
|
||||
@@ -40,10 +41,10 @@ public class PlayerDeathListener implements Listener {
|
||||
siege.addPointsToAttackers(KILL_POINTS_OFF);
|
||||
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
}
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +58,10 @@ public class PlayerDeathListener implements Listener {
|
||||
siege.addPointsToDefenders(KILL_POINTS_DEF);
|
||||
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
}
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ public class PlayerDeathListener implements Listener {
|
||||
* @param victim killed player
|
||||
* @param e event
|
||||
*/
|
||||
private void siegeKill(Player victim, PlayerDeathEvent e) {
|
||||
private void siegeKill(@NotNull Player victim, @NotNull PlayerDeathEvent e) {
|
||||
//Helper
|
||||
Utils.damageAllGear(victim);
|
||||
|
||||
@@ -100,7 +101,7 @@ public class PlayerDeathListener implements Listener {
|
||||
* @param victim killed player
|
||||
* @param e event
|
||||
*/
|
||||
private void oocKill(Player victim, PlayerDeathEvent e) {
|
||||
private void oocKill(Player victim, @NotNull PlayerDeathEvent e) {
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
||||
e.setKeepInventory(true);
|
||||
|
||||
+5
-4
@@ -7,14 +7,15 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerJoin(PlayerJoinEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
private void onPlayerJoin(@NotNull PlayerJoinEvent e) {
|
||||
final @NotNull Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnySiege(p)) {
|
||||
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
for (@NotNull Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final @NotNull BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
siege.addOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -7,14 +7,15 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerQuitListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerQuit(PlayerQuitEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
private void onPlayerQuit(@NotNull PlayerQuitEvent e) {
|
||||
final @NotNull Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnySiege(p)) {
|
||||
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
for (@NotNull Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final @NotNull BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
siege.removeOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,17 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
public static void checkPlayer(Player p) {
|
||||
final UUID uuid = p.getUniqueId();
|
||||
public static void checkPlayer(@NotNull Player p) {
|
||||
final @NotNull UUID uuid = p.getUniqueId();
|
||||
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(uuid)) {
|
||||
for (final War war : WarManager.getInstance().getWars()) {
|
||||
for (final @NotNull War war : WarManager.getInstance().getWars()) {
|
||||
if (war.getSide1().isPlayerOnSide(uuid) && !war.getSide1().isPlayerSurrendered(uuid)) {
|
||||
TABHook.assignSide1WarSuffix(p, war);
|
||||
} else if (war.getSide2().isPlayerOnSide(uuid) && !war.getSide2().isPlayerSurrendered(uuid)) {
|
||||
@@ -31,12 +33,12 @@ public class PlayerJoinListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onPlayerJoin(PlayerJoinEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
private void onPlayerJoin(@NotNull PlayerJoinEvent e) {
|
||||
final @NotNull Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(p)) {
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
for (@NotNull War war : WarManager.getInstance().getWars()) {
|
||||
if (war.isPlayerInWar(p)) {
|
||||
Side side = war.getPlayerSide(p);
|
||||
@Nullable Side side = war.getPlayerSide(p);
|
||||
if (side != null) {
|
||||
side.addOnlinePlayer(p);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,17 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerQuitListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerQuit(PlayerQuitEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
private void onPlayerQuit(@NotNull PlayerQuitEvent e) {
|
||||
final @NotNull Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(p)) {
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
for (@NotNull War war : WarManager.getInstance().getWars()) {
|
||||
if (war.isPlayerInWar(p)) {
|
||||
Side side = war.getPlayerSide(p);
|
||||
@Nullable Side side = war.getPlayerSide(p);
|
||||
if (side != null) {
|
||||
side.removeOnlinePlayer(p);
|
||||
}
|
||||
|
||||
@@ -2,16 +2,17 @@ package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class DB {
|
||||
public static Connection get() throws SQLException {
|
||||
public static @NotNull Connection get() throws SQLException {
|
||||
return Main.getInstance().getDataManager().getConnection();
|
||||
}
|
||||
|
||||
public static HikariDataSource getDataSource() {
|
||||
public static @NotNull HikariDataSource getDataSource() {
|
||||
return Main.getInstance().getDataManager().getDataSource();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@ import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.*;
|
||||
@@ -111,6 +115,7 @@ public class SQLQueries {
|
||||
`town` uuid NOT NULL,
|
||||
`siegeLeader` uuid NOT NULL,
|
||||
`endTime` timestamp NOT NULL,
|
||||
`lastTouched` timestamp NOT NULL,
|
||||
`siegeProgress` int(11) NOT NULL,
|
||||
PRIMARY KEY (`uuid`),
|
||||
KEY `siege_war` (`war`),
|
||||
@@ -144,12 +149,12 @@ public class SQLQueries {
|
||||
|
||||
public static void saveAll() {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
@NotNull Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) "
|
||||
+ "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?")
|
||||
) {
|
||||
// Save wars
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
for (@NotNull War war : WarManager.getInstance().getWars()) {
|
||||
// Insert
|
||||
warStatement.setString(1, war.getUUID().toString());
|
||||
warStatement.setString(2, war.getName());
|
||||
@@ -166,24 +171,24 @@ public class SQLQueries {
|
||||
warStatement.executeUpdate();
|
||||
|
||||
// Save sides
|
||||
for (Side side : war.getSides()) {
|
||||
for (@NotNull Side side : war.getSides()) {
|
||||
saveSide(con, side);
|
||||
}
|
||||
|
||||
// TODO Save sieges
|
||||
// for (Siege siege : war.getSieges()) {
|
||||
//
|
||||
// }
|
||||
// Save sieges
|
||||
for (@NotNull Siege siege : war.getSieges()) {
|
||||
saveSiege(con, siege);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSide(Connection con, Side side) throws SQLException {
|
||||
private static void saveSide(@NotNull Connection con, @NotNull Side side) {
|
||||
try (
|
||||
PreparedStatement sideStatement = con.prepareStatement("INSERT INTO `wars_sides` (`war`, `uuid`, `side`, `team`, `name`, `town`, `siegeGrace`, `raidGrace`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
||||
+ "ON DUPLICATE KEY UPDATE `side` = ?, `team` = ?, `name` = ?, `town` = ?, `siegeGrace` = ?, `raidGrace` = ?");
|
||||
+ "ON DUPLICATE KEY UPDATE `side` = ?, `team` = ?, `name` = ?, `town` = ?, `siegeGrace` = ?, `raidGrace` = ?")
|
||||
) {
|
||||
// Insert
|
||||
sideStatement.setString(1, side.getWar().getUUID().toString());
|
||||
@@ -216,10 +221,10 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSideNations(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
private static void saveSideNations(@NotNull Connection con, @NotNull Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `nation`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `nation`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"))
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
@@ -230,7 +235,7 @@ public class SQLQueries {
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (Nation nation : (surrendered ? side.getSurrenderedNations() : side.getNations())) {
|
||||
for (@NotNull Nation nation : (surrendered ? side.getSurrenderedNations() : side.getNations())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, nation.getUUID().toString());
|
||||
insertStatement.executeUpdate();
|
||||
@@ -246,10 +251,10 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSideTowns(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
private static void saveSideTowns(@NotNull Connection con, @NotNull Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `town`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `town`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"))
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
@@ -260,7 +265,7 @@ public class SQLQueries {
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (Town town : (surrendered ? side.getSurrenderedTowns() : side.getTowns())) {
|
||||
for (@NotNull Town town : (surrendered ? side.getSurrenderedTowns() : side.getTowns())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, town.getUUID().toString());
|
||||
insertStatement.executeUpdate();
|
||||
@@ -276,10 +281,10 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSidePlayers(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
private static void saveSidePlayers(@NotNull Connection con, @NotNull Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `player`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `player`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"))
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
@@ -290,7 +295,7 @@ public class SQLQueries {
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (UUID uuid : (surrendered ? side.getSurrenderedPlayersIncludingOffline() : side.getPlayersIncludingOffline())) {
|
||||
for (@NotNull UUID uuid : (surrendered ? side.getSurrenderedPlayersIncludingOffline() : side.getPlayersIncludingOffline())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, uuid.toString());
|
||||
insertStatement.executeUpdate();
|
||||
@@ -306,11 +311,11 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<War> loadAll() {
|
||||
Set<War> wars = new HashSet<>();
|
||||
public static @NotNull Set<War> loadAll() {
|
||||
@NotNull Set<War> wars = new HashSet<>();
|
||||
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
@NotNull Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `wars_list`")
|
||||
) {
|
||||
// Load all wars
|
||||
@@ -321,15 +326,13 @@ public class SQLQueries {
|
||||
|
||||
while (warsResult.next()) {
|
||||
// War data
|
||||
UUID uuid = UUID.fromString(warsResult.getString("uuid"));
|
||||
@NotNull UUID uuid = UUID.fromString(warsResult.getString("uuid"));
|
||||
String name = warsResult.getString("name");
|
||||
String label = warsResult.getString("label");
|
||||
UUID side1UUID = UUID.fromString(warsResult.getString("side1"));
|
||||
UUID side2UUID = UUID.fromString(warsResult.getString("side2"));
|
||||
Side side1 = loadSide(con, uuid, side1UUID);
|
||||
Side side2 = loadSide(con, uuid, side2UUID);
|
||||
|
||||
// TODO Siege data
|
||||
@NotNull UUID side1UUID = UUID.fromString(warsResult.getString("side1"));
|
||||
@NotNull UUID side2UUID = UUID.fromString(warsResult.getString("side2"));
|
||||
@NotNull Side side1 = loadSide(con, uuid, side1UUID);
|
||||
@NotNull Side side2 = loadSide(con, uuid, side2UUID);
|
||||
|
||||
wars.add(new War(
|
||||
uuid,
|
||||
@@ -341,6 +344,11 @@ public class SQLQueries {
|
||||
new HashSet<>()
|
||||
));
|
||||
}
|
||||
|
||||
for (War war : wars) {
|
||||
@NotNull Set<Siege> sieges = loadSieges(con, war);
|
||||
war.setSieges(sieges);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -348,7 +356,8 @@ public class SQLQueries {
|
||||
return wars;
|
||||
}
|
||||
|
||||
public static Side loadSide(Connection con, UUID warUUID, UUID uuid) {
|
||||
@Contract("_, _, _ -> new")
|
||||
public static @NotNull Side loadSide(@NotNull Connection con, @NotNull UUID warUUID, @NotNull UUID uuid) {
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `wars_sides` WHERE `war` = ? AND `uuid` = ?")) {
|
||||
// Load side
|
||||
warStatement.setString(1, warUUID.toString());
|
||||
@@ -361,19 +370,19 @@ public class SQLQueries {
|
||||
sideResult.next();
|
||||
|
||||
// Side data
|
||||
BattleSide side = BattleSide.valueOf(sideResult.getString("side"));
|
||||
BattleTeam team = BattleTeam.valueOf(sideResult.getString("team"));
|
||||
@NotNull BattleSide side = BattleSide.valueOf(sideResult.getString("side"));
|
||||
@NotNull BattleTeam team = BattleTeam.valueOf(sideResult.getString("team"));
|
||||
String name = sideResult.getString("name");
|
||||
Town town = TownyAPI.getInstance().getTown(UUID.fromString(sideResult.getString("town")));
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(UUID.fromString(sideResult.getString("town")));
|
||||
Instant siegeGrace = sideResult.getTimestamp("siegeGrace").toInstant();
|
||||
Instant raidGrace = sideResult.getTimestamp("raidGrace").toInstant();
|
||||
|
||||
Set<UUID> players = loadSidePlayers(con, uuid, false);
|
||||
Set<UUID> playersSurrendered = loadSidePlayers(con, uuid, true);
|
||||
Set<Nation> nations = loadSideNations(con, uuid, false);
|
||||
Set<Nation> nationsSurrendered = loadSideNations(con, uuid, true);
|
||||
Set<Town> towns = loadSideTowns(con, uuid, false);
|
||||
Set<Town> townsSurrendered = loadSideTowns(con, uuid, true);
|
||||
@NotNull Set<UUID> players = loadSidePlayers(con, uuid, false);
|
||||
@NotNull Set<UUID> playersSurrendered = loadSidePlayers(con, uuid, true);
|
||||
@NotNull Set<Nation> nations = loadSideNations(con, uuid, false);
|
||||
@NotNull Set<Nation> nationsSurrendered = loadSideNations(con, uuid, true);
|
||||
@NotNull Set<Town> towns = loadSideTowns(con, uuid, false);
|
||||
@NotNull Set<Town> townsSurrendered = loadSideTowns(con, uuid, true);
|
||||
|
||||
return new Side(
|
||||
warUUID,
|
||||
@@ -397,8 +406,8 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<UUID> loadSidePlayers(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<UUID> players = new HashSet<>();
|
||||
public static @NotNull Set<UUID> loadSidePlayers(@NotNull Connection con, @NotNull UUID sideUUID, boolean surrendered) {
|
||||
@NotNull Set<UUID> players = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
@@ -417,8 +426,8 @@ public class SQLQueries {
|
||||
return players;
|
||||
}
|
||||
|
||||
public static Set<Nation> loadSideNations(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<Nation> nations = new HashSet<>();
|
||||
public static @NotNull Set<Nation> loadSideNations(@NotNull Connection con, @NotNull UUID sideUUID, boolean surrendered) {
|
||||
@NotNull Set<Nation> nations = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
@@ -428,7 +437,7 @@ public class SQLQueries {
|
||||
throw new SQLException("Failed to get nations from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
final UUID uuid = UUID.fromString(warsResult.getString("nation"));
|
||||
final @NotNull UUID uuid = UUID.fromString(warsResult.getString("nation"));
|
||||
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(uuid);
|
||||
if (nation == null) continue;
|
||||
@@ -442,8 +451,8 @@ public class SQLQueries {
|
||||
return nations;
|
||||
}
|
||||
|
||||
public static Set<Town> loadSideTowns(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<Town> towns = new HashSet<>();
|
||||
public static @NotNull Set<Town> loadSideTowns(@NotNull Connection con, @NotNull UUID sideUUID, boolean surrendered) {
|
||||
@NotNull Set<Town> towns = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
@@ -453,7 +462,7 @@ public class SQLQueries {
|
||||
throw new SQLException("Failed to get towns from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
final UUID uuid = UUID.fromString(warsResult.getString("town"));
|
||||
final @NotNull UUID uuid = UUID.fromString(warsResult.getString("town"));
|
||||
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(uuid);
|
||||
if (town == null) continue;
|
||||
@@ -467,10 +476,71 @@ public class SQLQueries {
|
||||
return towns;
|
||||
}
|
||||
|
||||
public static void deleteWar(War war) {
|
||||
public static @NotNull Set<Siege> loadSieges(@NotNull Connection con, @NotNull War war) {
|
||||
@NotNull Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
try (PreparedStatement siegesStatement = con.prepareStatement("SELECT * FROM `wars_sieges` WHERE `war` = ?")) {
|
||||
siegesStatement.setString(1, war.getUUID().toString());
|
||||
ResultSet siegesResults = siegesStatement.executeQuery();
|
||||
|
||||
if (siegesResults == null)
|
||||
throw new SQLException("Failed to get sieges from DB");
|
||||
|
||||
while (siegesResults.next()) {
|
||||
final UUID uuid = UUID.fromString(siegesResults.getString("uuid"));
|
||||
final @Nullable Town town = TownyAPI.getInstance().getTown(UUID.fromString(siegesResults.getString("town")));
|
||||
final OfflinePlayer siegeLeader = Bukkit.getOfflinePlayer(UUID.fromString(siegesResults.getString("siegeLeader")));
|
||||
final Instant endTime = siegesResults.getTimestamp("endTime").toInstant();
|
||||
final Instant lastTouched = siegesResults.getTimestamp("lastTouched").toInstant();
|
||||
final int siegeProgress = siegesResults.getInt("siegeProgress");
|
||||
final Set<UUID> attackersIncludingOffline = loadSiegePlayers(con, uuid, true);
|
||||
final Set<UUID> defendersIncludingOffline = loadSiegePlayers(con, uuid, false);
|
||||
|
||||
if (town == null) continue;
|
||||
|
||||
sieges.add(new Siege(
|
||||
war,
|
||||
uuid,
|
||||
town,
|
||||
siegeLeader,
|
||||
endTime,
|
||||
lastTouched,
|
||||
siegeProgress,
|
||||
attackersIncludingOffline,
|
||||
defendersIncludingOffline
|
||||
));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sieges;
|
||||
}
|
||||
|
||||
public static @NotNull Set<UUID> loadSiegePlayers(@NotNull Connection con, @NotNull UUID siegeUUID, boolean getAttackers) {
|
||||
@NotNull Set<UUID> players = new HashSet<>();
|
||||
|
||||
try (PreparedStatement siegeStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `siege` = ?".formatted(getAttackers ? "wars_sieges_players_attackers" : "wars_sieges_players_defenders"))) {
|
||||
siegeStatement.setString(1, siegeUUID.toString());
|
||||
ResultSet playersResult = siegeStatement.executeQuery();
|
||||
|
||||
if (playersResult == null)
|
||||
throw new SQLException("Failed to get players from DB");
|
||||
|
||||
while (playersResult.next()) {
|
||||
players.add(UUID.fromString(playersResult.getString("player")));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
public static void deleteWar(@NotNull War war) {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("DELETE FROM `wars_list` WHERE `uuid` = ?");
|
||||
@NotNull Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("DELETE FROM `wars_list` WHERE `uuid` = ?")
|
||||
) {
|
||||
// Delete war data
|
||||
warStatement.setString(1, war.getUUID().toString());
|
||||
@@ -480,10 +550,10 @@ public class SQLQueries {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteSiege(Siege siege) {
|
||||
public static void deleteSiege(@NotNull Siege siege) {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement siegesStatement = con.prepareStatement("DELETE FROM `wars_sieges` WHERE `uuid` = ?");
|
||||
@NotNull Connection con = DB.get();
|
||||
PreparedStatement siegesStatement = con.prepareStatement("DELETE FROM `wars_sieges` WHERE `uuid` = ?")
|
||||
) {
|
||||
// Delete siege data
|
||||
siegesStatement.setString(1, siege.getUUID().toString());
|
||||
@@ -492,4 +562,65 @@ public class SQLQueries {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSiege(@NotNull Connection con, @NotNull Siege siege) {
|
||||
try (
|
||||
PreparedStatement siegeStatement = con.prepareStatement("INSERT INTO `wars_sieges` (`war`, `uuid`, `town`, `siegeLeader`, `endTime`, `lastTouched`, `siegeProgress`) VALUES (?, ?, ?, ?, ?, ?, ?) "
|
||||
+ "ON DUPLICATE KEY UPDATE `war` = ?, `town` = ?, `siegeLeader` = ?, `endTime` = ?, `lastTouched` = ?, `siegeProgress` = ?")
|
||||
) {
|
||||
// Insert
|
||||
siegeStatement.setString(1, siege.getWar().getUUID().toString());
|
||||
siegeStatement.setString(2, siege.getUUID().toString());
|
||||
siegeStatement.setString(3, siege.getTown().getUUID().toString());
|
||||
siegeStatement.setString(4, siege.getSiegeLeader().getUniqueId().toString());
|
||||
siegeStatement.setTimestamp(5, Timestamp.from(siege.getEndTime()));
|
||||
siegeStatement.setTimestamp(6, Timestamp.from(siege.getLastTouched()));
|
||||
siegeStatement.setInt(7, siege.getSiegeProgress());
|
||||
|
||||
// Update
|
||||
siegeStatement.setString(8, siege.getWar().getUUID().toString());
|
||||
siegeStatement.setString(9, siege.getTown().getUUID().toString());
|
||||
siegeStatement.setString(10, siege.getSiegeLeader().getUniqueId().toString());
|
||||
siegeStatement.setTimestamp(11, Timestamp.from(siege.getEndTime()));
|
||||
siegeStatement.setTimestamp(12, Timestamp.from(siege.getLastTouched()));
|
||||
siegeStatement.setInt(13, siege.getSiegeProgress());
|
||||
|
||||
siegeStatement.executeUpdate();
|
||||
|
||||
saveSiegePlayers(con, siege, false);
|
||||
saveSiegePlayers(con, siege, true);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSiegePlayers(@NotNull Connection con, @NotNull Siege siege, boolean isAttacker) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `siege` = ?".formatted(isAttacker ? "wars_sieges_players_attackers" : "wars_sieges_players_defenders"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`siege`, `player`) VALUES (?, ?)".formatted(isAttacker ? "wars_sieges_players_attackers" : "wars_sieges_players_defenders"))
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
con.setAutoCommit(false);
|
||||
|
||||
// Delete old
|
||||
deleteStatement.setString(1, siege.getUUID().toString());
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (@NotNull UUID uuid : (isAttacker ? siege.getAttackerPlayersIncludingOffline() : siege.getDefenderPlayersIncludingOffline())) {
|
||||
insertStatement.setString(1, siege.getUUID().toString());
|
||||
insertStatement.setString(2, uuid.toString());
|
||||
insertStatement.executeUpdate();
|
||||
}
|
||||
|
||||
// Transaction end
|
||||
con.commit();
|
||||
} catch (Exception e) {
|
||||
con.rollback();
|
||||
} finally {
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDUtil {
|
||||
public static UUID generateWarUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
public static @NotNull UUID generateWarUUID() {
|
||||
@NotNull UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getWar(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
@@ -16,8 +17,8 @@ public class UUIDUtil {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static UUID generateSideUUID(@Nullable UUID previousSideUUID) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
public static @NotNull UUID generateSideUUID(@Nullable UUID previousSideUUID) {
|
||||
@NotNull UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getSide(uuid) != null || uuid == previousSideUUID) {
|
||||
uuid = UUID.randomUUID();
|
||||
@@ -26,8 +27,8 @@ public class UUIDUtil {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static UUID generateSiegeUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
public static @NotNull UUID generateSiegeUUID() {
|
||||
@NotNull UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getSiege(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -42,8 +43,8 @@ public class Utils {
|
||||
* @param p
|
||||
* @author ShermansWorld
|
||||
*/
|
||||
public static void damageAllGear(Player p) {
|
||||
for (ItemStack itemStack : p.getInventory().getContents()) {
|
||||
public static void damageAllGear(@NotNull Player p) {
|
||||
for (@Nullable ItemStack itemStack : p.getInventory().getContents()) {
|
||||
if (itemStack == null)
|
||||
continue;
|
||||
|
||||
@@ -52,9 +53,9 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
final ItemStack @NotNull [] armor = p.getInventory().getArmorContents();
|
||||
|
||||
for (ItemStack itemStack : armor) {
|
||||
for (@Nullable ItemStack itemStack : armor) {
|
||||
if (itemStack == null)
|
||||
continue;
|
||||
|
||||
@@ -195,10 +196,10 @@ public class Utils {
|
||||
* @return List of connected chunks
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
|
||||
ArrayList<WorldCoord> worldCoords = new ArrayList<>();
|
||||
private static @NotNull ArrayList<WorldCoord> getAdjCells(@NotNull WorldCoord worldCoord) {
|
||||
@NotNull ArrayList<WorldCoord> worldCoords = new ArrayList<>();
|
||||
|
||||
int[][] XZarray = new int[][]{
|
||||
int[] @NotNull [] XZarray = new int[][]{
|
||||
{-1, 0},
|
||||
{1, 0},
|
||||
{0, -1},
|
||||
@@ -207,7 +208,7 @@ public class Utils {
|
||||
|
||||
for (int[] pair : XZarray) {
|
||||
// Constructs new WorldCoord for comparison
|
||||
WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
||||
@NotNull WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
||||
if (tCoord.getTownOrNull() != null && tCoord.getTownOrNull() == worldCoord.getTownOrNull()) {
|
||||
// If in town, and in same town, adds to return list
|
||||
worldCoords.add(tCoord);
|
||||
@@ -223,15 +224,15 @@ public class Utils {
|
||||
* @return List of WorldCoords
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord) {
|
||||
public static @NotNull ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord) {
|
||||
// worldCoords is the returning array, searchList is the to-search list.
|
||||
ArrayList<WorldCoord> worldCoords = new ArrayList<>();
|
||||
ArrayList<WorldCoord> searchList = new ArrayList<>(Collections.singletonList(chunkCoord)); // Adds 1st chunk to list
|
||||
@NotNull ArrayList<WorldCoord> worldCoords = new ArrayList<>();
|
||||
@NotNull ArrayList<WorldCoord> searchList = new ArrayList<>(Collections.singletonList(chunkCoord)); // Adds 1st chunk to list
|
||||
|
||||
// Iterates through searchList, to create a full list of every adjacent cell.
|
||||
while (!searchList.isEmpty()) {
|
||||
WorldCoord toSearch = searchList.get(0); // Gets WorldCoord
|
||||
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch); // Gets adjacent cells
|
||||
@NotNull ArrayList<WorldCoord> adjCells = getAdjCells(toSearch); // Gets adjacent cells
|
||||
|
||||
for (WorldCoord cell : adjCells) {
|
||||
if (worldCoords.contains(cell)) continue; // If in final list, ignore.
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UtilsChat {
|
||||
public static String getPrefix() {
|
||||
public static @NotNull String getPrefix() {
|
||||
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>]<reset> ";
|
||||
}
|
||||
|
||||
public static String color(final String input) {
|
||||
public static @NotNull String color(final @NotNull String input) {
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user