java.lang.Object
tfagaming.projects.minecraft.homestead.managers.WarManager

public final class WarManager extends Object
A utility class that manages War declaration, participation, and lifecycle.
  • Method Details

    • getWarCount

      public static int getWarCount()
      Returns the total number of active wars.
      Returns:
      War count.
    • getAll

      public static List<War> getAll()
      Returns all active wars.
      Returns:
      List of wars.
    • getActiveWars

      public static List<War> getActiveWars()
      Returns all active wars (alias for semantic clarity).
      Returns:
      List of active wars.
    • findWar

      public static War findWar(long warId)
      Retrieves the war with the exact ID.
      Parameters:
      warId - The war ID
      Returns:
      The War, or null.
    • findWar

      public static War findWar(String name)
      Retrieves the war with the exact name (case-sensitive).
      Parameters:
      name - The war name
      Returns:
      The War, or null.
    • findWarIgnoreCase

      public static War findWarIgnoreCase(String name)
      Finds a war by name (case-insensitive).
      Parameters:
      name - The war name
      Returns:
      The War, or null.
    • getWarNames

      public static List<String> getWarNames()
      Returns all war names for tab-completion.
      Returns:
      List of war names.
    • findWarByRegion

      public static War findWarByRegion(long regionId)
      Returns the war the given region is participating in.
      Parameters:
      regionId - The region ID
      Returns:
      The War, or null.
    • getWarsByRegion

      public static List<War> getWarsByRegion(Region region)
      Returns all wars a region is participating in.
      Parameters:
      region - The region
      Returns:
      List of wars.
    • getWarsByRegion

      public static List<War> getWarsByRegion(long regionId)
      Returns all wars a region is participating in.
      Parameters:
      regionId - The region ID
      Returns:
      List of wars.
    • declareWar

      public static War declareWar(String name, double prize, Region regionA, Region regionB)
      Declares a new war between exactly two regions.
      Parameters:
      name - The war display name
      prize - The reward given to the winning region; must be > 0
      regionA - The first participating region
      regionB - The second participating region
      Returns:
      The created War.
      Throws:
      IllegalArgumentException - if regions are identical
      IllegalStateException - if either region is already in a war
    • canDeclareWar

      public static boolean canDeclareWar(Region regionA, Region regionB)
      Checks if two regions can declare war (pre-flight validation).
      Parameters:
      regionA - The first region
      regionB - The second region
      Returns:
      true if war can be declared.
    • addRegionToWar

      public static boolean addRegionToWar(War war, Region region)
      Adds a region to an existing war.
      Parameters:
      war - The war
      region - The region to add
      Returns:
      true if added successfully.
    • endWar

      public static void endWar(long warId)
      Ends and removes the war with the given ID.
      Parameters:
      warId - The war ID
    • forceEndWar

      public static void forceEndWar(War war, Region winner)
      Ends a war and declares a specific winner.
      Parameters:
      war - The war
      winner - The winning region
    • endAllWars

      public static int endAllWars()
      Ends all active wars immediately.
      Returns:
      The number of wars ended.
    • getWarDuration

      public static long getWarDuration(War war)
      Returns how long a war has been running in milliseconds.
      Parameters:
      war - The war
      Returns:
      Duration in milliseconds.
    • getLongestWar

      public static War getLongestWar()
      Returns the war with the longest duration.
      Returns:
      The longest running war, or null.
    • getRichestWar

      public static War getRichestWar()
      Returns the war with the highest prize.
      Returns:
      The richest war, or null.
    • getWarLeaderboard

      public static List<War> getWarLeaderboard(int limit)
      Returns wars sorted by prize descending.
      Parameters:
      limit - Maximum results
      Returns:
      List of wars.
    • getRecentWars

      public static List<War> getRecentWars(int limit)
      Returns the most recently declared wars.
      Parameters:
      limit - Maximum results
      Returns:
      List of recent wars.
    • getWarParticipants

      public static List<Region> getWarParticipants(War war)
      Returns all regions participating in a war.
      Parameters:
      war - The war
      Returns:
      List of regions.
    • getWarParticipantCount

      public static int getWarParticipantCount(War war)
      Returns the number of regions in a war.
      Parameters:
      war - The war
      Returns:
      Participant count.
    • getWarMemberCount

      public static int getWarMemberCount(War war)
      Returns the total number of unique players involved in a war.
      Parameters:
      war - The war
      Returns:
      Player count.
    • getOnlineWarMembers

      public static List<org.bukkit.entity.Player> getOnlineWarMembers(War war)
      Returns only online players participating in a war.
      Parameters:
      war - The war
      Returns:
      List of online players.
    • getMembersOfWar

      public static List<org.bukkit.OfflinePlayer> getMembersOfWar(long warId)
      Collects all members and owners from every region in the war.
      Parameters:
      warId - The war ID
      Returns:
      List of unique players.
    • getMembersOfWar

      public static List<org.bukkit.OfflinePlayer> getMembersOfWar(War war)
      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)
      Returns true if the given player is a member or owner of any active war.
      Parameters:
      player - The player
      Returns:
      true if in any war.
    • isPlayerInWar

      public static boolean isPlayerInWar(org.bukkit.OfflinePlayer player, War war)
      Returns true if the given player is a member or owner of the specified war.
      Parameters:
      player - The player
      war - The war
      Returns:
      true if in the war.
    • removeRegionFromWar

      public static War removeRegionFromWar(long regionId)
      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

      public static boolean isNameUsed(String name)
      Checks whether any active war already carries the supplied name (case-insensitive).
      Parameters:
      name - The name to check
      Returns:
      true if the name is used.
    • isWarNameUsed

      public static boolean isWarNameUsed(String name)
      Checks whether any active war already carries the supplied name (case-sensitive).
      Parameters:
      name - The name to check
      Returns:
      true if the name is used.
    • isRegionInWar

      public static boolean isRegionInWar(Region region)
      Returns true if the given region is currently participating in any war.
      Parameters:
      region - The region
      Returns:
      true if in a war.
    • isRegionInWar

      public static boolean isRegionInWar(long regionId)
      Returns true if the given region is currently participating in any war.
      Parameters:
      regionId - The region ID
      Returns:
      true if in a war.
    • updateWarPrize

      public static void updateWarPrize(War war, double newPrize)
      Updates the prize for a war.
      Parameters:
      war - The war
      newPrize - The new prize amount
    • sendWarMessage

      public static void sendWarMessage(War war, String message)
      Sends a message to all online participants of a war.
      Parameters:
      war - The war
      message - The message to send
    • playWarSound

      public static void playWarSound(War war, org.bukkit.Sound sound)
      Plays a sound to all online participants of a war.
      Parameters:
      war - The war
      sound - The sound to play
    • tellPlayersWarEnded

      public static void tellPlayersWarEnded(List<org.bukkit.OfflinePlayer> receivers, Region winner)
      Notifies all war participants that the war has ended.
      Parameters:
      receivers - The players to notify
      winner - The winning region
    • broadcastDeclarationOfWar

      public static void broadcastDeclarationOfWar(War war)
      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.