Class War
java.lang.Object
me.tayebyassine.homestead.models.War
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionWar(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).Create a new war with a generated snowflake ID.Create a new war with initial participating regions. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRegionId(long regionId) Add a region to the war.intGet the attacker's current kill count.intGet the defender's current kill count.@Nullable StringGet the description.@NotNull StringGet the display name.intGet the number of kills needed to win an ownership war.@NotNull StringgetName()Get the war name.doublegetPrize()Get the prize pool.Get a copy of the participating region IDs.Get all participating regions from the cache.longGet the start timestamp.longGet the timeout timestamp for ownership wars.longGet the unique snowflake ID.@NotNull War.WagerTypeGet the wager type.@Nullable RegionGet the winning region.booleanCheck if this war has timed out.voidremoveRegionId(long regionId) Remove a region from the war.voidsetAttackerKills(int attackerKills) Set the attacker's kill count.voidsetDefenderKills(int defenderKills) Set the defender's kill count.voidsetDescription(@Nullable String description) Set the description.voidsetDisplayName(@Nullable String displayName) Set the display name.voidsetKillsToWin(int killsToWin) Set the number of kills needed to win.voidSet the war name.voidsetPrize(double prize) Set the prize pool.voidsetRegionIds(List<Long> regionIds) Replace all participating region IDs.voidsetStartedAt(long startedAt) Set the start timestamp.voidsetTimeout(long timeout) Set the timeout timestamp.voidsetWagerType(@NotNull War.WagerType wagerType) Set the wager type.
-
Constructor Details
-
War
Create a new war with a generated snowflake ID.- Parameters:
name- the war name
-
War
-
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 IDname- the war namedisplayName- the display namedescription- the descriptionregionIds- the participating region IDsprize- the prize poolstartedAt- the start timestampwagerType- the wager typekillsToWin- kills needed to win (ownership wars)attackerKills- attacker's current kill countdefenderKills- defender's current kill counttimeout- timeout timestamp (0 = no timeout)
-
-
Method Details
-
getUniqueId
public long getUniqueId()Get the unique snowflake ID.- Returns:
- the war ID
-
getName
-
setName
Set the war name.- Parameters:
name- the new name
-
getDisplayName
Get the display name. Falls back to the name if not set.- Returns:
- the display name
-
setDisplayName
Set the display name.- Parameters:
displayName- the new display name, ornullto clear
-
getDescription
Get the description.- Returns:
- the description, or
nullif not set
-
setDescription
Set the description.- Parameters:
description- the new description, ornullto clear
-
getRegionIds
-
setRegionIds
-
getRegions
-
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
-
setWagerType
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:
trueif timeout is set and has passed
-
getWinner
Get the winning region. A region wins when it is the last one remaining.- Returns:
- the winning region, or
nullif the war is still in progress
-