mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 22:15:24 +00:00
feat: add util methods for checking town sieges
This commit is contained in:
3 files changed
+64
-32
No files matched your search
@@ -399,10 +399,10 @@ public class War extends Conflict {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Side> getSides() {
|
public Set<Side> getSides() {
|
||||||
final @NotNull Set<Side> sides = new HashSet<>();
|
return Set.of(
|
||||||
sides.add(getSide1());
|
getSide1(),
|
||||||
sides.add(getSide2());
|
getSide2()
|
||||||
return sides;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -508,6 +508,16 @@ public class War extends Conflict {
|
|||||||
raids.remove(raid);
|
raids.remove(raid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public boolean isTownUnderSiege(Town town) {
|
||||||
|
return sieges.stream().anyMatch(siege -> siege.getTown().equals(town));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public boolean isTownUnderRaid(Town town) {
|
||||||
|
return raids.stream().anyMatch(raid -> raid.getTown().equals(town));
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Player> getPlayers() {
|
public Set<Player> getPlayers() {
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class WarManager {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public War getWar(String warName) {
|
public War getWar(String warName) {
|
||||||
for (@NotNull War war : wars)
|
for (@NotNull War war : getWars())
|
||||||
if (war.equals(warName)) return war;
|
if (war.equals(warName)) return war;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -54,7 +54,7 @@ public class WarManager {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public War getWar(UUID uuid) {
|
public War getWar(UUID uuid) {
|
||||||
for (@NotNull War war : wars)
|
for (@NotNull War war : getWars())
|
||||||
if (war.equals(uuid)) return war;
|
if (war.equals(uuid)) return war;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -62,7 +62,7 @@ public class WarManager {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Side getSide(UUID uuid) {
|
public Side getSide(UUID uuid) {
|
||||||
for (@NotNull War war : wars)
|
for (@NotNull War war : getWars())
|
||||||
if (war.getSide(uuid) != null) return war.getSide(uuid);
|
if (war.getSide(uuid) != null) return war.getSide(uuid);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -70,25 +70,23 @@ public class WarManager {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Siege getSiege(UUID uuid) {
|
public Siege getSiege(UUID uuid) {
|
||||||
for (@NotNull War war : wars)
|
for (@NotNull War war : getWars())
|
||||||
if (war.getSiege(uuid) != null) return war.getSiege(uuid);
|
if (war.getSiege(uuid) != null) return war.getSiege(uuid);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWar(War war) {
|
public void addWar(War war) {
|
||||||
wars.add(war);
|
getWars().add(war);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeWar(War war) {
|
public void removeWar(War war) {
|
||||||
wars.remove(war);
|
getWars().remove(war);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerInAnyWars(UUID uuid) {
|
public boolean isPlayerInAnyWars(UUID uuid) {
|
||||||
for (@NotNull War war : wars) {
|
return getWars().stream()
|
||||||
if (war.isPlayerInWar(uuid)) return true;
|
.anyMatch(war -> war.isPlayerInWar(uuid));
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerInAnyWars(@NotNull Player p) {
|
public boolean isPlayerInAnyWars(@NotNull Player p) {
|
||||||
@@ -100,40 +98,68 @@ public class WarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Set<War> getPlayerWars(UUID uuid) {
|
public @NotNull Set<War> getPlayerWars(UUID uuid) {
|
||||||
return wars.stream()
|
return getWars().stream()
|
||||||
.filter(war -> war.isPlayerInWar(uuid))
|
.filter(war -> war.isPlayerInWar(uuid))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTownInAnyWars(Town town) {
|
public boolean isTownInAnyWars(Town town) {
|
||||||
for (@NotNull War war : wars) {
|
return getWars().stream()
|
||||||
if (war.isTownInWar(town)) return true;
|
.anyMatch(war -> war.isTownInWar(town));
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
public boolean isTownInAnySieges(Town town) {
|
||||||
|
return getWars().stream()
|
||||||
|
.anyMatch(war -> war.isTownInWar(town) && war.isTownUnderSiege(town));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTownInAnyRaids(Town town) {
|
||||||
|
return getWars().stream()
|
||||||
|
.anyMatch(war -> war.isTownInWar(town) && war.isTownUnderRaid(town));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNationInAnySieges(Nation nation) {
|
||||||
|
return nation.getTowns().stream()
|
||||||
|
.anyMatch(this::isTownInAnySieges);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNationInAnyRaids(Nation nation) {
|
||||||
|
return nation.getTowns().stream()
|
||||||
|
.anyMatch(this::isTownInAnyRaids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<Siege> getTownSieges(Town town) {
|
||||||
|
return getSieges().stream()
|
||||||
|
.filter(siege -> siege.getAttackerSide().isTownOnSide(town) || siege.getDefenderSide().isTownOnSide(town))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<Raid> getTownRaids(Town town) {
|
||||||
|
return getRaids().stream()
|
||||||
|
.filter(raid -> raid.getAttackerSide().isTownOnSide(town) || raid.getDefenderSide().isTownOnSide(town))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Set<War> getTownWars(Town town) {
|
public @NotNull Set<War> getTownWars(Town town) {
|
||||||
return wars.stream()
|
return getWars().stream()
|
||||||
.filter(war -> war.isTownInWar(town))
|
.filter(war -> war.isTownInWar(town))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNationInAnyWars(Nation nation) {
|
public boolean isNationInAnyWars(Nation nation) {
|
||||||
for (@NotNull War war : wars) {
|
return getWars().stream()
|
||||||
if (war.isNationInWar(nation)) return true;
|
.anyMatch(war -> war.isNationInWar(nation));
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Set<War> getNationWars(Nation nation) {
|
public @NotNull Set<War> getNationWars(Nation nation) {
|
||||||
return wars.stream()
|
return getWars().stream()
|
||||||
.filter(war -> war.isNationInWar(nation))
|
.filter(war -> war.isNationInWar(nation))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getWarNames() {
|
public List<String> getWarNames() {
|
||||||
return wars.stream()
|
return getWars().stream()
|
||||||
.map(War::getName)
|
.map(War::getName)
|
||||||
.sorted(String::compareToIgnoreCase)
|
.sorted(String::compareToIgnoreCase)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -141,7 +167,7 @@ public class WarManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getWarLabels() {
|
public List<String> getWarLabels() {
|
||||||
return wars.stream()
|
return getWars().stream()
|
||||||
.map(War::getLabel)
|
.map(War::getLabel)
|
||||||
.sorted(String::compareToIgnoreCase)
|
.sorted(String::compareToIgnoreCase)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -168,11 +194,8 @@ public class WarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerInAnySiege(UUID uuid) {
|
public boolean isPlayerInAnySiege(UUID uuid) {
|
||||||
for (@NotNull Siege siege : getSieges()) {
|
return getSieges().stream()
|
||||||
if (siege.isPlayerInSiege(uuid)) return true;
|
.anyMatch(siege -> siege.isPlayerInSiege(uuid));
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Set<Siege> getPlayerSieges(@NotNull Player p) {
|
public @NotNull Set<Siege> getPlayerSieges(@NotNull Player p) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.palmergames.bukkit.towny.event.town.TownKickEvent;
|
|||||||
import com.palmergames.bukkit.towny.event.town.TownLeaveEvent;
|
import com.palmergames.bukkit.towny.event.town.TownLeaveEvent;
|
||||||
import com.palmergames.bukkit.towny.event.town.TownPreMergeEvent;
|
import com.palmergames.bukkit.towny.event.town.TownPreMergeEvent;
|
||||||
import com.palmergames.bukkit.towny.event.town.TownRuinedEvent;
|
import com.palmergames.bukkit.towny.event.town.TownRuinedEvent;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
|||||||
Reference in new issue
Block a user