refactor: rename WarManeger to WarController

This commit is contained in:
darksaid98 committed 2024-02-01 17:17:44 +01:00
1 parent a099a6b358
commit ba3307490e
19 files changed
+70 -70

No files matched your search

@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars;
import com.github.alathra.AlathranWars.commands.CommandManager; import com.github.alathra.AlathranWars.commands.CommandManager;
import com.github.alathra.AlathranWars.config.ConfigHandler; import com.github.alathra.AlathranWars.config.ConfigHandler;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.db.DatabaseHandler; import com.github.alathra.AlathranWars.db.DatabaseHandler;
import com.github.alathra.AlathranWars.db.DatabaseQueries; import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.github.alathra.AlathranWars.hooks.HookManager; import com.github.alathra.AlathranWars.hooks.HookManager;
@@ -44,7 +44,7 @@ public class AlathranWars extends JavaPlugin {
public void onLoad() { public void onLoad() {
instance = this; instance = this;
paperLib = new MorePaperLib(instance); paperLib = new MorePaperLib(instance);
WarManager.getInstance(); WarController.getInstance();
configHandler = new ConfigHandler(instance); configHandler = new ConfigHandler(instance);
databaseHandler = new DatabaseHandler(instance); databaseHandler = new DatabaseHandler(instance);
commandManager = new CommandManager(instance); commandManager = new CommandManager(instance);
@@ -68,7 +68,7 @@ public class AlathranWars extends JavaPlugin {
commandManager.onEnable(); commandManager.onEnable();
listenerHandler.onEnable(); listenerHandler.onEnable();
hookManager.onEnable(); hookManager.onEnable();
WarManager.getInstance().loadAll(); WarController.getInstance().loadAll();
} }
public void onDisable() { public void onDisable() {
@@ -3,7 +3,7 @@ package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars; import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.CommandArgsSiege; import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
import com.github.alathra.AlathranWars.enums.CommandArgsWar; import com.github.alathra.AlathranWars.enums.CommandArgsWar;
@@ -302,7 +302,7 @@ public class CommandUtil {
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(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) { if (checkIfSieged) {
for (@NotNull Siege siege : WarManager.getInstance().getSieges()) { for (@NotNull Siege siege : WarController.getInstance().getSieges()) {
if (siege.getTown().getUUID() == town.getUUID()) if (siege.getTown().getUUID() == town.getUUID())
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is already under siege!").parseLegacy().build()); throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The town is already under siege!").parseLegacy().build());
} }
@@ -342,13 +342,13 @@ public class CommandUtil {
final String argSiegeName = info.input(); final String argSiegeName = info.input();
@Nullable UUID siegeUUID = null; @Nullable UUID siegeUUID = null;
for (Siege siege : WarManager.getInstance().getSieges()) { for (Siege siege : WarController.getInstance().getSieges()) {
if (siege.getName().equals(argSiegeName)) { if (siege.getName().equals(argSiegeName)) {
siegeUUID = siege.getUUID(); siegeUUID = siege.getUUID();
} }
} }
final @Nullable Siege siege = WarManager.getInstance().getSiege(siegeUUID); final @Nullable Siege siege = WarController.getInstance().getSiege(siegeUUID);
if (siege == null) if (siege == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The siege <siege> does not exist!").parseMinimessagePlaceholder("siege", argSiegeName).build()); throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The siege <siege> does not exist!").parseMinimessagePlaceholder("siege", argSiegeName).build());
@@ -394,7 +394,7 @@ public class CommandUtil {
} }
private static List<String> siegeAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) { private static List<String> siegeAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) {
return WarManager.getInstance().getSieges().stream().map(Siege::getName).toList(); return WarController.getInstance().getSieges().stream().map(Siege::getName).toList();
} }
private static List<String> siegeOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) { private static List<String> siegeOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
@@ -402,11 +402,11 @@ public class CommandUtil {
if (isAdmin) { if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) { if (info.previousArgs().get(playerNodeName) instanceof Player player) {
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList(); siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
} }
} else { } else {
if (info.sender() instanceof Player player) { if (info.sender() instanceof Player player) {
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList(); siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> !siege.isPlayerInSiege(player)).map(Siege::getName).toList();
} }
} }
@@ -418,11 +418,11 @@ public class CommandUtil {
if (isAdmin) { if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) { if (info.previousArgs().get(playerNodeName) instanceof Player player) {
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList(); siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
} }
} else { } else {
if (info.sender() instanceof Player player) { if (info.sender() instanceof Player player) {
siegeNames = WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList(); siegeNames = WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(player)).map(Siege::getName).toList();
} }
} }
@@ -433,7 +433,7 @@ public class CommandUtil {
return new CustomArgument<>(new StringArgument(nodeName), info -> { return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argWarName = info.input(); final String argWarName = info.input();
final @Nullable War war = WarManager.getInstance().getWar(argWarName); final @Nullable War war = WarController.getInstance().getWar(argWarName);
if (war == null) if (war == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war <war> does not exist!").parseMinimessagePlaceholder("war", argWarName).build()); throw CustomArgument.CustomArgumentException.fromAdventureComponent(ColorParser.of(UtilsChat.getPrefix() + "<red>The war <war> does not exist!").parseMinimessagePlaceholder("war", argWarName).build());
@@ -479,7 +479,7 @@ public class CommandUtil {
} }
private static List<String> warsAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) { private static List<String> warsAll(SuggestionInfo<CommandSender> info, final boolean isAdmin) {
return WarManager.getInstance().getWarNames(); return WarController.getInstance().getWarNames();
} }
private static List<String> warsOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) { private static List<String> warsOutside(SuggestionInfo<CommandSender> info, final boolean isAdmin, final String playerNodeName) {
@@ -487,11 +487,11 @@ public class CommandUtil {
if (isAdmin) { if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) { if (info.previousArgs().get(playerNodeName) instanceof Player player) {
warNames = WarManager.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList(); warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
} }
} else { } else {
if (info.sender() instanceof Player player) { if (info.sender() instanceof Player player) {
warNames = WarManager.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList(); warNames = WarController.getInstance().getWars().stream().filter(war -> !war.isPlayerInWar(player)).map(War::getName).toList();
} }
} }
@@ -503,11 +503,11 @@ public class CommandUtil {
if (isAdmin) { if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) { if (info.previousArgs().get(playerNodeName) instanceof Player player) {
warNames = WarManager.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList(); warNames = WarController.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
} }
} else { } else {
if (info.sender() instanceof Player player) { if (info.sender() instanceof Player player) {
warNames = WarManager.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList(); warNames = WarController.getInstance().getWars().stream().filter(war -> war.isPlayerInWar(player)).map(War::getName).toList();
} }
} }
@@ -3,7 +3,7 @@ package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars; import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason; import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -211,7 +211,7 @@ public class SiegeCommands {
} }
private static void siegeList(@NotNull Player sender, CommandArguments args) throws WrapperCommandSyntaxException { private static void siegeList(@NotNull Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
Set<Siege> sieges = WarManager.getInstance().getSieges(); Set<Siege> sieges = WarController.getInstance().getSieges();
if (sieges.isEmpty()) { if (sieges.isEmpty()) {
sender.sendMessage(ColorParser.of("<red>There are no sieges at the moment.").build()); sender.sendMessage(ColorParser.of("<red>There are no sieges at the moment.").build());
@@ -449,7 +449,7 @@ public class WarCommands {
} }
private static void warList(@NotNull Player p, CommandArguments args) throws WrapperCommandSyntaxException { private static void warList(@NotNull Player p, CommandArguments args) throws WrapperCommandSyntaxException {
Set<War> wars = WarManager.getInstance().getWars(); Set<War> wars = WarController.getInstance().getWars();
if (wars.isEmpty()) { if (wars.isEmpty()) {
p.sendMessage(ColorParser.of("<red>There are no wars at the moment, the world is at peace.").build()); p.sendMessage(ColorParser.of("<red>There are no wars at the moment, the world is at peace.").build());
@@ -517,7 +517,7 @@ public class Side {
@Nullable @Nullable
public War getWar() { public War getWar() {
return WarManager.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't return WarController.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't
} }
public void processSurrenders() { public void processSurrenders() {
@@ -118,7 +118,7 @@ public class War extends Conflict {
this.label = label; this.label = label;
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName()); this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
if (WarManager.getInstance().getWar(this.name) != null) if (WarController.getInstance().getWar(this.name) != null)
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of(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());
this.side1 = new SideBuilder() this.side1 = new SideBuilder()
@@ -144,7 +144,7 @@ public class War extends Conflict {
return; return;
// TODO All logic below this point should be separated out // TODO All logic below this point should be separated out
WarManager.getInstance().addWar(this); WarController.getInstance().addWar(this);
start(); start();
@@ -804,7 +804,7 @@ public class War extends Conflict {
getAllTowns().forEach(Occupation::removeOccupied); getAllTowns().forEach(Occupation::removeOccupied);
DatabaseQueries.deleteWar(this); DatabaseQueries.deleteWar(this);
WarManager.getInstance().removeWar(this); WarController.getInstance().removeWar(this);
// Run check after war is removed to cleanup player tags // Run check after war is removed to cleanup player tags
getPlayers().forEach(p -> NameColorHandler.getInstance().calculatePlayerColors(p)); getPlayers().forEach(p -> NameColorHandler.getInstance().calculatePlayerColors(p));
@@ -18,19 +18,19 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Singleton @Singleton
public class WarManager { public class WarController {
private static WarManager instance; private static WarController instance;
private @NotNull Set<War> wars = new HashSet<>(); private @NotNull Set<War> wars = new HashSet<>();
private WarManager() { private WarController() {
if (instance != null) if (instance != null)
Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton"); Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton");
} }
@NotNull @NotNull
public static WarManager getInstance() { public static WarController getInstance() {
if (instance == null) if (instance == null)
instance = new WarManager(); instance = new WarController();
return instance; return instance;
} }
@@ -79,7 +79,7 @@ public abstract class DatabaseQueries {
) { ) {
DSLContext context = DB.getContext(con); DSLContext context = DB.getContext(con);
for (War war : WarManager.getInstance().getWars()) { for (War war : WarController.getInstance().getWars()) {
context context
// .insertInto(LIST) // .insertInto(LIST)
// .set(LIST.UUID, DatabaseQueries.convertUUIDToBytes(war.getUUID())) // .set(LIST.UUID, DatabaseQueries.convertUUIDToBytes(war.getUUID()))
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.hooks; package com.github.alathra.AlathranWars.hooks;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.utility.Logger; import com.github.alathra.AlathranWars.utility.Logger;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -28,14 +28,14 @@ public class NameColorHandler {
} }
public void calculatePlayerColors(Player p) { public void calculatePlayerColors(Player p) {
if (!WarManager.getInstance().isPlayerInAnyWars(p)) { if (!WarController.getInstance().isPlayerInAnyWars(p)) {
playerHasChanges.remove(p); playerHasChanges.remove(p);
playerColor.remove(p); playerColor.remove(p);
playerInitial.remove(p); playerInitial.remove(p);
return; return;
} }
Optional<War> war = WarManager.getInstance().getPlayerWars(p).stream().findFirst(); Optional<War> war = WarController.getInstance().getPlayerWars(p).stream().findFirst();
if (war.isEmpty()) if (war.isEmpty())
return; return;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners; package com.github.alathra.AlathranWars.listeners;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.utility.Utils; import com.github.alathra.AlathranWars.utility.Utils;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -148,7 +148,7 @@ public class CommandsListener implements Listener {
Prevent players from teleporting during a siege Prevent players from teleporting during a siege
*/ */
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) { for (Siege siege : WarController.getInstance().getPlayerSieges(p)) {
//payment check //payment check
if (args.length >= 2) { if (args.length >= 2) {
//parse what we have, remove the starting sslash //parse what we have, remove the starting sslash
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners.items; package com.github.alathra.AlathranWars.listeners.items;
import com.github.alathra.AlathranWars.AlathranWars; import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.items.WarItemRegistry; import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -71,7 +71,7 @@ public class PlayerInteractListener implements Listener {
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) { if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
boolean inSiegeOrRaid = false; boolean inSiegeOrRaid = false;
//siege check //siege check
for (@NotNull Siege s : WarManager.getInstance().getSieges()) { for (@NotNull Siege s : WarController.getInstance().getSieges()) {
for (@NotNull TownBlock townBlock : s.getTown().getTownBlocks()) { for (@NotNull TownBlock townBlock : s.getTown().getTownBlocks()) {
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) { if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
// if we find one, just end no need to continue // if we find one, just end no need to continue
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners.siege; package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleSide; import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -13,8 +13,8 @@ public class PlayerJoinListener implements Listener {
@EventHandler @EventHandler
private void onPlayerJoin(@NotNull PlayerJoinEvent e) { private void onPlayerJoin(@NotNull PlayerJoinEvent e) {
final @NotNull Player p = e.getPlayer(); final @NotNull Player p = e.getPlayer();
if (WarManager.getInstance().isPlayerInAnySiege(p)) { if (WarController.getInstance().isPlayerInAnySiege(p)) {
for (@NotNull Siege siege : WarManager.getInstance().getPlayerSieges(p)) { for (@NotNull Siege siege : WarController.getInstance().getPlayerSieges(p)) {
final @NotNull BattleSide side = siege.getPlayerSideInSiege(p); final @NotNull BattleSide side = siege.getPlayerSideInSiege(p);
siege.addOnlinePlayer(p, side); siege.addOnlinePlayer(p, side);
} }
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners.siege; package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleSide; import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -13,8 +13,8 @@ public class PlayerQuitListener implements Listener {
@EventHandler @EventHandler
private void onPlayerQuit(@NotNull PlayerQuitEvent e) { private void onPlayerQuit(@NotNull PlayerQuitEvent e) {
final @NotNull Player p = e.getPlayer(); final @NotNull Player p = e.getPlayer();
if (WarManager.getInstance().isPlayerInAnySiege(p)) { if (WarController.getInstance().isPlayerInAnySiege(p)) {
for (@NotNull Siege siege : WarManager.getInstance().getPlayerSieges(p)) { for (@NotNull Siege siege : WarController.getInstance().getPlayerSieges(p)) {
final @NotNull BattleSide side = siege.getPlayerSideInSiege(p); final @NotNull BattleSide side = siege.getPlayerSideInSiege(p);
siege.removeOnlinePlayer(p, side); siege.removeOnlinePlayer(p, side);
} }
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler; import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.palmergames.bukkit.towny.event.NationAddTownEvent; import com.palmergames.bukkit.towny.event.NationAddTownEvent;
import com.palmergames.bukkit.towny.event.NationPreRenameEvent; import com.palmergames.bukkit.towny.event.NationPreRenameEvent;
@@ -23,7 +23,7 @@ public class NationListener implements Listener {
private void onRename(NationPreRenameEvent e) { private void onRename(NationPreRenameEvent e) {
Nation nation = e.getNation(); Nation nation = e.getNation();
if (WarManager.getInstance().isNationInAnyWars(nation)) { if (WarController.getInstance().isNationInAnyWars(nation)) {
e.setCancelMessage("You can't rename a nation while it's in a war."); e.setCancelMessage("You can't rename a nation while it's in a war.");
e.setCancelled(true); e.setCancelled(true);
} }
@@ -35,7 +35,7 @@ public class NationListener implements Listener {
Town town = e.getTown(); Town town = e.getTown();
// Add town to all nation wars // Add town to all nation wars
for (War war : WarManager.getInstance().getNationWars(nation)) { for (War war : WarController.getInstance().getNationWars(nation)) {
Side side = war.getNationSide(nation); Side side = war.getNationSide(nation);
if (side == null) continue; if (side == null) continue;
@@ -43,14 +43,14 @@ public class NationListener implements Listener {
} }
// TODO Add nation to towns' wars // TODO Add nation to towns' wars
for (War war : WarManager.getInstance().getTownWars(town)) { for (War war : WarController.getInstance().getTownWars(town)) {
Side side = war.getTownSide(town); Side side = war.getTownSide(town);
if (side == null) continue; if (side == null) continue;
side.addNation(nation); side.addNation(nation);
} }
for (War war : WarManager.getInstance().getNationWars(nation)) { for (War war : WarController.getInstance().getNationWars(nation)) {
Side side = war.getNationSide(nation); Side side = war.getNationSide(nation);
if (side == null) continue; if (side == null) continue;
@@ -68,7 +68,7 @@ public class NationListener implements Listener {
Nation nation = e.getRemainingNation(); Nation nation = e.getRemainingNation();
Nation nation1 = e.getNation(); Nation nation1 = e.getNation();
if (WarManager.getInstance().isNationInAnyWars(nation) || WarManager.getInstance().isNationInAnyWars(nation1)) { if (WarController.getInstance().isNationInAnyWars(nation) || WarController.getInstance().isNationInAnyWars(nation1)) {
e.setCancelMessage("You can't merge nations while they are in a war."); e.setCancelMessage("You can't merge nations while they are in a war.");
e.setCancelled(true); e.setCancelled(true);
} }
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler; import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -15,8 +15,8 @@ public class PlayerJoinListener implements Listener {
@EventHandler @EventHandler
private void onPlayerJoin(@NotNull PlayerJoinEvent e) { private void onPlayerJoin(@NotNull PlayerJoinEvent e) {
final @NotNull Player p = e.getPlayer(); final @NotNull Player p = e.getPlayer();
if (WarManager.getInstance().isPlayerInAnyWars(p)) { if (WarController.getInstance().isPlayerInAnyWars(p)) {
for (@NotNull War war : WarManager.getInstance().getWars()) { for (@NotNull War war : WarController.getInstance().getWars()) {
if (war.isPlayerInWar(p)) { if (war.isPlayerInWar(p)) {
@Nullable Side side = war.getPlayerSide(p); @Nullable Side side = war.getPlayerSide(p);
if (side != null) { if (side != null) {
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler; import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -15,8 +15,8 @@ public class PlayerQuitListener implements Listener {
@EventHandler @EventHandler
private void onPlayerQuit(@NotNull PlayerQuitEvent e) { private void onPlayerQuit(@NotNull PlayerQuitEvent e) {
final @NotNull Player p = e.getPlayer(); final @NotNull Player p = e.getPlayer();
if (WarManager.getInstance().isPlayerInAnyWars(p)) { if (WarController.getInstance().isPlayerInAnyWars(p)) {
for (@NotNull War war : WarManager.getInstance().getWars()) { for (@NotNull War war : WarController.getInstance().getWars()) {
if (war.isPlayerInWar(p)) { if (war.isPlayerInWar(p)) {
@Nullable Side side = war.getPlayerSide(p); @Nullable Side side = war.getPlayerSide(p);
if (side != null) { if (side != null) {
@@ -2,7 +2,7 @@ package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler; import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.github.milkdrinkers.colorparser.ColorParser; import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.event.TownAddResidentEvent; import com.palmergames.bukkit.towny.event.TownAddResidentEvent;
@@ -26,7 +26,7 @@ public class TownListener implements Listener {
private void onRename(TownPreRenameEvent e) { private void onRename(TownPreRenameEvent e) {
Town town = e.getTown(); Town town = e.getTown();
if (WarManager.getInstance().isTownInAnyWars(town)) { if (WarController.getInstance().isTownInAnyWars(town)) {
e.setCancelMessage("You can't rename a town while it's in a war."); e.setCancelMessage("You can't rename a town while it's in a war.");
e.setCancelled(true); e.setCancelled(true);
} }
@@ -40,7 +40,7 @@ public class TownListener implements Listener {
Player p = e.getResident().getPlayer(); Player p = e.getResident().getPlayer();
if (p == null) return; if (p == null) return;
for (War war : WarManager.getInstance().getTownWars(town)) { for (War war : WarController.getInstance().getTownWars(town)) {
Side side = war.getTownSide(town); Side side = war.getTownSide(town);
if (side == null) continue; if (side == null) continue;
side.addPlayer(p); side.addPlayer(p);
@@ -68,7 +68,7 @@ public class TownListener implements Listener {
Player p = e.getResident().getPlayer(); Player p = e.getResident().getPlayer();
if (p == null) return; if (p == null) return;
for (War war : WarManager.getInstance().getTownWars(town)) { for (War war : WarController.getInstance().getTownWars(town)) {
Side side = war.getTownSide(town); Side side = war.getTownSide(town);
if (side == null) continue; if (side == null) continue;
side.removePlayer(p); side.removePlayer(p);
@@ -83,7 +83,7 @@ public class TownListener implements Listener {
Player p = e.getKickedResident().getPlayer(); Player p = e.getKickedResident().getPlayer();
if (p == null) return; if (p == null) return;
for (War war : WarManager.getInstance().getTownWars(town)) { for (War war : WarController.getInstance().getTownWars(town)) {
Side side = war.getTownSide(town); Side side = war.getTownSide(town);
if (side == null) continue; if (side == null) continue;
side.removePlayer(p); side.removePlayer(p);
@@ -118,7 +118,7 @@ public class TownListener implements Listener {
Town town = e.getRemainingTown(); Town town = e.getRemainingTown();
Town town2 = e.getSuccumbingTown(); Town town2 = e.getSuccumbingTown();
if (WarManager.getInstance().isTownInAnyWars(town) || WarManager.getInstance().isTownInAnyWars(town2)) { if (WarController.getInstance().isTownInAnyWars(town) || WarController.getInstance().isTownInAnyWars(town2)) {
e.setCancelMessage("You can't merge towns while they are in a war."); e.setCancelMessage("You can't merge towns while they are in a war.");
e.setCancelled(true); e.setCancelled(true);
} }
@@ -133,7 +133,7 @@ public class TownListener implements Listener {
private void onRuin(TownRuinedEvent e) { private void onRuin(TownRuinedEvent e) {
Town town = e.getTown(); Town town = e.getTown();
for (War war : WarManager.getInstance().getTownWars(town)) { for (War war : WarController.getInstance().getTownWars(town)) {
Side side = war.getTownSide(town); Side side = war.getTownSide(town);
if (side == null) continue; if (side == null) continue;
war.unsurrenderTown(town); war.unsurrenderTown(town);
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.utility; package com.github.alathra.AlathranWars.utility;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -13,7 +13,7 @@ public abstract class UUIDUtil {
public static @NotNull UUID generateWarUUID() { public static @NotNull UUID generateWarUUID() {
@NotNull UUID uuid = UUID.randomUUID(); @NotNull UUID uuid = UUID.randomUUID();
while (WarManager.getInstance().getWar(uuid) != null) { while (WarController.getInstance().getWar(uuid) != null) {
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
} }
@@ -23,7 +23,7 @@ public abstract class UUIDUtil {
public static @NotNull UUID generateSideUUID(@Nullable UUID previousSideUUID) { public static @NotNull UUID generateSideUUID(@Nullable UUID previousSideUUID) {
@NotNull UUID uuid = UUID.randomUUID(); @NotNull UUID uuid = UUID.randomUUID();
while (WarManager.getInstance().getSide(uuid) != null || uuid == previousSideUUID) { while (WarController.getInstance().getSide(uuid) != null || uuid == previousSideUUID) {
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
} }
@@ -33,7 +33,7 @@ public abstract class UUIDUtil {
public static @NotNull UUID generateSiegeUUID() { public static @NotNull UUID generateSiegeUUID() {
@NotNull UUID uuid = UUID.randomUUID(); @NotNull UUID uuid = UUID.randomUUID();
while (WarManager.getInstance().getSiege(uuid) != null) { while (WarController.getInstance().getSiege(uuid) != null) {
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
} }
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.utility; package com.github.alathra.AlathranWars.utility;
import com.github.alathra.AlathranWars.conflict.WarManager; import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Location; import org.bukkit.Location;
@@ -199,8 +199,8 @@ public abstract class Utils {
// TODO Implement usage in siege commands to make siege optional argument // TODO Implement usage in siege commands to make siege optional argument
public static @Nullable Siege getClosestSiege(Player p, boolean checkIfInSiege) { public static @Nullable Siege getClosestSiege(Player p, boolean checkIfInSiege) {
Set<Siege> sieges = checkIfInSiege Set<Siege> sieges = checkIfInSiege
? WarManager.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(p)).collect(Collectors.toSet()) ? WarController.getInstance().getSieges().stream().filter(siege -> siege.isPlayerInSiege(p)).collect(Collectors.toSet())
: WarManager.getInstance().getSieges(); : WarController.getInstance().getSieges();
@Nullable Siege siegeResult = null; @Nullable Siege siegeResult = null;
final Location playerLoc = p.getLocation(); final Location playerLoc = p.getLocation();