Class Hunt

java.lang.Object
com.Moshu.TreasureHunt.Core.Hunt

public class Hunt extends Object
Represents an active treasure hunt instance. This class manages the lifecycle of a treasure hunt, from creation to completion, including location generation, treasure spawning, and hunt state management. Each Hunt instance corresponds to a single treasure hunt event and contains all the necessary data and logic to manage that specific hunt.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Hunt(String treasureTypeString, int duration)
    Creates a new hunt at a random location with the specified treasure type and duration.
    Hunt(org.bukkit.Location location, String treasureTypeString, int duration)
    Creates a new hunt at a specific location with the specified treasure type and duration.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    activeHuntsMenu(org.bukkit.entity.Player p)
    Opens a GUI menu showing all currently active hunts for the specified player.
    static List<String>
    Retrieves the identifiers of all active treasure hunts.
    static List<Hunt>
    Retrieves all hunts that have active treasures spawned in the world.
    int
    Returns the configured duration for this hunt in minutes.
    long
    Calculates the elapsed time since the hunt started.
    static Hunt
    Retrieves an active hunt by its unique identifier.
    static List<Hunt>
    Hunt here are guaranteed to be active
    static List<String>
    Hunt here are guaranteed to be active
    static ArrayList<Hunt>
    getHuntsInWorld(org.bukkit.World w)
    Retrieves all hunts currently active in the specified world.
    org.bukkit.Location
    Returns the location where this hunt's treasure is or will be spawned.
    CompletableFuture<org.bukkit.Location>
    Provides a CompletableFuture that completes when the hunt location is ready.
    static Hunt
    getNearestHunt(org.bukkit.Location loc)
    Finds the hunt closest to the specified location.
    long
    Calculates the remaining time before the hunt expires.
    long
    Returns the timestamp when this hunt was started.
    Returns the treasure instance associated with this hunt.
    Returns the treasure configuration data associated with this hunt.
    static boolean
    huntActiveInWorld(org.bukkit.World w)
    Checks if there is any active hunt in the specified world.
    static String
    Returns a string representation of whether a hunt with the given identifier is active.
    boolean
    Checks if this specific hunt instance is currently active.
    static boolean
    Checks if a hunt with the specified identifier is currently active.
    static boolean
    isHuntActive(org.bukkit.Location loc)
    Checks if there is an active hunt at the specified location.
    void
    Gets called on removal of treasure
    void
    Starts the hunt by spawning the treasure at the designated location.
    void
    Stops and deactivates the hunt, cleaning up all associated resources.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Hunt

      public Hunt(String treasureTypeString, int duration)
      Creates a new hunt at a random location with the specified treasure type and duration. The location will be determined asynchronously based on the treasure configuration and world boundaries. This constructor initializes the hunt but does not start it.
      Parameters:
      treasureTypeString - the identifier of the treasure type to spawn
      duration - the duration in minutes for how long the hunt should remain active
    • Hunt

      public Hunt(org.bukkit.Location location, String treasureTypeString, int duration)
      Creates a new hunt at a specific location with the specified treasure type and duration. This constructor immediately sets the hunt location and initializes the hunt, but does not start it. The location must be valid and safe for treasure spawning.
      Parameters:
      location - the specific location where the treasure should spawn
      treasureTypeString - the identifier of the treasure type to spawn
      duration - the duration in minutes for how long the hunt should remain active
  • Method Details

    • setInactive

      public void setInactive()
      Gets called on removal of treasure
    • getHuntByIdentifier

      public static Hunt getHuntByIdentifier(String id)
      Retrieves an active hunt by its unique identifier. This method searches through all currently active hunts and returns the one matching the provided identifier.
      Parameters:
      id - the unique identifier of the hunt to retrieve
      Returns:
      the Hunt instance with the matching identifier, or null if no active hunt is found
    • huntActiveInWorld

      public static boolean huntActiveInWorld(org.bukkit.World w)
      Checks if there is any active hunt in the specified world. This method iterates through all active hunts to determine if any are located within the given world boundaries.
      Parameters:
      w - the world to check for active hunts
      Returns:
      true if at least one hunt is active in the world, false otherwise
    • getHuntsInWorld

      public static ArrayList<Hunt> getHuntsInWorld(org.bukkit.World w)
      Retrieves all hunts currently active in the specified world. This method filters all active hunts and returns only those that are located within the boundaries of the given world.
      Parameters:
      w - the world to search for hunts
      Returns:
      an ArrayList containing all hunts active in the specified world
    • start

      public void start()
      Starts the hunt by spawning the treasure at the designated location. This method activates the hunt, spawns the treasure with all its components (particles, keepers, effects), broadcasts messages to players, and starts the hunt timer. The hunt must have a valid location before calling this method.
    • getTreasureData

      public TreasureData getTreasureData()
      Returns the treasure configuration data associated with this hunt. The TreasureData contains all information from the treasure.yml file including rewards, spawn settings, particle effects, and keeper configurations.
      Returns:
      the TreasureData object containing all treasure configuration
    • getActiveTreasures

      public static List<Hunt> getActiveTreasures()
      Retrieves all hunts that have active treasures spawned in the world. This method filters hunts to return only those where the treasure has been successfully generated and is currently active (not just the hunt being active).
      Returns:
      a List of Hunt instances that have active treasures
    • getHunts

      public static List<Hunt> getHunts()
      Hunt here are guaranteed to be active
      Returns:
      a list of all the hunts active
    • getHuntsIdentifiers

      public static List<String> getHuntsIdentifiers()
      Hunt here are guaranteed to be active
      Returns:
      a list of all the hunts active
    • getActiveTreasureIdentifiers

      public static List<String> getActiveTreasureIdentifiers()
      Retrieves the identifiers of all active treasure hunts. This method returns the string identifiers for all hunts that have active treasures currently spawned in the world, useful for administrative purposes and API access.
      Returns:
      a List of String identifiers for all hunts with active treasures
    • getNearestHunt

      public static Hunt getNearestHunt(org.bukkit.Location loc)
      Finds the hunt closest to the specified location. This method calculates distances between the given location and all active hunt locations, returning the hunt with the minimum distance.
      Parameters:
      loc - the location to measure distances from
      Returns:
      the Hunt instance closest to the specified location, or null if no hunts are active
    • stop

      public void stop()
      Stops and deactivates the hunt, cleaning up all associated resources. This method removes the treasure from the world, despawns any associated keepers, stops particle effects, removes the hunt from active collections, and performs all necessary cleanup operations.
    • getRemainingTime

      public long getRemainingTime()
      Calculates the remaining time before the hunt expires. This method computes the time left by subtracting the elapsed time from the total duration, returning the result in milliseconds.
      Returns:
      the remaining time in milliseconds before the hunt expires, or 0 if expired
    • isHuntActive

      public static boolean isHuntActive(org.bukkit.Location loc)
      Checks if there is an active hunt at the specified location. This method determines if any hunt has a treasure spawned at or very close to the given location coordinates.
      Parameters:
      loc - the location to check for active hunts
      Returns:
      true if a hunt is active at the location, false otherwise
    • isHuntActive

      public boolean isHuntActive()
      Checks if this specific hunt instance is currently active. This method verifies that the hunt is in the active hunts collection and has not been stopped or expired.
      Returns:
      true if this hunt is currently active, false otherwise
    • isHuntActive

      public static boolean isHuntActive(String id)
      Checks if a hunt with the specified identifier is currently active. This method searches the active hunts collection for a hunt matching the given identifier string.
      Parameters:
      id - the identifier to check for activity
      Returns:
      true if a hunt with the identifier is active, false otherwise
    • isActiveString

      public static String isActiveString(String id)
      Returns a string representation of whether a hunt with the given identifier is active. This method provides a user-friendly string response indicating the active status of a hunt, useful for command responses and administrative interfaces.
      Parameters:
      id - the identifier to check for activity status
      Returns:
      a String indicating whether the hunt is active or not
    • getLocation

      public org.bukkit.Location getLocation()
      Returns the location where this hunt's treasure is or will be spawned. For hunts created with random locations, this may return null until a suitable location is found asynchronously.
      Returns:
      the Location where the treasure is positioned, or null if not yet determined
    • getLocationReadyFuture

      public CompletableFuture<org.bukkit.Location> getLocationReadyFuture()
      Provides a CompletableFuture that completes when the hunt location is ready. This is particularly useful for hunts created with random locations, allowing callers to react asynchronously when a suitable spawn location is found without blocking the main thread.
      Returns:
      a CompletableFuture that completes when the location is determined
    • getTreasure

      public Treasure getTreasure()
      Returns the treasure instance associated with this hunt. The treasure object contains the physical representation in the world, including blocks, entities, particles, and interaction handlers.
      Returns:
      the Treasure instance spawned by this hunt, or null if not yet spawned
    • getDuration

      public int getDuration()
      Returns the configured duration for this hunt in minutes. This represents the total time the hunt should remain active before automatically expiring and cleaning up.
      Returns:
      the duration in minutes for this hunt
    • getElapsedTime

      public long getElapsedTime()
      Calculates the elapsed time since the hunt started. This method computes the time that has passed since the hunt's startTime was set, returning the result in milliseconds.
      Returns:
      the elapsed time in milliseconds since the hunt started
    • getStartTime

      public long getStartTime()
      Returns the timestamp when this hunt was started. This value is set when the start() method is called and represents the time in milliseconds since epoch when the hunt became active.
      Returns:
      the start time in milliseconds since epoch, or 0 if not yet started
    • activeHuntsMenu

      public static void activeHuntsMenu(org.bukkit.entity.Player p)
      Opens a GUI menu showing all currently active hunts for the specified player. This method creates and displays an interactive menu interface where players can view information about all active treasure hunts, including locations, remaining time, and treasure details.
      Parameters:
      p - the player to show the active hunts menu to