Class War

java.lang.Object
me.tayebyassine.homestead.models.War

public final class War extends Object
Represents a war between multiple regions.

A war tracks participating regions by ID, a shared prize pool, and a start timestamp. When only one region remains, getWinner() returns it as the victor.

  • Constructor Details

    • War

      public War(String name)
      Create a new war with a generated snowflake ID.
      Parameters:
      name - the war name
    • War

      public War(String name, List<Long> regionIds)
      Create a new war with initial participating regions.
      Parameters:
      name - the war name
      regionIds - the participating region IDs
    • War

      public War(long id, String name, String displayName, String description, List<Long> regionIds, double prize, long startedAt, War.WagerType wagerType, int killsToWin, int attackerKills, int defenderKills, long timeout)
      Create a war from pre-existing data (deserialisation).
      Parameters:
      id - the snowflake ID
      name - the war name
      displayName - the display name
      description - the description
      regionIds - the participating region IDs
      prize - the prize pool
      startedAt - the start timestamp
      wagerType - the wager type
      killsToWin - kills needed to win (ownership wars)
      attackerKills - attacker's current kill count
      defenderKills - defender's current kill count
      timeout - timeout timestamp (0 = no timeout)
  • Method Details

    • getUniqueId

      public long getUniqueId()
      Get the unique snowflake ID.
      Returns:
      the war ID
    • getName

      @NotNull public @NotNull String getName()
      Get the war name.
      Returns:
      the name
    • setName

      public void setName(@NotNull @NotNull String name)
      Set the war name.
      Parameters:
      name - the new name
    • getDisplayName

      @NotNull public @NotNull String getDisplayName()
      Get the display name. Falls back to the name if not set.
      Returns:
      the display name
    • setDisplayName

      public void setDisplayName(@Nullable @Nullable String displayName)
      Set the display name.
      Parameters:
      displayName - the new display name, or null to clear
    • getDescription

      @Nullable public @Nullable String getDescription()
      Get the description.
      Returns:
      the description, or null if not set
    • setDescription

      public void setDescription(@Nullable @Nullable String description)
      Set the description.
      Parameters:
      description - the new description, or null to clear
    • getRegionIds

      public List<Long> getRegionIds()
      Get a copy of the participating region IDs.
      Returns:
      a list of region IDs
    • setRegionIds

      public void setRegionIds(List<Long> regionIds)
      Replace all participating region IDs.
      Parameters:
      regionIds - the new list of region IDs
    • getRegions

      public List<Region> getRegions()
      Get all participating regions from the cache.
      Returns:
      a list of resolved regions (missing IDs are silently omitted)
    • addRegionId

      public void addRegionId(long regionId)
      Add a region to the war. Ignored if already present.
      Parameters:
      regionId - the region ID to add
    • removeRegionId

      public void removeRegionId(long regionId)
      Remove a region from the war.
      Parameters:
      regionId - the region ID to remove
    • getPrize

      public double getPrize()
      Get the prize pool.
      Returns:
      the prize amount
    • setPrize

      public void setPrize(double prize)
      Set the prize pool.
      Parameters:
      prize - the new prize amount
    • getStartedAt

      public long getStartedAt()
      Get the start timestamp.
      Returns:
      the epoch-millis timestamp
    • setStartedAt

      public void setStartedAt(long startedAt)
      Set the start timestamp.
      Parameters:
      startedAt - the new timestamp
    • getWagerType

      @NotNull public @NotNull War.WagerType getWagerType()
      Get the wager type.
      Returns:
      the wager type
    • setWagerType

      public void setWagerType(@NotNull @NotNull War.WagerType wagerType)
      Set the wager type.
      Parameters:
      wagerType - the new wager type
    • getKillsToWin

      public int getKillsToWin()
      Get the number of kills needed to win an ownership war.
      Returns:
      kills to win
    • setKillsToWin

      public void setKillsToWin(int killsToWin)
      Set the number of kills needed to win.
      Parameters:
      killsToWin - the kills threshold
    • getAttackerKills

      public int getAttackerKills()
      Get the attacker's current kill count.
      Returns:
      attacker kills
    • setAttackerKills

      public void setAttackerKills(int attackerKills)
      Set the attacker's kill count.
      Parameters:
      attackerKills - the kill count
    • getDefenderKills

      public int getDefenderKills()
      Get the defender's current kill count.
      Returns:
      defender kills
    • setDefenderKills

      public void setDefenderKills(int defenderKills)
      Set the defender's kill count.
      Parameters:
      defenderKills - the kill count
    • getTimeout

      public long getTimeout()
      Get the timeout timestamp for ownership wars.
      Returns:
      timeout epoch-millis, or 0 if no timeout
    • setTimeout

      public void setTimeout(long timeout)
      Set the timeout timestamp.
      Parameters:
      timeout - the timeout epoch-millis, or 0 to clear
    • hasTimedOut

      public boolean hasTimedOut()
      Check if this war has timed out.
      Returns:
      true if timeout is set and has passed
    • getWinner

      @Nullable public @Nullable Region getWinner()
      Get the winning region. A region wins when it is the last one remaining.
      Returns:
      the winning region, or null if the war is still in progress