Class TreasureScheduler

java.lang.Object
com.Moshu.TreasureHunt.TreasureScheduler

public class TreasureScheduler extends Object
Manages scheduled treasure hunts with configurable timing and location settings. This class handles the scheduling logic for treasure hunts, including day/time validation, location parsing, and automatic treasure spawning based on configured schedules.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for TreasureScheduler.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the treasure data configuration for this scheduler.
    Gets the configured day of the week for this scheduler.
    Gets the encoded coordinates string for this scheduler.
    Gets the unique identifier for this scheduler.
    org.bukkit.Location
    Parses the encoded coordinates and world to create a Location object.
    Gets the configured time for this scheduler.
    Gets the configured world name for this scheduler.
    boolean
    Checks if this scheduler is currently enabled.
    void
    Sets the treasure data configuration for this scheduler.
    void
    Sets the day of the week when the treasure hunt should spawn.
    void
    setEnabled(boolean enabled)
    Sets whether this scheduler is enabled or disabled.
    void
    setEncodedCoords(String encodedCoords)
    Sets the encoded coordinates for the treasure hunt location.
    void
    Sets the unique identifier for this scheduler.
    void
    Sets the time when the treasure hunt should spawn.
    void
    Sets the world where the treasure hunt should spawn.
    boolean
    Determines if a treasure hunt should spawn based on current time and scheduler configuration.
    boolean
    Attempts to spawn a treasure hunt based on the scheduler configuration.

    Methods inherited from class java.lang.Object

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

    • TreasureScheduler

      public TreasureScheduler()
      Default constructor for TreasureScheduler. Creates a new scheduler instance with default values.
  • Method Details

    • setId

      public void setId(String id)
      Sets the unique identifier for this scheduler.
      Parameters:
      id - The unique identifier string for the scheduler
    • setDay

      public void setDay(String day)
      Sets the day of the week when the treasure hunt should spawn. Valid values: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "daily"
      Parameters:
      day - The day of the week for scheduling
    • setTime

      public void setTime(String time)
      Sets the time when the treasure hunt should spawn. Expected format: "HH:MM" (24-hour format)
      Parameters:
      time - The time in HH:MM format when the treasure should spawn
    • setWorld

      public void setWorld(String world)
      Sets the world where the treasure hunt should spawn.
      Parameters:
      world - The name of the world for the treasure hunt
    • setEncodedCoords

      public void setEncodedCoords(String encodedCoords)
      Sets the encoded coordinates for the treasure hunt location. Format: "x:y:z" or "random" for random location generation
      Parameters:
      encodedCoords - The encoded coordinates string or "random"
    • setData

      public void setData(TreasureData data)
      Sets the treasure data configuration for this scheduler.
      Parameters:
      data - The TreasureData object containing hunt configuration
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether this scheduler is enabled or disabled.
      Parameters:
      enabled - True to enable the scheduler, false to disable it
    • isEnabled

      public boolean isEnabled()
      Checks if this scheduler is currently enabled.
      Returns:
      True if the scheduler is enabled, false otherwise
    • getLocation

      public org.bukkit.Location getLocation()
      Parses the encoded coordinates and world to create a Location object. Validates that the world exists and coordinates are properly formatted.
      Returns:
      The parsed Location object, or null if validation fails
    • getDay

      public String getDay()
      Gets the configured day of the week for this scheduler.
      Returns:
      The day string (e.g., "monday", "daily")
    • getTime

      public String getTime()
      Gets the configured time for this scheduler.
      Returns:
      The time string in HH:MM format
    • getWorld

      public String getWorld()
      Gets the configured world name for this scheduler.
      Returns:
      The world name string
    • getEncodedCoords

      public String getEncodedCoords()
      Gets the encoded coordinates string for this scheduler.
      Returns:
      The encoded coordinates string or "random"
    • getData

      public TreasureData getData()
      Gets the treasure data configuration for this scheduler.
      Returns:
      The TreasureData object
    • getId

      public String getId()
      Gets the unique identifier for this scheduler.
      Returns:
      The scheduler ID string
    • shouldSpawn

      public boolean shouldSpawn()
      Determines if a treasure hunt should spawn based on current time and scheduler configuration. Compares the current day and time with the configured schedule, accounting for daily spawns. Logs debug information about time comparisons.
      Returns:
      True if the treasure should spawn now, false otherwise
    • spawn

      public boolean spawn()
      Attempts to spawn a treasure hunt based on the scheduler configuration. Handles both fixed location and random location spawning. For random locations, uses asynchronous task to wait for location generation. Validates that no hunt is already active for the same treasure type.
      Returns:
      True if the treasure hunt was successfully initiated, false otherwise