refactor: wip update 7

This commit is contained in:
darksaid98 committed 2023-07-25 06:29:51 +02:00
1 parent 03cb3a4d1c
commit 51830514ec
50 files changed
+1546 -739

No files matched your search

File diff suppressed because it is too large. Load diff
+321
View File
@@ -0,0 +1,321 @@
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.BattleTeam;
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.Town;
import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.BooleanArgument;
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.HashSet;
import java.util.Set;
public class SiegeCommand {
public SiegeCommand() {
new CommandAPICommand("siege")
.withSubcommands(
commandStart(),
commandStop(),
commandAbandon(),
commandList(),
commandHelp()
)
.executesPlayer((sender, args) -> {
if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
})
.register();
}
public static CommandAPICommand commandStart() {
return new CommandAPICommand("start")
.withPermission("AlathranWars.admin")
.withArguments(
CommandUtil.warWarArgument(
"war",
false,
false,
""
),
CommandUtil.customSiegeAttackableTownArgument(
"town",
"war",
false,
true
),
new PlayerArgument("leader")
.setOptional(true)
.withPermission("AlathranWars.admin"),
new BooleanArgument("minutemen")
.setOptional(true)
.withPermission("AlathranWars.admin")
)
.executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false));
}
public static CommandAPICommand commandStop() {
return new CommandAPICommand("stop")
.withPermission("AlathranWars.admin")
.withArguments(
CommandUtil.warWarArgument(
"war",
false,
false,
""
),
CommandUtil.customSiegeAttackableTownArgument(
"town",
"war",
false,
false
)
)
.executesPlayer(SiegeCommand::siegeStop);
}
public static CommandAPICommand commandAbandon() {
return new CommandAPICommand("abandon")
.withArguments(
CommandUtil.warWarArgument(
"war",
false,
false,
""
),
CommandUtil.customSiegeAttackableTownArgument(
"town",
"war",
false,
false
)
)
.executesPlayer(SiegeCommand::siegeAbandon);
}
public static CommandAPICommand commandList() {
return new CommandAPICommand("list")
.executesPlayer(SiegeCommand::siegeList);
}
public static CommandAPICommand commandHelp() {
return new CommandAPICommand("help")
.executesPlayer(SiegeCommand::siegeHelp);
}
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());
//if this is admin mode use the forth arg instad of sender.
//if player is null after this then force end
final @NotNull Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
if (siegeOwner == null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("You need to pick a valid leader.").build());
// Player participance check
@Nullable Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
@Nullable Side side = war.getTownSide(leaderTown);
// TODO DEBUG PRINT
// Main.warLogger.log("Leader Town: " + leaderTown.getName());
// Main.warLogger.log("Siege Owner: " + siegeOwner.getName());
// sender.sendMessage("Leader Town: " + leaderTown.getName());
// sender.sendMessage("Siege Owner: " + siegeOwner.getName());
// TODO DEBUG PRINT
/*for (String t : war.getSide1Towns()) {
Main.warLogger.log("Side1 town: " + t);
sender.sendMessage("Side1 town: " + t);
}
for (String t : war.getSide2Towns()) {
Main.warLogger.log("Side2 town: " + t);
sender.sendMessage("Side2 town: " + t);
}*/
if (!war.isTownInWar(leaderTown)) {
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(ColorParser.of(UtilsChat.getPrefix() + "You are under occupation.").build());
if (admin) sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You are under occupation.").build());
return;
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
//Minuteman countermeasures
/*int minuteman = CommandHelper.isPlayerMinuteman(siegeOwner.getName());
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
if (minuteManOverride) {
sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
}
//override?
if (!minuteManOverride) {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin)
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin)
sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
}
}*/
// Is being raided check
/*for (OldRaid r : RaidData.getRaids()) {
if (r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot siege at this time!");
if (admin)
sender.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot siege at this time!");
return;
}
}*/
// Attacking own side
if (side.isTownOnSide(town)) {
siegeOwner.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
if (admin)
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
return;
}
@NotNull Siege siege = new Siege(war, town, siegeOwner);
war.addSiege(siege);
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
if (admin)
sender.sendMessage(ColorParser.of("<red>Forcefully started siege from the console.").build());
siege.start();
// TODO Debug logs...
// Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
// sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
}
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 @NotNull Town town))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
final @NotNull Set<Siege> sieges = war.getSieges();
if (sieges.isEmpty())
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress!").build());
for (@NotNull Siege siege : sieges) {
if (siege.getTown().getUUID().equals(town.getUUID()) && siege.getWar().equals(war)) {
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(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, @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 @NotNull Town town))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
@Nullable Siege siege = null;
for (@NotNull Siege siegeVar : war.getSieges()) {
if (siegeVar.getTown().getUUID().equals(town.getUUID())) {
siege = siegeVar;
break;
}
}
if (siege == null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid siege").build());
@NotNull OfflinePlayer oPlayer = siege.getSiegeLeader();
if (oPlayer != p) {
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "You are not the leader of this siege.").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(@NotNull Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
@NotNull Set<War> wars = WarManager.getInstance().getWars();
@NotNull Set<Siege> sieges = new HashSet<>();
for (@NotNull War war : wars) {
sieges.addAll(war.getSieges());
}
if (sieges.isEmpty())
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress.").build());
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
for (@NotNull Siege siege : sieges) {
@NotNull War war = siege.getWar();
final @NotNull String color = (siege.getSide1AreAttackers() && (war.getTownSide(siege.getTown()).getTeam().equals(BattleTeam.SIDE_1))) ? "<red>" : "<blue>";
sender.sendMessage(
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(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(@NotNull Player sender, CommandArguments args) {
if (sender.hasPermission("AlathranWars.admin")) {
sender.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "/siege stop [war] [town]").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());
}
}
+404
View File
@@ -0,0 +1,404 @@
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 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() {
new CommandAPICommand("war")
.withSubcommands(
commandCreate(),
commandDelete(),
commandJoin(),
commandSurrender(),
commandList(),
// commandInfo(),
commandHelp()
)
.executesPlayer((sender, args) -> {
if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
})
.register();
}
public static CommandAPICommand commandCreate() {
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(WarCommand::warCreate);
}
public static CommandAPICommand commandDelete() {
return new CommandAPICommand("delete")
.withPermission("AlathranWars.admin")
.withArguments(
CommandUtil.warWarArgument("war", false, false, "")
)
.executesPlayer(WarCommand::warDelete);
}
public static CommandAPICommand commandJoin() {
return new CommandAPICommand("join")
.withArguments(
CommandUtil.warWarArgument("war", false, true, ""),
CommandUtil.warSideCreateArgument("side", "war", false, true, ""),
new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin.join")
)
.executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false));
}
public static CommandAPICommand commandSurrender() {
return new CommandAPICommand("surrender")
.withArguments(
CommandUtil.warWarArgument("war", false, false, "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(WarCommand::warList);
}
/*public static CommandAPICommand commandInfo() {
return new CommandAPICommand("info")
.withArguments(
new PlayerArgument("player")
)
.executesPlayer(WarCommand::warInfo);
}*/
public static CommandAPICommand commandHelp() {
return new CommandAPICommand("help")
.executesPlayer(WarCommand::warHelp);
}
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(ColorParser.of(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
@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);
@Nullable Town town2 = TownyAPI.getInstance().getTown(townName2);
@Nullable Nation nation1 = TownyAPI.getInstance().getNation(townName1);
@Nullable Nation nation2 = TownyAPI.getInstance().getNation(townName2);
// Automatically elevate town wars to nation level if possible (This may be undesirable in terms of allowing civil wars etc)
if (town1 != null && town1.getNationOrNull() != null) {
nation1 = town1.getNationOrNull();
}
if (town2 != null && town2.getNationOrNull() != null) {
nation2 = town2.getNationOrNull();
}
// TODO Ensure side1 valid
// TODO Ensure side2 valid
// TODO Deep Check if war exists where the same sides are fighting???
// Create war depending on what args have been passed, attempt to create nation wars first
if (nation1 != null) {
if (nation2 != null) {
new War(argLabel, nation1, nation2);
} else if (town2 != null) {
new War(argLabel, nation1, town2);
}
} else if (town1 != null) {
if (town2 != null) {
new War(argLabel, town1, town2);
} else if (nation2 != null) {
new War(argLabel, town1, nation2);
}
}
/*for (War war1 : WarManager.getInstance().getWars()) {
war.
}*/
// Check if side1 is nation or town
// Check if side2 is nation or town
// Check if opposing factions are already at war?
/*Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
+ " vs. " + argSide2);*/
}
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, @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 @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);
}
}
}
/**
* @param p - executor
* @param args
* @param admin - admin behavior
*/
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 @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());
// Towny Resident Object, if admin then dont use command runner, use declared player
@Nullable Resident res = TownyAPI.getInstance().getResident(argPlayer);
// Town check
@Nullable Town town = res.getTownOrNull();
if (town == null) {
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(ChatColor.RED + "You are not in a town.").build());
}
//Minuteman countermeasures
// final int minuteman = CommandHelper.isPlayerMinuteman(argPlayer.getName());
// final boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
//
// if (minuteManOverride) {
// p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
// }
//
// //override?
// if (!minuteManOverride) {
// if (minuteman != 0) {
// if (minuteman == 1) {
// //player has joined to recently
// if (admin)
// p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
// argPlayer.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
// return;
// } else if (minuteman == 2) {
// //player has played too little
// if (admin)
// p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
// argPlayer.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
// return;
// }
// }
// }
// Side checks
if (war.getSurrenderedTowns().contains(town)) {
argPlayer.sendMessage(UtilsChat.getPrefix() + "You've already surrendered!");
return;
}
if (res.hasNation()) {
if (res.getPlayer().hasPermission("AlathranWars.nationjoin") || res.isKing()) {
// Has nation declaration permission
side.addNation(res.getNationOrNull());
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
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(ColorParser.of(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
}
} else if (res.hasTown()) {
if (res.getPlayer().hasPermission("AlathranWars.townjoin") || res.isMayor()) {
// Is in indepdenent town & has declaration perms
side.addTown(res.getTownOrNull());
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
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(ColorParser.of(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
}
}
}
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(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 the war.").build());
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(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 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(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(ColorParser.of(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
}
}
}
private static void warList(@NotNull Player p, CommandArguments args) throws WrapperCommandSyntaxException {
@NotNull Set<War> wars = WarManager.getInstance().getWars();
if (wars.isEmpty()) {
p.sendMessage(ColorParser.of("There are no wars at the moment, the world is at peace.").build());
} else {
p.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "Wars:").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(ColorParser.of(UtilsChat.getPrefix() + "/war info [Player]").build());
}
if (!(args.get("player") instanceof Player argsPlayer))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("Specify a player.").build());
Resident res = TownyAPI.getInstance().getResident(argsPlayer);
if (res == null || res.getTownOrNull() == null) {
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "Invalid town resident.").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) {
if (side == TownWarState.SURRENDERED) {
p.sendMessage(war.getName() + " - Surrendered");
} else if (side == TownWarState.SIDE1) {
p.sendMessage(war.getName() + " - " + war.getSide1());
} else if (side == TownWarState.SIDE2) {
p.sendMessage(war.getName() + " - " + war.getSide2());
}
}
}
}*/
private static void warHelp(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
// TODO
}
/**
* Method for console access
*
* @param sender
* @param args
*/
// private static void consoleCommand(CommandSender sender, CommandArguments args) {
// if (args.length < 1) return;
// if (args[0].equalsIgnoreCase("list")) {
// ArrayList<War> warList = WarManager.getInstance().getWars();
// sender.sendMessage("Wars: " + warList.size());
// for (War war : WarManager.getInstance().getWars()) {
// if (war == null) continue;
// sender.sendMessage(war.toString());
// }
// }
// }
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.