Class WarManager
java.lang.Object
me.tayebyassine.homestead.managers.WarManager
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddRegionToWar(War war, Region region) Adds a region to an existing war.static voidBroadcasts the declaration of war to participants or the entire server.static booleancanDeclareWar(Region regionA, Region regionB) Checks if two regions can declare war (pre-flight validation).static intRemoves all wars with invalid references:
- Regions that no longer exist
- Wars with fewer than 2 valid regionsstatic WardeclareOwnershipWar(String name, Region regionA, Region regionB, int killsToWin, int timeout) Declares an ownership wager war between two regions.static WardeclareWar(String name, double prize, Region regionA, Region regionB) Declares a new war between exactly two regions.static intEnds all active wars immediately.static voidendOwnershipWar(War war, Region winner) Ends an ownership war and transfers the loser's region ownership.static voidendWar(long warId) Ends and removes the war with the given ID.static WarfindWar(long warId) Retrieves the war with the exact ID.static WarRetrieves the war with the exact name (case-sensitive).static WarfindWarByRegion(long regionId) Returns the war the given region is participating in.static WarfindWarIgnoreCase(String name) Finds a war by name (case-insensitive).static voidforceEndWar(War war, Region winner) Ends a war and declares a specific winner.Returns all active wars (alias for semantic clarity).getAll()Returns all active wars.static WarReturns the war with the longest duration.static List<org.bukkit.OfflinePlayer> getMembersOfWar(long warId) Collects all members and owners from every region in the war.static List<org.bukkit.OfflinePlayer> getMembersOfWar(War war) Collects all members and owners from every region in the war.static List<org.bukkit.entity.Player> getOnlineWarMembers(War war) Returns only online players participating in a war.static @Nullable RegiongetOwnershipWinner(War war) Determines the winner of an ownership war based on kill counts.getRecentWars(int limit) Returns the most recently declared wars.static WarReturns the war with the highest prize.static intReturns the total number of active wars.static longgetWarDuration(War war) Returns how long a war has been running in milliseconds.getWarLeaderboard(int limit) Returns wars sorted by prize descending.static intgetWarMemberCount(War war) Returns the total number of unique players involved in a war.Returns all war names for tab-completion.static intReturns the number of regions in a war.getWarParticipants(War war) Returns all regions participating in a war.getWarsByRegion(long regionId) Returns all wars a region is participating in.getWarsByRegion(Region region) Returns all wars a region is participating in.static @Nullable RegionhandleTimeout(War war) Checks if an ownership war has timed out and declares a winner based on kills.static booleanisNameUsed(String name) Checks whether any active war already carries the supplied name (case-insensitive).static booleanisOwnershipWar(War war) Checks if a war is an ownership wager war.static booleanisPlayerInWar(org.bukkit.OfflinePlayer player) Returnstrueif the given player is a member or owner of any active war.static booleanisPlayerInWar(org.bukkit.OfflinePlayer player, War war) Returnstrueif the given player is a member or owner of the specified war.static booleanisRegionInWar(long regionId) Returnstrueif the given region is currently participating in any war.static booleanisRegionInWar(Region region) Returnstrueif the given region is currently participating in any war.static booleanisWarNameUsed(String name) Checks whether any active war already carries the supplied name (case-sensitive).static voidplayWarSound(War war, org.bukkit.Sound sound) Plays a sound to all online participants of a war.static voidrecordKill(War war, Region killerRegion, Region victimRegion, org.bukkit.OfflinePlayer killer, org.bukkit.OfflinePlayer victim) Records a kill for the given region in an ownership war.static WarremoveRegionFromWar(long regionId) Removes the given region from whichever war it belongs to, without ending the war.static voidscheduleTimeout(War war) Schedules a timeout task for an ownership war.static voidsendWarMessage(War war, String message) Sends a message to all online participants of a war.static voidtellPlayersWarEnded(List<org.bukkit.OfflinePlayer> receivers, Region winner) Notifies all war participants that the war has ended.static voidtransferOwnership(War war, Region loser, Region winner) Transfers ownership of a region from its current owner to a member of the winning region.static voidupdateWarPrize(War war, double newPrize) Updates the prize for a war.
-
Method Details
-
getWarCount
public static int getWarCount()Returns the total number of active wars.- Returns:
- war count
-
getAll
-
getActiveWars
-
findWar
Retrieves the war with the exact ID.- Parameters:
warId- the war ID- Returns:
- the war, or
null
-
findWar
-
findWarIgnoreCase
-
getWarNames
-
findWarByRegion
Returns the war the given region is participating in.- Parameters:
regionId- the region ID- Returns:
- the war, or
null
-
getWarsByRegion
-
getWarsByRegion
-
declareWar
Declares a new war between exactly two regions.- Parameters:
name- the war display nameprize- the reward given to the winning region; must be > 0regionA- the first participating regionregionB- the second participating region- Returns:
- the created war
- Throws:
IllegalArgumentException- if regions are identicalIllegalStateException- if either region is already in a war
-
declareOwnershipWar
public static War declareOwnershipWar(String name, Region regionA, Region regionB, int killsToWin, int timeout) Declares an ownership wager war between two regions. The loser's region ownership is transferred to a member of the winning region.- Parameters:
name- the war display nameregionA- the attacking regionregionB- the defending regionkillsToWin- the number of kills needed to wintimeout- the timeout in minutes (0 = no timeout)- Returns:
- the created war
-
isOwnershipWar
Checks if a war is an ownership wager war.- Parameters:
war- the war- Returns:
trueif ownership wager
-
recordKill
public static void recordKill(War war, Region killerRegion, Region victimRegion, org.bukkit.OfflinePlayer killer, org.bukkit.OfflinePlayer victim) Records a kill for the given region in an ownership war.- Parameters:
war- the warkillerRegion- the region of the killervictimRegion- the region of the victimkiller- the killer playervictim- the victim player
-
getOwnershipWinner
-
handleTimeout
-
endOwnershipWar
-
transferOwnership
-
scheduleTimeout
Schedules a timeout task for an ownership war.- Parameters:
war- the war
-
canDeclareWar
-
addRegionToWar
-
endWar
public static void endWar(long warId) Ends and removes the war with the given ID.- Parameters:
warId- the war ID
-
forceEndWar
-
endAllWars
public static int endAllWars()Ends all active wars immediately.- Returns:
- the number of wars ended
-
getWarDuration
Returns how long a war has been running in milliseconds.- Parameters:
war- the war- Returns:
- duration in milliseconds
-
getLongestWar
Returns the war with the longest duration.- Returns:
- the longest running war, or
null
-
getRichestWar
Returns the war with the highest prize.- Returns:
- the richest war, or
null
-
getWarLeaderboard
-
getRecentWars
-
getWarParticipants
-
getWarParticipantCount
Returns the number of regions in a war.- Parameters:
war- the war- Returns:
- participant count
-
getWarMemberCount
Returns the total number of unique players involved in a war.- Parameters:
war- the war- Returns:
- player count
-
getOnlineWarMembers
-
getMembersOfWar
Collects all members and owners from every region in the war.- Parameters:
warId- the war ID- Returns:
- list of unique players
-
getMembersOfWar
-
isPlayerInWar
public static boolean isPlayerInWar(org.bukkit.OfflinePlayer player) Returnstrueif the given player is a member or owner of any active war.Returns
falsewhile the wars feature is disabled.- Parameters:
player- the player- Returns:
trueif in any war
-
isPlayerInWar
Returnstrueif the given player is a member or owner of the specified war.Returns
falsewhile the wars feature is disabled.- Parameters:
player- the playerwar- the war- Returns:
trueif in the war
-
isRegionInWar
Returnstrueif the given region is currently participating in any war.- Parameters:
region- the region- Returns:
trueif in a war
-
isRegionInWar
public static boolean isRegionInWar(long regionId) Returnstrueif the given region is currently participating in any war.- Parameters:
regionId- the region ID- Returns:
trueif in a war
-
removeRegionFromWar
Removes the given region from whichever war it belongs to, without ending the war. The caller is responsible for checking the war's state afterward and ending it if needed.- Parameters:
regionId- the region ID to remove- Returns:
- the war the region was removed from, or
null
-
updateWarPrize
Updates the prize for a war.- Parameters:
war- the warnewPrize- the new prize amount
-
sendWarMessage
-
playWarSound
Plays a sound to all online participants of a war.- Parameters:
war- the warsound- the sound to play
-
tellPlayersWarEnded
-
broadcastDeclarationOfWar
Broadcasts the declaration of war to participants or the entire server.- Parameters:
war- the war to broadcast
-
isNameUsed
Checks whether any active war already carries the supplied name (case-insensitive).- Parameters:
name- the name to check- Returns:
trueif the name is used
-
isWarNameUsed
Checks whether any active war already carries the supplied name (case-sensitive).- Parameters:
name- the name to check- Returns:
trueif the name is used
-
cleanupInvalidWars
public static int cleanupInvalidWars()Removes all wars with invalid references:
- Regions that no longer exist
- Wars with fewer than 2 valid regions- Returns:
- number of corrupted wars removed
-