Class WarManager
java.lang.Object
tfagaming.projects.minecraft.homestead.managers.WarManager
A utility class that manages
War declaration, participation, and lifecycle.-
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 WardeclareWar(String name, double prize, Region regionA, Region regionB) Declares a new war between exactly two regions.static intEnds all active wars immediately.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.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 booleanisNameUsed(String name) Checks whether any active war already carries the supplied name (case-insensitive).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 WarremoveRegionFromWar(long regionId) Removes the given region from whichever war it belongs to, without ending the 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 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
Returns all active wars.- Returns:
- List of wars.
-
getActiveWars
Returns all active wars (alias for semantic clarity).- Returns:
- List of active wars.
-
findWar
Retrieves the war with the exact ID.- Parameters:
warId- The war ID- Returns:
- The War, or
null.
-
findWar
Retrieves the war with the exact name (case-sensitive).- Parameters:
name- The war name- Returns:
- The War, or
null.
-
findWarIgnoreCase
Finds a war by name (case-insensitive).- Parameters:
name- The war name- Returns:
- The War, or
null.
-
getWarNames
Returns all war names for tab-completion.- Returns:
- List of war names.
-
findWarByRegion
Returns the war the given region is participating in.- Parameters:
regionId- The region ID- Returns:
- The War, or
null.
-
getWarsByRegion
Returns all wars a region is participating in.- Parameters:
region- The region- Returns:
- List of wars.
-
getWarsByRegion
Returns all wars a region is participating in.- Parameters:
regionId- The region ID- Returns:
- List of wars.
-
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
-
canDeclareWar
Checks if two regions can declare war (pre-flight validation).- Parameters:
regionA- The first regionregionB- The second region- Returns:
trueif war can be declared.
-
addRegionToWar
Adds a region to an existing war.- Parameters:
war- The warregion- The region to add- Returns:
trueif added successfully.
-
endWar
public static void endWar(long warId) Ends and removes the war with the given ID.- Parameters:
warId- The war ID
-
forceEndWar
Ends a war and declares a specific winner.- Parameters:
war- The warwinner- The winning region
-
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
Returns wars sorted by prize descending.- Parameters:
limit- Maximum results- Returns:
- List of wars.
-
getRecentWars
Returns the most recently declared wars.- Parameters:
limit- Maximum results- Returns:
- List of recent wars.
-
getWarParticipants
Returns all regions participating in a war.- Parameters:
war- The war- Returns:
- List of regions.
-
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
Returns only online players participating in a war.- Parameters:
war- The war- Returns:
- List of online players.
-
getMembersOfWar
Collects all members and owners from every region in the war.- Parameters:
warId- The war ID- Returns:
- List of unique players.
-
getMembersOfWar
Collects all members and owners from every region in the war.- Parameters:
war- The war- Returns:
- List of unique players.
-
isPlayerInWar
public static boolean isPlayerInWar(org.bukkit.OfflinePlayer player) Returnstrueif the given player is a member or owner of any active war.- Parameters:
player- The player- Returns:
trueif in any war.
-
isPlayerInWar
Returnstrueif the given player is a member or owner of the specified war.- Parameters:
player- The playerwar- The war- Returns:
trueif in the 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.
-
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.
-
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.
-
updateWarPrize
Updates the prize for a war.- Parameters:
war- The warnewPrize- The new prize amount
-
sendWarMessage
Sends a message to all online participants of a war.- Parameters:
war- The warmessage- The message to send
-
playWarSound
Plays a sound to all online participants of a war.- Parameters:
war- The warsound- The sound to play
-
tellPlayersWarEnded
Notifies all war participants that the war has ended.- Parameters:
receivers- The players to notifywinner- The winning region
-
broadcastDeclarationOfWar
Broadcasts the declaration of war to participants or the entire server.- Parameters:
war- The war to broadcast
-
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.
-