Class WarManager

java.lang.Object
me.tayebyassine.homestead.managers.WarManager

public final class WarManager extends Object
A utility class that manages War.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addRegionToWar(War war, Region region)
    Adds a region to an existing war.
    static void
    Broadcasts the declaration of war to participants or the entire server.
    static boolean
    canDeclareWar(Region regionA, Region regionB)
    Checks if two regions can declare war (pre-flight validation).
    static int
    Removes all wars with invalid references:
    - Regions that no longer exist
    - Wars with fewer than 2 valid regions
    static War
    declareOwnershipWar(String name, Region regionA, Region regionB, int killsToWin, int timeout)
    Declares an ownership wager war between two regions.
    static War
    declareWar(String name, double prize, Region regionA, Region regionB)
    Declares a new war between exactly two regions.
    static int
    Ends all active wars immediately.
    static void
    endOwnershipWar(War war, Region winner)
    Ends an ownership war and transfers the loser's region ownership.
    static void
    endWar(long warId)
    Ends and removes the war with the given ID.
    static War
    findWar(long warId)
    Retrieves the war with the exact ID.
    static War
    Retrieves the war with the exact name (case-sensitive).
    static War
    findWarByRegion(long regionId)
    Returns the war the given region is participating in.
    static War
    Finds a war by name (case-insensitive).
    static void
    forceEndWar(War war, Region winner)
    Ends a war and declares a specific winner.
    static List<War>
    Returns all active wars (alias for semantic clarity).
    static List<War>
    Returns all active wars.
    static War
    Returns 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>
    Collects all members and owners from every region in the war.
    static List<org.bukkit.entity.Player>
    Returns only online players participating in a war.
    static @Nullable Region
    Determines the winner of an ownership war based on kill counts.
    static List<War>
    getRecentWars(int limit)
    Returns the most recently declared wars.
    static War
    Returns the war with the highest prize.
    static int
    Returns the total number of active wars.
    static long
    Returns how long a war has been running in milliseconds.
    static List<War>
    getWarLeaderboard(int limit)
    Returns wars sorted by prize descending.
    static int
    Returns the total number of unique players involved in a war.
    static List<String>
    Returns all war names for tab-completion.
    static int
    Returns the number of regions in a war.
    static List<Region>
    Returns all regions participating in a war.
    static List<War>
    getWarsByRegion(long regionId)
    Returns all wars a region is participating in.
    static List<War>
    Returns all wars a region is participating in.
    static @Nullable Region
    Checks if an ownership war has timed out and declares a winner based on kills.
    static boolean
    Checks whether any active war already carries the supplied name (case-insensitive).
    static boolean
    Checks if a war is an ownership wager war.
    static boolean
    isPlayerInWar(org.bukkit.OfflinePlayer player)
    Returns true if the given player is a member or owner of any active war.
    static boolean
    isPlayerInWar(org.bukkit.OfflinePlayer player, War war)
    Returns true if the given player is a member or owner of the specified war.
    static boolean
    isRegionInWar(long regionId)
    Returns true if the given region is currently participating in any war.
    static boolean
    Returns true if the given region is currently participating in any war.
    static boolean
    Checks whether any active war already carries the supplied name (case-sensitive).
    static void
    playWarSound(War war, org.bukkit.Sound sound)
    Plays a sound to all online participants of a war.
    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.
    static War
    removeRegionFromWar(long regionId)
    Removes the given region from whichever war it belongs to, without ending the war.
    static void
    Schedules a timeout task for an ownership war.
    static void
    sendWarMessage(War war, String message)
    Sends a message to all online participants of a war.
    static void
    tellPlayersWarEnded(List<org.bukkit.OfflinePlayer> receivers, Region winner)
    Notifies all war participants that the war has ended.
    static void
    transferOwnership(War war, Region loser, Region winner)
    Transfers ownership of a region from its current owner to a member of the winning region.
    static void
    updateWarPrize(War war, double newPrize)
    Updates the prize for a war.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • 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 name
      regionA - the attacking region
      regionB - the defending region
      killsToWin - the number of kills needed to win
      timeout - the timeout in minutes (0 = no timeout)
      Returns:
      the created war
    • isOwnershipWar

      public static boolean isOwnershipWar(War war)
      Checks if a war is an ownership wager war.
      Parameters:
      war - the war
      Returns:
      true if 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 war
      killerRegion - the region of the killer
      victimRegion - the region of the victim
      killer - the killer player
      victim - the victim player
    • getOwnershipWinner

      @Nullable public static @Nullable Region getOwnershipWinner(War war)
      Determines the winner of an ownership war based on kill counts.
      Parameters:
      war - the war
      Returns:
      the winning region, or null if no winner yet
    • handleTimeout

      @Nullable public static @Nullable Region handleTimeout(War war)
      Checks if an ownership war has timed out and declares a winner based on kills.
      Parameters:
      war - the war
      Returns:
      the winning region, or null if no timeout or no winner
    • endOwnershipWar

      public static void endOwnershipWar(War war, Region winner)
      Ends an ownership war and transfers the loser's region ownership.
      Parameters:
      war - the war
      winner - the winning region
    • transferOwnership

      public static void transferOwnership(War war, Region loser, Region winner)
      Transfers ownership of a region from its current owner to a member of the winning region.
      Parameters:
      war - the war
      loser - the losing region
      winner - the winning region
    • scheduleTimeout

      public static void scheduleTimeout(War war)
      Schedules a timeout task for an ownership war.
      Parameters:
      war - the 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.

      Returns false while the wars feature is disabled.

      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.

      Returns false while the wars feature is disabled.

      Parameters:
      player - the player
      war - the war
      Returns:
      true if in the war
    • 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
    • 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
    • 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
    • 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
    • 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