Package com.Moshu.TreasureHunt
Class TreasureScheduler
java.lang.Object
com.Moshu.TreasureHunt.TreasureScheduler
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 -
Method Summary
Modifier and TypeMethodDescriptiongetData()
Gets the treasure data configuration for this scheduler.getDay()
Gets the configured day of the week for this scheduler.Gets the encoded coordinates string for this scheduler.getId()
Gets the unique identifier for this scheduler.org.bukkit.Location
Parses the encoded coordinates and world to create a Location object.getTime()
Gets the configured time for this scheduler.getWorld()
Gets the configured world name for this scheduler.boolean
Checks if this scheduler is currently enabled.void
setData
(TreasureData data) 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
spawn()
Attempts to spawn a treasure hunt based on the scheduler configuration.
-
Constructor Details
-
TreasureScheduler
public TreasureScheduler()Default constructor for TreasureScheduler. Creates a new scheduler instance with default values.
-
-
Method Details
-
setId
Sets the unique identifier for this scheduler.- Parameters:
id
- The unique identifier string for the scheduler
-
setDay
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
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
Sets the world where the treasure hunt should spawn.- Parameters:
world
- The name of the world for the treasure hunt
-
setEncodedCoords
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
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
Gets the configured day of the week for this scheduler.- Returns:
- The day string (e.g., "monday", "daily")
-
getTime
Gets the configured time for this scheduler.- Returns:
- The time string in HH:MM format
-
getWorld
Gets the configured world name for this scheduler.- Returns:
- The world name string
-
getEncodedCoords
Gets the encoded coordinates string for this scheduler.- Returns:
- The encoded coordinates string or "random"
-
getData
Gets the treasure data configuration for this scheduler.- Returns:
- The TreasureData object
-
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
-