refactor: prepare for raids

- Recode most classes
- Add phases to battles
- Pull updates from gradle-template-plugin
This commit is contained in:
darksaid98 committed 2024-09-21 10:37:15 +02:00
1 parent a4440c9283
commit b1a95ed011
105 files changed
+6941 -3296

No files matched your search

@@ -1,7 +1,7 @@
package com.github.alathra.alathranwars.commands;
import com.github.alathra.alathranwars.AlathranWars;
import com.github.alathra.alathranwars.hooks.NameColorHandler;
import com.github.alathra.alathranwars.hook.NameColorHandler;
import com.github.alathra.alathranwars.items.WarItemRegistry;
import com.github.alathra.alathranwars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -4,15 +4,20 @@ import com.github.alathra.alathranwars.AlathranWars;
import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;
public class CommandManager {
private final AlathranWars instance;
public class CommandHandler {
private final AlathranWars plugin;
public CommandManager(AlathranWars instance) {
this.instance = instance;
/**
* Instantiates the Command handler.
*
* @param plugin the plugin
*/
public CommandHandler(AlathranWars plugin) {
this.plugin = plugin;
}
public void onLoad() {
CommandAPI.onLoad(new CommandAPIBukkitConfig(instance).shouldHookPaperReload(true).silentLogs(true));
CommandAPI.onLoad(new CommandAPIBukkitConfig(plugin).shouldHookPaperReload(true).silentLogs(true));
}
public void onEnable() {
@@ -7,7 +7,6 @@ import com.github.alathra.alathranwars.conflict.war.WarController;
import com.github.alathra.alathranwars.conflict.war.side.Side;
import com.github.alathra.alathranwars.enums.CommandArgsSiege;
import com.github.alathra.alathranwars.enums.CommandArgsWar;
import com.github.alathra.alathranwars.hooks.TownyHook;
import com.github.alathra.alathranwars.items.WarItemRegistry;
import com.github.alathra.alathranwars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -31,10 +30,7 @@ import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -66,7 +62,7 @@ public class CommandUtil {
return TownyAPI.getInstance().getNation(argNationName);
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final @NotNull List<String> nationNames = TownyHook.getNations()
final @NotNull List<String> nationNames = TownyAPI.getInstance().getNations()
.stream()
.map(Nation::getName)
.sorted()
@@ -85,7 +81,7 @@ public class CommandUtil {
return TownyAPI.getInstance().getTown(argTownName);
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final @NotNull List<String> townNames = TownyHook.getTowns()
final @NotNull List<String> townNames = TownyAPI.getInstance().getTowns()
.stream()
.map(Town::getName)
.sorted()
@@ -107,17 +103,17 @@ public class CommandUtil {
@Nullable Nation nation = TownyAPI.getInstance().getNation(argNationName);
if (war.getNations().contains(nation) || war.getSurrenderedNations().contains(nation))
if (war.getNations().contains(nation) || war.getNationsSurrendered().contains(nation))
return nation;
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation is already at war!").parseLegacy().build());
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final @NotNull List<String> nationNames = TownyHook.getNations()
final @NotNull List<String> nationNames = TownyAPI.getInstance().getNations()
.stream()
.map(Nation::getName)
.sorted()
.collect(Collectors.toList());
final @NotNull List<String> townNames = TownyHook.getTowns()
final @NotNull List<String> townNames = TownyAPI.getInstance().getTowns()
.stream()
.map(Town::getName)
.sorted()
@@ -131,7 +127,7 @@ public class CommandUtil {
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)
war.getNationsSurrendered().stream().map(Nation::getName)
).toList();
nationNames.removeAll(removeNames);
@@ -152,12 +148,12 @@ public class CommandUtil {
@Nullable Town town = TownyAPI.getInstance().getTown(argTownName);
if (war.getTowns().contains(town) || war.getSurrenderedTowns().contains(town))
if (war.getTowns().contains(town) || war.getTownsSurrendered().contains(town))
return town;
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is already at war!").parseLegacy().build());
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final @NotNull List<String> townNames = TownyHook.getTowns()
final @NotNull List<String> townNames = TownyAPI.getInstance().getTowns()
.stream()
.map(Town::getName)
.sorted()
@@ -169,7 +165,7 @@ public class CommandUtil {
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)
war.getTownsSurrendered().stream().map(Town::getName)
).toList();
townNames.removeAll(removeNames);
@@ -188,7 +184,7 @@ public class CommandUtil {
if (nation == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
if (!war.isNationInWar(nation))
if (!war.isInWar(nation))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The nation is not in that war!").parseLegacy().build());
return nation;
@@ -198,7 +194,7 @@ public class CommandUtil {
return Stream.concat( // Create a list of all nations & towns in war
war.getNations().stream().map(Nation::getName),
war.getSurrenderedNations().stream().map(Nation::getName)
war.getNationsSurrendered().stream().map(Nation::getName)
).sorted().toList();
}));
}
@@ -213,7 +209,7 @@ public class CommandUtil {
if (town == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
if (!war.isTownInWar(town))
if (!war.isInWar(town))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
return town;
@@ -223,7 +219,7 @@ public class CommandUtil {
return Stream.concat( // Create a list of all nations & towns in war
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
war.getTownsSurrendered().stream().map(Town::getName)
).sorted().toList();
}));
}
@@ -256,12 +252,12 @@ public class CommandUtil {
.build()
);
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final @NotNull List<String> nationNames = TownyHook.getNations()
final @NotNull List<String> nationNames = TownyAPI.getInstance().getNations()
.stream()
.map(Nation::getName)
.sorted()
.collect(Collectors.toList());
final @NotNull List<String> townNames = TownyHook.getTowns()
final @NotNull List<String> townNames = TownyAPI.getInstance().getTowns()
.stream()
.map(Town::getName)
.sorted()
@@ -276,10 +272,10 @@ public class CommandUtil {
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),
war.getNationsSurrendered().stream().map(Nation::getName),
Stream.concat(
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
war.getTownsSurrendered().stream().map(Town::getName)
)
)
).toList();
@@ -301,9 +297,9 @@ public class CommandUtil {
);
}
final List<String> townNames = war.getTowns().stream().map(Town::getName).sorted().toList();
final List<String> nationNames = war.getNations().stream().map(Nation::getName).sorted().toList();
final List<String> playerNames = war.getPlayersIncludingOffline().stream()
final List<String> townNames = war.getTownsAll().stream().map(Town::getName).sorted().toList();
final List<String> nationNames = war.getNationsAll().stream().map(Nation::getName).sorted().toList();
final List<String> playerNames = war.getPlayersAll().stream()
.filter(offlinePlayer -> Instant.ofEpochMilli(offlinePlayer.getLastSeen()).isAfter(Instant.now().minus(Duration.ofDays(60)))) // Remove players that haven't been on in 60 days
.filter(p -> p.getName() != null)
.map(OfflinePlayer::getName)
@@ -330,12 +326,12 @@ public class CommandUtil {
return Collections.emptyList();
}
final List<String> nationNames = war.getNations().stream().map(Nation::getName).sorted().toList();
final List<String> townNames = war.getTowns().stream().map(Town::getName).sorted().toList();
final List<String> playerNames = war.getPlayersIncludingOffline().stream()
final List<String> nationNames = war.getNationsAll().stream().map(Nation::getName).sorted().toList();
final List<String> townNames = war.getTownsAll().stream().map(Town::getName).sorted().toList();
final List<String> playerNames = war.getPlayersAll().stream()
.filter(offlinePlayer -> Instant.ofEpochMilli(offlinePlayer.getLastSeen()).isAfter(Instant.now().minus(Duration.ofDays(60)))) // Remove players that haven't been on in 60 days
.filter(p -> p.getName() != null)
.map(OfflinePlayer::getName)
.filter(Objects::nonNull)
.sorted()
.toList();
@@ -358,7 +354,7 @@ public class CommandUtil {
if (town == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
if (!war.isTownInWar(town))
if (!war.isInWar(town))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
if (checkIfSieged) {
@@ -376,14 +372,14 @@ public class CommandUtil {
final @NotNull List<String> townNames = new ArrayList<>();
if (info.sender() instanceof Player p) {
if (war.getSide1().isPlayerOnSide(p)) {
if (war.getSide1().isOnSide(p)) {
townNames.addAll(war.getSide2().getTowns()
.stream()
.map(TownyObject::getName)
.sorted()
.toList()
);
} else if (war.getSide2().isPlayerOnSide(p)) {
} else if (war.getSide2().isOnSide(p)) {
townNames.addAll(war.getSide1().getTowns()
.stream()
.map(TownyObject::getName)
@@ -418,13 +414,13 @@ public class CommandUtil {
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))
if (!siege.isPlayerParticipating(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))
if (!siege.isPlayerParticipating(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
}
}
@@ -433,13 +429,13 @@ public class CommandUtil {
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))
if (siege.isPlayerParticipating(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))
if (siege.isPlayerParticipating(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are not in that war.").build());
}
}
@@ -462,11 +458,11 @@ public class CommandUtil {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerParticipating(player)).map(Siege::getName).toList();
}
} else {
if (info.sender() instanceof Player player) {
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerParticipating(player)).map(Siege::getName).toList();
}
}
@@ -478,11 +474,11 @@ public class CommandUtil {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerParticipating(player)).map(Siege::getName).toList();
}
} else {
if (info.sender() instanceof Player player) {
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerParticipating(player)).map(Siege::getName).toList();
}
}
@@ -503,13 +499,13 @@ public class CommandUtil {
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))
if (!war.isInWar(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))
if (!war.isInWar(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already in this war.").parseLegacy().build());
}
}
@@ -518,13 +514,13 @@ public class CommandUtil {
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))
if (war.isInWar(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))
if (war.isInWar(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are not in that war.").parseLegacy().build());
}
}
@@ -547,11 +543,11 @@ public class CommandUtil {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isInWar(player)).map(War::getName).toList();
}
} else {
if (info.sender() instanceof Player player) {
warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isInWar(player)).map(War::getName).toList();
}
}
@@ -563,11 +559,11 @@ public class CommandUtil {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
warNames = WarController.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
warNames = WarController.getInstance().getWars().stream().filter(war -> war.isInWar(player)).map(War::getName).toList();
}
} else {
if (info.sender() instanceof Player player) {
warNames = WarController.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
warNames = WarController.getInstance().getWars().stream().filter(war -> war.isInWar(player)).map(War::getName).toList();
}
}
@@ -594,13 +590,13 @@ public class CommandUtil {
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 (side.getPlayers().contains(player))
if (side.getPlayersOnline().contains(player))
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(ColorParser.of(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
if (side.getPlayers().contains(player))
if (side.getPlayersOnline().contains(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>You are already on that side.").parseLegacy().build());
}
}
@@ -616,14 +612,14 @@ public class CommandUtil {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
for (@NotNull Side side : war.getSides()) {
if (!side.getPlayers().contains(player))
if (!side.getPlayersOnline().contains(player))
sideNames.add(side.getName());
}
}
} else {
if (info.sender() instanceof Player player) {
for (@NotNull Side side : war.getSides()) {
if (!side.getPlayers().contains(player))
if (!side.getPlayersOnline().contains(player))
sideNames.add(side.getName());
}
}
@@ -655,7 +651,7 @@ public class CommandUtil {
if (isTown && !war.getTowns().stream().map(Town::getName).toList().contains(argTargetName))
return argTargetName;
if (isPlayer && !war.getPlayers().stream().map(Player::getName).toList().contains(argTargetName))
if (isPlayer && !war.getPlayersOnline().stream().map(Player::getName).toList().contains(argTargetName))
return argTargetName;
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>Invalid target.").build());
@@ -665,7 +661,7 @@ public class CommandUtil {
// Get all participants in war into list
final List<String> inWar = Stream.concat(
war.getPlayers().stream().map(Player::getName),
war.getPlayersOnline().stream().map(Player::getName),
Stream.concat(
war.getNations().stream().map(Nation::getName),
war.getTowns().stream().map(Town::getName)
@@ -119,7 +119,7 @@ public class SiegeCommands {
if (side == null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in this war.").build());
if (side.isPlayerSurrendered(siegeLeader))
if (side.isSurrendered(siegeLeader))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You have surrendered and cannot participate in this war.").build());
if (side.isSiegeGraceActive() && !asAdmin)
@@ -130,7 +130,7 @@ public class SiegeCommands {
);
// Attacking own side
if (side.isTownOnSide(town) && !side.isTownSurrendered(town)) {
if (side.isOnSide(town) && !side.isSurrendered(town)) {
if (asAdmin)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot attack your own side.").build());
else
@@ -152,7 +152,7 @@ public class SiegeCommands {
if (location.distance(townLocation) <= Siege.BATTLEFIELD_START_MIN_RANGE && !asAdmin)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to be further than <range> blocks away from the town to start a siege!").parseMinimessagePlaceholder("range", String.valueOf(Siege.BATTLEFIELD_START_MIN_RANGE)).build());
if ((AlathranWars.econ.getBalance(siegeLeader) < Siege.SIEGE_VICTORY_MONEY) && !asAdmin)
if ((AlathranWars.getVaultHook().isEconomyLoaded() && AlathranWars.getVaultHook().getEconomy().getBalance(siegeLeader) < Siege.SIEGE_VICTORY_MONEY) && !asAdmin)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You need to have $<amount> to start a siege!").parseMinimessagePlaceholder("amount", String.valueOf(Siege.SIEGE_VICTORY_MONEY)).build());
side.setSiegeGrace();
@@ -5,7 +5,7 @@ import com.github.alathra.alathranwars.conflict.war.WarBuilder;
import com.github.alathra.alathranwars.conflict.war.WarController;
import com.github.alathra.alathranwars.conflict.war.side.Side;
import com.github.alathra.alathranwars.conflict.war.side.SideCreationException;
import com.github.alathra.alathranwars.hooks.NameColorHandler;
import com.github.alathra.alathranwars.hook.NameColorHandler;
import com.github.alathra.alathranwars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.TownyAPI;
@@ -249,8 +249,8 @@ public class WarCommands {
if (!war.isEventWar()) {
// Join nation into war
if (isArgNation && nation != null && !war.isNationInWar(nation) && (asAdmin || canKingJoin)) {
side.addNation(nation);
if (isArgNation && nation != null && !war.isInWar(nation) && (asAdmin || canKingJoin)) {
side.add(nation);
nation.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(player -> NameColorHandler.getInstance().calculatePlayerColors(player));
Bukkit.broadcast(
ColorParser.of(
@@ -282,8 +282,8 @@ public class WarCommands {
}
// Join town into war
if (isArgTown && town != null && !war.isTownInWar(town) && (asAdmin || canMayorJoin)) {
side.addTown(town);
if (isArgTown && town != null && !war.isInWar(town) && (asAdmin || canMayorJoin)) {
side.add(town);
town.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).toList().forEach(player -> NameColorHandler.getInstance().getPlayerNameColor(player));
Bukkit.broadcast(
ColorParser.of(
@@ -316,9 +316,9 @@ public class WarCommands {
}
// Join player into war
if (isArgPlayer && targetPlayer != null && !war.isPlayerInWar(targetPlayer) && asAdmin) {
if (isArgPlayer && targetPlayer != null && !war.isInWar(targetPlayer) && asAdmin) {
targetPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
side.addPlayer(targetPlayer);
side.add(targetPlayer);
NameColorHandler.getInstance().calculatePlayerColors(targetPlayer);
final Title warTitle = Title.title(
ColorParser.of("<gradient:#D72A09:#B01F03><u><b>War")
@@ -367,10 +367,10 @@ public class WarCommands {
final Location targetLocation = targetPlayer.getLocation();
if (!location.getWorld().equals(targetLocation.getWorld())) continue;
if (location.distance(targetLocation) > 25D) continue;
if (war.isPlayerInWar(targetPlayer)) continue;
if (war.isInWar(targetPlayer)) continue;
targetPlayer.sendMessage(ColorParser.of(UtilsChat.getPrefix() + "You have joined the war.").build());
side.addPlayer(targetPlayer);
side.add(targetPlayer);
NameColorHandler.getInstance().calculatePlayerColors(targetPlayer);
final Title warTitle = Title.title(
ColorParser.of("<gradient:#D72A09:#B01F03><u><b>War")
@@ -404,7 +404,7 @@ public class WarCommands {
if (town == null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in a town.").build());
@Nullable Side side = war.getTownSide(town);
@Nullable Side side = war.getSide(town);
if (side == null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You are not in that war.").build());
@@ -415,7 +415,7 @@ public class WarCommands {
// 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());
war.surrenderNation(resNation);
war.surrender(resNation);
} else if (resTown == null) {
// Cannot surrender nation involvement
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender for your nation.").build());
@@ -426,7 +426,7 @@ public class WarCommands {
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());
war.cancelSieges(resTown);
war.surrenderTown(resTown);
war.surrender(resTown);
} else {
// No perms
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>You cannot surrender war for your town.").build());
@@ -447,26 +447,26 @@ public class WarCommands {
Town town = TownyAPI.getInstance().getTown(uuid);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
Side sideNation = war.getNationSide(nation);
Side sideTown = war.getTownSide(town);
Side sideNation = war.getSide(nation);
Side sideTown = war.getSide(town);
Side sidePlayer = war.getPlayerSide(uuid);
if (isNation && sideNation != null) {
sideNation.kickNation(nation);
sideNation.kick(nation);
p.sendMessage(ColorParser.of("Target yeeted.").build());
nation.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).forEach(player1 -> NameColorHandler.getInstance().calculatePlayerColors(player1));
return;
}
if (isTown && sideTown != null) {
sideTown.kickTown(town);
sideTown.kick(town);
p.sendMessage(ColorParser.of("Target yeeted.").build());
town.getResidents().stream().filter(Resident::isOnline).map(Resident::getPlayer).forEach(player1 -> NameColorHandler.getInstance().calculatePlayerColors(player1));
return;
}
if (isPlayer && sidePlayer != null) {
sidePlayer.kickPlayer(player.getUniqueId());
sidePlayer.kick(player.getUniqueId());
p.sendMessage(ColorParser.of("Target yeeted.").build());
if (player.getPlayer() != null)
NameColorHandler.getInstance().calculatePlayerColors(player.getPlayer());
@@ -509,9 +509,9 @@ public class WarCommands {
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 <grey>Nations: <green>%s<grey>/<red>%s".formatted(side.getNations().size(), side.getNations().size() + side.getNationsSurrendered().size()));
msg.append("\n <grey>Towns: <green>%s<grey>/<red>%s".formatted(side.getTowns().size(), side.getTowns().size() + side.getTownsSurrendered().size()));
msg.append("\n <grey>Players: <green>%s<grey>/<red>%s".formatted(side.getPlayersAll().size(), side.getPlayersAll().size() + side.getPlayersSurrendered().size()));
msg.append("\n");
}