refactor: cleanup and comment more

This commit is contained in:
darksaid98 committed 2024-02-01 18:15:02 +01:00
1 parent ba3307490e
commit 230cee4196
34 files changed
+338 -232

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.config.ConfigHandler;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.db.DatabaseHandler;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.github.alathra.AlathranWars.hooks.HookManager;
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
import com.github.alathra.AlathranWars.enums.CommandArgsWar;
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -1,6 +1,10 @@
package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.conflict.*;
import com.github.alathra.AlathranWars.conflict.war.War;
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.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.conflict.battle.raid;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
import com.github.alathra.AlathranWars.enums.battle.*;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.conflict.battle.siege;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
@@ -1,7 +1,11 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.*;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.side.SideBuilder;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.github.alathra.AlathranWars.enums.ConflictType;
import com.github.alathra.AlathranWars.enums.WarDeleteReason;
@@ -47,7 +51,7 @@ public class War extends Conflict {
private final ConflictType conflictType = ConflictType.WAR;
private boolean event;
private @NotNull Side side1;
private Side side1;
private Side side2;
private final Side attacker; // Reference variable to side1 or side2
private final Side defender; // Reference variable to side1 or side2
@@ -72,7 +76,7 @@ public class War extends Conflict {
UUID uuid,
String name,
String label,
@NotNull Side side1,
Side side1,
Side side2,
Set<Siege> sieges,
Set<Raid> raids,
@@ -127,14 +131,14 @@ public class War extends Conflict {
.setLeader(aggressor)
.setSide(BattleSide.ATTACKER)
.setTeam(BattleTeam.SIDE_1)
.buildNew();
.build();
this.side2 = new SideBuilder()
.setWarUUID(this.uuid)
.setUuid(UUID.randomUUID())
.setLeader(victim)
.setSide(BattleSide.DEFENDER)
.setTeam(BattleTeam.SIDE_2)
.buildNew();
.build();
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
@@ -196,7 +200,7 @@ public class War extends Conflict {
* @param war the war
* @return the boolean
*/
public boolean equals(@NotNull War war) {
public boolean equals(War war) {
return this.uuid.equals(war.getUUID());
}
@@ -817,9 +821,9 @@ public class War extends Conflict {
*
* @param loserSide the loser side
*/
public void defeat(@NotNull Side loserSide) {
@NotNull Side loser = loserSide.equals(getSide1()) ? getSide1() : getSide2();
@NotNull Side winner = loserSide.equals(getSide1()) ? getSide2() : getSide1();
public void defeat(Side loserSide) {
Side loser = loserSide.equals(getSide1()) ? getSide1() : getSide2();
Side winner = loserSide.equals(getSide1()) ? getSide2() : getSide1();
Bukkit.broadcast(ColorParser.of(UtilsChat.getPrefix() + "The war of <war> has ended. <red><winner> <reset>has triumphed against <red><loser><reset>.")
.parseMinimessagePlaceholder("war", getLabel())
@@ -1,5 +1,7 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.ConflictType;
@@ -7,10 +9,8 @@ import com.palmergames.bukkit.towny.object.Government;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -25,11 +25,6 @@ public class WarBuilder {
private Set<Siege> sieges = new HashSet<>();
private Set<Raid> raids = new HashSet<>();
private Town aggressorTown;
private Optional<Nation> aggressorNation = Optional.empty();
private Town victimTown;
private Optional<Nation> victimNation = Optional.empty();
private Government aggressor;
private Government victim;
@@ -60,27 +55,6 @@ public class WarBuilder {
);
}
/*public War create() throws WrapperCommandSyntaxException {
this.setUuid(UUID.randomUUID());
if (aggressorNation.isEmpty() && aggressorTown != null) {
// TODO Throw
}
if (victimNation.isEmpty() && victimTown != null) {
// TODO Throw
}
return new War(
uuid,
label,
aggressorTown,
victimTown,
aggressorNation.isPresent(),
victimNation.isPresent(),
event
);
}*/
public War create() throws WrapperCommandSyntaxException, SideCreationException {
this.setUuid(UUID.randomUUID());
@@ -139,24 +113,18 @@ public class WarBuilder {
}
public WarBuilder setAggressorTown(Town target) {
this.aggressorTown = target;
return this;
}
public WarBuilder setAggressorNation(Nation target) {
this.aggressorTown = target.getCapital();
this.aggressorNation = Optional.of(target);
return this;
}
public WarBuilder setVictimTown(Town target) {
this.victimTown = target;
return this;
}
public WarBuilder setVictimNation(Nation target) {
this.victimTown = target.getCapital();
this.victimNation = Optional.of(target);
return this;
}
@@ -1,5 +1,6 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
@@ -7,6 +8,7 @@ import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,6 +19,9 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* The singleton War controller.
*/
@Singleton
public class WarController {
private static WarController instance;
@@ -27,6 +32,11 @@ public class WarController {
Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton");
}
/**
* Gets or creates an instance of the war controller.
*
* @return the instance
*/
@NotNull
public static WarController getInstance() {
if (instance == null)
@@ -35,128 +45,264 @@ public class WarController {
return instance;
}
/**
* Load all wars into memory from database.
*/
@ApiStatus.Internal
public void loadAll() {
wars = DatabaseQueries.loadAll();
}
/**
* Gets all wars.
*
* @return the wars
*/
@NotNull
public Set<War> getWars() {
return wars;
}
/**
* Gets war by its name or returns null.
*
* @param warName the war name
* @return the war
*/
@Nullable
public War getWar(String warName) {
for (@NotNull War war : getWars())
if (war.equals(warName)) return war;
return null;
return getWars().stream()
.filter(war -> war.equals(warName))
.findAny()
.orElse(null);
}
/**
* Gets war by its UUID or returns null.
*
* @param uuid the uuid
* @return the war
*/
@Nullable
public War getWar(UUID uuid) {
for (@NotNull War war : getWars())
if (war.equals(uuid)) return war;
return null;
return getWars().stream()
.filter(war -> war.equals(uuid))
.findAny()
.orElse(null);
}
/**
* Gets side by the side UUID.
*
* @param uuid the uuid
* @return the side
*/
@Nullable
public Side getSide(UUID uuid) {
for (@NotNull War war : getWars())
if (war.getSide(uuid) != null) return war.getSide(uuid);
return null;
return getWars().stream()
.filter(war -> war.getSide(uuid) != null)
.map(war -> war.getSide(uuid))
.findAny()
.orElse(null);
}
/**
* Gets siege by the siege UUID.
*
* @param uuid the uuid
* @return the siege
*/
@Nullable
public Siege getSiege(UUID uuid) {
for (@NotNull War war : getWars())
if (war.getSiege(uuid) != null) return war.getSiege(uuid);
return null;
return getWars().stream()
.filter(war -> war.getSiege(uuid) != null)
.map(war -> war.getSiege(uuid))
.findAny()
.orElse(null);
}
/**
* Add a war to the war controller.
*
* @param war the war
*/
@ApiStatus.Internal
public void addWar(War war) {
getWars().add(war);
}
/**
* Remove a war from the war controller.
*
* @param war the war
*/
@ApiStatus.Internal
public void removeWar(War war) {
getWars().remove(war);
}
/**
* Is player in any wars. Includes if surrendered.
*
* @param uuid the uuid
* @return the boolean
*/
public boolean isPlayerInAnyWars(UUID uuid) {
return getWars().stream()
.anyMatch(war -> war.isPlayerInWar(uuid));
}
public boolean isPlayerInAnyWars(@NotNull Player p) {
/**
* Is player in any wars. Includes if surrendered.
*
* @param p the p
* @return the boolean
*/
public boolean isPlayerInAnyWars(Player p) {
return isPlayerInAnyWars(p.getUniqueId());
}
public @NotNull Set<War> getPlayerWars(@NotNull Player p) {
/**
* Gets list of player wars. Includes if surrendered.
*
* @param p the p
* @return the player wars
*/
public @NotNull Set<War> getPlayerWars(Player p) {
return getPlayerWars(p.getUniqueId());
}
/**
* Gets list of player wars. Includes if surrendered.
*
* @param uuid the uuid
* @return the player wars
*/
public @NotNull Set<War> getPlayerWars(UUID uuid) {
return getWars().stream()
.filter(war -> war.isPlayerInWar(uuid))
.collect(Collectors.toSet());
}
/**
* Is town in any wars. Includes surrendered towns.
*
* @param town the town
* @return the boolean
*/
public boolean isTownInAnyWars(Town town) {
return getWars().stream()
.anyMatch(war -> war.isTownInWar(town));
}
/**
* Is town in any sieges. Includes surrendered towns.
*
* @param town the town
* @return the boolean
*/
public boolean isTownInAnySieges(Town town) {
return getWars().stream()
.anyMatch(war -> war.isTownInWar(town) && war.isTownUnderSiege(town));
}
/**
* Is town in any raids. Includes surrendered towns.
*
* @param town the town
* @return the boolean
*/
public boolean isTownInAnyRaids(Town town) {
return getWars().stream()
.anyMatch(war -> war.isTownInWar(town) && war.isTownUnderRaid(town));
}
/**
* Is nation in any sieges. Includes surrendered nations.
*
* @param nation the nation
* @return the boolean
*/
public boolean isNationInAnySieges(Nation nation) {
return nation.getTowns().stream()
.anyMatch(this::isTownInAnySieges);
}
/**
* Is nation in any raids. Includes surrendered nations.
*
* @param nation the nation
* @return the boolean
*/
public boolean isNationInAnyRaids(Nation nation) {
return nation.getTowns().stream()
.anyMatch(this::isTownInAnyRaids);
}
/**
* Gets town sieges. Includes surrendered towns.
*
* @param town the town
* @return the town sieges
*/
public @NotNull Set<Siege> getTownSieges(Town town) {
return getSieges().stream()
.filter(siege -> siege.getAttackerSide().isTownOnSide(town) || siege.getDefenderSide().isTownOnSide(town))
.collect(Collectors.toSet());
}
/**
* Gets town raids. Includes surrendered towns.
*
* @param town the town
* @return the town raids
*/
public @NotNull Set<Raid> getTownRaids(Town town) {
return getRaids().stream()
.filter(raid -> raid.getAttackerSide().isTownOnSide(town) || raid.getDefenderSide().isTownOnSide(town))
.collect(Collectors.toSet());
}
/**
* Gets town wars. Includes surrendered towns.
*
* @param town the town
* @return the town wars
*/
public @NotNull Set<War> getTownWars(Town town) {
return getWars().stream()
.filter(war -> war.isTownInWar(town))
.collect(Collectors.toSet());
}
/**
* Is nation in any wars. Includes surrendered nations.
*
* @param nation the nation
* @return the boolean
*/
public boolean isNationInAnyWars(Nation nation) {
return getWars().stream()
.anyMatch(war -> war.isNationInWar(nation));
}
/**
* Gets nation wars. Includes surrendered nations.
*
* @param nation the nation
* @return the nation wars
*/
public @NotNull Set<War> getNationWars(Nation nation) {
return getWars().stream()
.filter(war -> war.isNationInWar(nation))
.collect(Collectors.toSet());
}
/**
* Gets a list of war names.
*
* @return the war names
*/
@NotNull
public List<String> getWarNames() {
return getWars().stream()
@@ -165,6 +311,11 @@ public class WarController {
.collect(Collectors.toList());
}
/**
* Gets a list of war labels.
*
* @return the war labels
*/
@NotNull
public List<String> getWarLabels() {
return getWars().stream()
@@ -173,6 +324,11 @@ public class WarController {
.collect(Collectors.toList());
}
/**
* Gets a list of all active sieges.
*
* @return the sieges
*/
@NotNull
public Set<Siege> getSieges() {
return getWars().stream()
@@ -181,6 +337,11 @@ public class WarController {
.collect(Collectors.toSet());
}
/**
* Gets a list of all active raids.
*
* @return the raids
*/
@NotNull
public Set<Raid> getRaids() {
return getWars().stream()
@@ -189,25 +350,54 @@ public class WarController {
.collect(Collectors.toSet());
}
public boolean isPlayerInAnySiege(@NotNull Player p) {
/**
* Is player in any siege.
*
* @param p the p
* @return the boolean
*/
public boolean isPlayerInAnySiege(Player p) {
return isPlayerInAnySiege(p.getUniqueId());
}
/**
* Is player in any siege. Returns true for offline players.
*
* @param uuid the uuid
* @return the boolean
*/
public boolean isPlayerInAnySiege(UUID uuid) {
return getSieges().stream()
.anyMatch(siege -> siege.isPlayerInSiege(uuid));
}
public @NotNull Set<Siege> getPlayerSieges(@NotNull Player p) {
/**
* Gets player sieges.
*
* @param p the p
* @return the player sieges
*/
public @NotNull Set<Siege> getPlayerSieges(Player p) {
return getPlayerSieges(p.getUniqueId());
}
/**
* Gets player sieges. Returns true for offline players.
*
* @param uuid the uuid
* @return the player sieges
*/
public @NotNull Set<Siege> getPlayerSieges(UUID uuid) {
return getSieges().stream()
.filter(siege -> siege.isPlayerInSiege(uuid))
.collect(Collectors.toSet());
}
/**
* Gets nations at war. Does not include surrendered nations.
*
* @return the nations at war
*/
public @NotNull Set<Nation> getNationsAtWar() {
return getWars().stream()
.map(War::getNations)
@@ -215,6 +405,11 @@ public class WarController {
.collect(Collectors.toSet());
}
/**
* Gets towns at war. Does not include surrendered towns.
*
* @return the towns at war
*/
public @NotNull Set<Town> getTownsAtWar() {
return getWars().stream()
.map(War::getTowns)
@@ -1,4 +1,6 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
public class WarCreationException extends SideCreationException {
public WarCreationException(String errorMessage) {
@@ -1,6 +1,8 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war.side;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import com.github.alathra.AlathranWars.enums.battle.BattleTeam;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
@@ -89,31 +91,6 @@ public class Side {
calculateOnlinePlayers();
}
/*public Side(UUID warUUID, UUID uuid, Town town, boolean isNation, BattleSide side, BattleTeam team) {
this.warUUID = warUUID;
this.uuid = uuid;
this.side = side;
this.team = team;
this.town = town;
this.name = this.town.getName();
this.towns = new HashSet<>();
this.nations = new HashSet<>();
this.playersIncludingOffline = new HashSet<>();
this.players = new HashSet<>();
this.surrenderedTowns = new HashSet<>();
this.surrenderedNations = new HashSet<>();
this.surrenderedPlayersIncludingOffline = new HashSet<>();
if (isNation)
addNation(Objects.requireNonNull(this.town.getNationOrNull()));
else
addTown(this.town);
calculateOnlinePlayers();
}*/
public Side(UUID warUUID, UUID uuid, Government government, BattleSide side, BattleTeam team) throws SideCreationException {
this.warUUID = warUUID;
this.uuid = uuid;
@@ -144,50 +121,6 @@ public class Side {
calculateOnlinePlayers();
}
/*public Side(UUID warUUID, UUID uuid, Town town, BattleSide side, BattleTeam team) {
this.warUUID = warUUID;
this.uuid = uuid;
this.side = side;
this.team = team;
this.town = town;
this.name = this.town.getName();
this.towns = new HashSet<>();
this.nations = new HashSet<>();
this.playersIncludingOffline = new HashSet<>();
this.players = new HashSet<>();
this.surrenderedTowns = new HashSet<>();
this.surrenderedNations = new HashSet<>();
this.surrenderedPlayersIncludingOffline = new HashSet<>();
addTown(this.town);
calculateOnlinePlayers();
}
public Side(UUID warUUID, UUID uuid, @NotNull Nation nation, BattleSide side, BattleTeam team) {
this.warUUID = warUUID;
this.uuid = uuid;
this.side = side;
this.team = team;
this.town = nation.getCapital();
this.name = this.town.getName();
this.towns = new HashSet<>();
this.nations = new HashSet<>();
this.playersIncludingOffline = new HashSet<>();
this.players = new HashSet<>();
this.surrenderedTowns = new HashSet<>();
this.surrenderedNations = new HashSet<>();
this.surrenderedPlayersIncludingOffline = new HashSet<>();
addNation(nation);
calculateOnlinePlayers();
}*/
public BattleSide getSide() {
return side;
}
@@ -246,7 +179,7 @@ public class Side {
return surrenderedNations.contains(nation);
}
public void addTown(@NotNull Town town) {
public void addTown(Town town) {
if (isTownOnSide(town)) return;
towns.add(town);
@@ -254,7 +187,7 @@ public class Side {
town.getResidents().forEach((Resident resident) -> addPlayer(resident.getUUID()));
}
public void addNation(@NotNull Nation nation) {
public void addNation(Nation nation) {
if (isNationOnSide(nation)) return;
nations.add(nation);
@@ -262,7 +195,7 @@ public class Side {
nation.getTowns().forEach(this::addTown);
}
public void removeTown(@NotNull Town town) {
public void removeTown(Town town) {
if (!isTownOnSide(town)) return;
towns.remove(town);
@@ -270,7 +203,7 @@ public class Side {
town.getResidents().forEach((Resident resident) -> removePlayer(resident.getUUID()));
}
public void removeNation(@NotNull Nation nation) {
public void removeNation(Nation nation) {
if (!isNationOnSide(nation)) return;
nations.remove(nation);
@@ -278,7 +211,7 @@ public class Side {
nation.getTowns().forEach(this::removeTown);
}
public void surrenderTown(@NotNull Town town) {
public void surrenderTown(Town town) {
if (isTownSurrendered(town)) return;
removeTown(town);
@@ -288,7 +221,7 @@ public class Side {
town.getResidents().forEach((Resident resident) -> surrenderPlayer(resident.getUUID()));
}
public void surrenderNation(@NotNull Nation nation) {
public void surrenderNation(Nation nation) {
if (isNationSurrendered(nation)) return;
removeNation(nation);
@@ -298,7 +231,7 @@ public class Side {
nation.getTowns().forEach(this::surrenderTown);
}
public void unsurrenderTown(@NotNull Town town) {
public void unsurrenderTown(Town town) {
if (!isTownSurrendered(town)) return;
addTown(town);
@@ -308,7 +241,7 @@ public class Side {
town.getResidents().forEach((Resident resident) -> unsurrenderPlayer(resident.getUUID()));
}
public void unsurrenderNation(@NotNull Nation nation) {
public void unsurrenderNation(Nation nation) {
if (!isNationSurrendered(nation)) return;
addNation(nation);
@@ -318,7 +251,7 @@ public class Side {
nation.getTowns().forEach(this::unsurrenderTown);
}
public boolean isPlayerOnSide(@NotNull Player p) {
public boolean isPlayerOnSide(Player p) {
return isPlayerOnSide(p.getUniqueId());
}
@@ -326,7 +259,7 @@ public class Side {
return playersIncludingOffline.contains(uuid) || surrenderedPlayersIncludingOffline.contains(uuid);
}
public boolean isPlayerSurrendered(@NotNull Player p) {
public boolean isPlayerSurrendered(Player p) {
return isPlayerSurrendered(p.getUniqueId());
}
@@ -334,21 +267,21 @@ public class Side {
return surrenderedPlayersIncludingOffline.contains(uuid);
}
public void addPlayer(@NotNull Player p) {
public void addPlayer(Player p) {
addPlayer(p.getUniqueId());
}
public void addPlayer(@NotNull OfflinePlayer offlinePlayer) {
public void addPlayer(OfflinePlayer offlinePlayer) {
if (offlinePlayer.hasPlayedBefore())
addPlayer(offlinePlayer.getUniqueId());
}
public void addPlayer(@NotNull UUID uuid) {
public void addPlayer(UUID uuid) {
if (isPlayerOnSide(uuid)) return;
playersIncludingOffline.add(uuid);
if (getWar() != null) { // We need to check this as on side creation War doesn't exist
for (@NotNull Siege siege : getWar().getSieges()) {
for (Siege siege : getWar().getSieges()) {
if (siege.getAttackerSide().equals(this)) {
siege.addPlayer(uuid, BattleSide.ATTACKER);
} else {
@@ -367,21 +300,21 @@ public class Side {
players.add(p);
}
public void removePlayer(@NotNull Player p) {
public void removePlayer(Player p) {
removePlayer(p.getUniqueId());
}
public void removePlayer(@NotNull OfflinePlayer offlinePlayer) {
public void removePlayer(OfflinePlayer offlinePlayer) {
if (offlinePlayer.hasPlayedBefore())
removePlayer(offlinePlayer.getUniqueId());
}
public void removePlayer(@NotNull UUID uuid) {
public void removePlayer(UUID uuid) {
if (!isPlayerOnSide(uuid)) return;
playersIncludingOffline.remove(uuid);
if (getWar() != null) { // We need to check this as on side creation War doesn't exist
for (@NotNull Siege siege : getWar().getSieges()) {
for (Siege siege : getWar().getSieges()) {
if (siege.getAttackerSide().equals(this)) {
siege.removePlayer(uuid);
} else {
@@ -400,11 +333,11 @@ public class Side {
players.remove(p);
}
public void surrenderPlayer(@NotNull Player p) {
public void surrenderPlayer(Player p) {
surrenderPlayer(p.getUniqueId());
}
public void surrenderPlayer(@NotNull UUID uuid) {
public void surrenderPlayer(UUID uuid) {
if (isPlayerSurrendered(uuid)) return;
removePlayer(uuid);
@@ -412,11 +345,11 @@ public class Side {
applyNameTags();
}
public void unsurrenderPlayer(@NotNull Player p) {
public void unsurrenderPlayer(Player p) {
unsurrenderPlayer(p.getUniqueId());
}
public void unsurrenderPlayer(@NotNull UUID uuid) {
public void unsurrenderPlayer(UUID uuid) {
if (!isPlayerSurrendered(uuid)) return;
addPlayer(uuid);
@@ -425,7 +358,7 @@ public class Side {
}
public void calculateOnlinePlayers() {
final @NotNull Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
final Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline())
.map(Bukkit::getPlayer)
.collect(Collectors.toSet());
@@ -499,11 +432,11 @@ public class Side {
return this.uuid.equals(uuid);
}
public boolean equals(@NotNull War war) {
public boolean equals(War war) {
return this.warUUID.equals(war.getUUID());
}
public boolean equals(@NotNull Side side) {
public boolean equals(Side side) {
return getUUID().equals(side.getUUID());
}
@@ -1,26 +1,42 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war.side;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import com.github.alathra.AlathranWars.enums.battle.BattleTeam;
import com.palmergames.bukkit.towny.object.Government;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.entity.Player;
import java.time.Instant;
import java.util.Set;
import java.util.UUID;
public class SideBuilder {
private UUID warUUID;
private UUID uuid;
private BattleSide side;
private BattleTeam team;
private String name;
private Government government;
private Set<Town> towns;
private Set<Nation> nations;
private Set<UUID> playersIncludingOffline;
private Set<Town> surrenderedTowns;
private Set<Nation> surrenderedNations;
private Set<UUID> surrenderedPlayersIncludingOffline;
private Instant siegeGrace;
private Instant raidGrace;
public SideBuilder() {}
public Side buildOld() throws SideCreationException {
public Side rebuild() throws SideCreationException {
// if (warUUID == null || uuid == null || town == null || side == null || team == null || name == null ||
// towns == null || nations == null || playersIncludingOffline == null ||
// surrenderedTowns == null || surrenderedNations == null || surrenderedPlayersIncludingOffline == null ||
// siegeGrace == null || raidGrace == null
// ) throw new IllegalStateException("Missing state to create Side 1");
// TODO Cleanup this shit
if (warUUID == null || uuid == null
) throw new IllegalStateException("Missing state to create Side 1.2");
@@ -56,7 +72,7 @@ public class SideBuilder {
);
}
public Side buildNew() throws SideCreationException {
public Side build() throws SideCreationException {
if (warUUID == null || uuid == null || government == null || side == null || team == null)
throw new IllegalStateException("Missing state to create new Side");
@@ -138,25 +154,4 @@ public class SideBuilder {
this.raidGrace = raidGrace;
return this;
}
private UUID warUUID;
private UUID uuid;
private BattleSide side;
private BattleTeam team;
private String name;
private Government government;
private Town town;
private Set<Town> towns;
private Set<Nation> nations;
private Set<UUID> playersIncludingOffline;
private Set<Town> surrenderedTowns;
private Set<Nation> surrenderedNations;
private Set<UUID> surrenderedPlayersIncludingOffline;
private Instant siegeGrace;
private Instant raidGrace;
}
@@ -1,4 +1,4 @@
package com.github.alathra.AlathranWars.conflict;
package com.github.alathra.AlathranWars.conflict.war.side;
public class SideCreationException extends Exception {
public SideCreationException(String errorMessage) {
@@ -1,7 +1,12 @@
package com.github.alathra.AlathranWars.db;
import com.github.alathra.AlathranWars.conflict.*;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.War;
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.SideBuilder;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import com.github.alathra.AlathranWars.enums.battle.BattleTeam;
import com.github.alathra.AlathranWars.utility.DB;
@@ -456,7 +461,7 @@ public abstract class DatabaseQueries {
.setSurrenderedPlayersIncludingOffline(playersSurrendered)
.setSiegeGrace(siegeGrace)
.setRaidGrace(raidGrace)
.buildOld();
.rebuild();
} catch (SideCreationException e) {
Logger.get().error("SQL Query threw an error!", e);
}
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.enums.WarDeleteReason;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.enums.WarDeleteReason;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.enums.battle.BattleVictor;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import com.github.alathra.AlathranWars.enums.battle.BattleVictor;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import org.bukkit.event.Cancellable;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.hooks;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.utility.Logger;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.utility.Utils;
import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners.items;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.palmergames.bukkit.towny.event.NationAddTownEvent;
import com.palmergames.bukkit.towny.event.NationPreRenameEvent;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.event.TownAddResidentEvent;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.utility;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,6 +1,6 @@
package com.github.alathra.AlathranWars.utility;
import com.github.alathra.AlathranWars.conflict.WarController;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Location;