Class Treasure

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

public class Treasure extends Object
Represents a treasure instance in the world. This class manages the physical treasure entity, including spawning, interaction, reward distribution, and treasure keeper management. Each Treasure instance is associated with a Hunt and contains all the logic for treasure behavior, player interactions, and reward systems.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addDamageGiven(org.bukkit.entity.Player p, double damage)
    Records damage dealt by a player to treasure keepers.
    void
    addParticipant(org.bukkit.entity.Player p)
    Adds a player to the list of treasure hunt participants.
    boolean
    Checks if the treasure has already applied debuff effects.
    void
    announceWinner(org.bukkit.entity.Player k)
    Announces a specific player as a treasure hunt winner.
    void
    awardPrize(org.bukkit.entity.Player p)
    Awards all configured prizes to a specific player.
    void
    Distributes all configured rewards to eligible players.
    void
    awardPrizesToTop(int topPlayers)
    Awards prizes to the top participating players based on damage dealt.
    boolean
    Checks if the treasure can be opened by players.
    static void
    Runs on startup and cleans up the world of all MysticTreasure related things Only thing not covered by any cleanup is the treasure block -- in case of a hard crash the block will stay in the world
    void
    Removes all treasure keeper entities from the world.
    void
    Removes all players from the participants list.
    void
    Creates and initializes the treasure in the world.
    void
    Activates continuous particle and visual effects around the treasure.
    void
    Triggers a flare effect to mark the treasure location.
    int
    Returns the current number of clicks the treasure has received.
    double
    getDamageGiven(org.bukkit.entity.Player p)
    Gets the total damage dealt by a specific player to treasure keepers.
    Returns the hunt instance that owns this treasure.
    org.bukkit.Location
    Returns the location where this treasure is positioned in the world.
    ArrayList<org.bukkit.entity.Player>
    Returns all players who have participated in this treasure hunt.
    Returns the names of all participating players as strings.
    static ArrayList<org.bukkit.entity.Player>
    Gets all players currently near the specified treasure.
    org.bukkit.entity.Player
    Gets the player who dealt the most damage to treasure keepers.
    ArrayList<org.bukkit.entity.Player>
    Returns the list of players who have already received command rewards.
    ArrayList<org.bukkit.entity.Entity>
    Returns a list of all remaining living treasure keeper entities.
    org.bukkit.inventory.Inventory
    Returns the inventory containing the treasure's item rewards.
    Returns a list of player UUIDs sorted by damage dealt to treasure keepers.
    static Treasure
    getTreasure(org.bukkit.Location loc)
    Retrieves the treasure instance located at the specified position.
    Returns the treasure configuration data for this treasure.
    getTreasureKeeper(org.bukkit.entity.LivingEntity e)
    Gets the treasure keeper configuration associated with a specific entity.
    Gets the Xth highest damage dealer and their damage amount.
    boolean
    Checks if the treasure keeper mobs have been spawned.
    void
    Creates and displays holographic text above the treasure.
    void
    Increments the click counter for this treasure.
    boolean
    Checks if this treasure is currently active in the world.
    boolean
    Checks if the treasure is currently locked and inaccessible.
    static boolean
    isNearTreasure(org.bukkit.entity.Player p)
    Checks if the specified player is near any active treasure.
    static boolean
    isTreasure(org.bukkit.Location loc)
    Checks if the specified location contains an active treasure.
    boolean
    isTreasureKeeper(org.bukkit.entity.LivingEntity e)
    Checks if the specified entity is a treasure keeper for this treasure.
    boolean
    Checks if all treasure keeper mobs have been defeated.
    boolean
    receivedCommandRewards(org.bukkit.entity.Player p)
    Checks if the specified player has already received command rewards.
    int
    Returns the count of remaining living treasure keepers.
    void
    remove(boolean runEffects)
    Completely removes the treasure from the world and performs cleanup.
    static void
    Removes all active treasures from all worlds.
    void
    runCommandPrizes(org.bukkit.entity.Player p)
    Executes command-based rewards for the specified player.
    void
    Spawns all configured treasure keeper guardian entities.
    boolean
    Checks if enough time has passed before the treasure can be picked up.
    void
    Unlocks the treasure, making it accessible to players.
    boolean
    Checks if any treasure keepers have taken damage from players.

    Methods inherited from class java.lang.Object

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

    • alreadyDebuffed

      public boolean alreadyDebuffed()
      Checks if the treasure has already applied debuff effects. This method determines if debuff effects (such as negative potion effects) have been applied to players, preventing duplicate applications.
      Returns:
      true if debuff effects have already been applied, false otherwise
    • getCurrentClicks

      public int getCurrentClicks()
      Returns the current number of clicks the treasure has received. This tracks player interactions with the treasure, which may be required to reach a certain threshold before the treasure can be opened.
      Returns:
      the current click count on this treasure
    • incrementCurrentClicks

      public void incrementCurrentClicks()
      Increments the click counter for this treasure. This method is called each time a player successfully interacts with the treasure, tracking progress toward any required click threshold.
    • receivedCommandRewards

      public boolean receivedCommandRewards(org.bukkit.entity.Player p)
      Checks if the specified player has already received command rewards. This method prevents duplicate execution of command rewards for the same player during a single treasure hunt session.
      Parameters:
      p - the player to check for received rewards
      Returns:
      true if the player has already received command rewards, false otherwise
    • getSortedPlayersByDamage

      public List<UUID> getSortedPlayersByDamage()
      Returns a list of player UUIDs sorted by damage dealt to treasure keepers. This method sorts all participants by their damage contribution in descending order, useful for determining rewards based on participation level.
      Returns:
      a List of UUIDs ordered by damage dealt (highest first)
    • getReceivedCommandRewards

      public ArrayList<org.bukkit.entity.Player> getReceivedCommandRewards()
      Returns the list of players who have already received command rewards. This method provides access to the collection of players who have been awarded command-based rewards to prevent duplicate distributions.
      Returns:
      an ArrayList of Players who have received command rewards
    • getRewardInventory

      public org.bukkit.inventory.Inventory getRewardInventory()
      Returns the inventory containing the treasure's item rewards. This inventory is populated during treasure setup and contains all configured item rewards that will be distributed to successful players.
      Returns:
      the Inventory containing item rewards for this treasure
    • getTreasureData

      public TreasureData getTreasureData()
      Returns the treasure configuration data for this treasure. The TreasureData contains all settings from the treasure.yml file including spawn behavior, rewards, effects, and keeper configurations.
      Returns:
      the TreasureData configuration object for this treasure
    • getLocation

      public org.bukkit.Location getLocation()
      Returns the location where this treasure is positioned in the world. This location represents the exact coordinates where the treasure block or entity has been placed.
      Returns:
      the Location of this treasure in the world
    • haveTheMobsSpawned

      public boolean haveTheMobsSpawned()
      Checks if the treasure keeper mobs have been spawned. This method indicates whether the guardian creatures protecting the treasure have been generated and are active in the world.
      Returns:
      true if treasure keeper mobs have spawned, false otherwise
    • isActive

      public boolean isActive()
      Checks if this treasure is currently active in the world. An active treasure has been spawned, is visible to players, and can be interacted with. Inactive treasures have been removed or never spawned.
      Returns:
      true if the treasure is active, false otherwise
    • getDamageGiven

      public double getDamageGiven(org.bukkit.entity.Player p)
      Gets the total damage dealt by a specific player to treasure keepers. This method tracks individual player contributions during combat phases, which may be used for reward distribution calculations.
      Parameters:
      p - the player whose damage total to retrieve
      Returns:
      the total damage dealt by the player as a double value
    • addDamageGiven

      public void addDamageGiven(org.bukkit.entity.Player p, double damage)
      Records damage dealt by a player to treasure keepers. This method accumulates damage values for tracking player participation and contribution levels during treasure keeper combat.
      Parameters:
      p - the player who dealt the damage
      damage - the amount of damage dealt
    • wereTreasureKeepersDamaged

      public boolean wereTreasureKeepersDamaged()
      Checks if any treasure keepers have taken damage from players. This method determines if combat has begun with the treasure guardians, which may trigger various game mechanics or unlock conditions.
      Returns:
      true if treasure keepers have been damaged, false otherwise
    • getXthMostDamage

      public Map.Entry<UUID,Double> getXthMostDamage(int x)
      Gets the Xth highest damage dealer and their damage amount. This method returns a map entry containing the UUID of the player and their damage total for a specific ranking position.
      Parameters:
      x - the ranking position to retrieve (1 for highest, 2 for second, etc.)
      Returns:
      a Map.Entry containing the player UUID and damage amount, or null if not found
    • isLocked

      public boolean isLocked()
      Checks if the treasure is currently locked and inaccessible. A locked treasure cannot be opened by players and typically requires certain conditions to be met (like defeating all keepers) before unlocking.
      Returns:
      true if the treasure is locked, false if it can be accessed
    • unlock

      public void unlock()
      Unlocks the treasure, making it accessible to players. This method is typically called when all unlock conditions have been met, such as defeating all treasure keepers or waiting for a time delay.
    • getPlayerWithMostDamage

      @Nullable public org.bukkit.entity.Player getPlayerWithMostDamage()
      Gets the player who dealt the most damage to treasure keepers. This method identifies the top contributor during combat phases, which may be used for special rewards or recognition.
      Returns:
      the Player who dealt the most damage, or null if no damage was recorded
    • getParticipants

      public ArrayList<org.bukkit.entity.Player> getParticipants()
      Returns all players who have participated in this treasure hunt. Participants are typically players who have engaged with the treasure or its keepers in some meaningful way.
      Returns:
      an ArrayList of all participating Players
    • getParticipantsNames

      public ArrayList<String> getParticipantsNames()
      Returns the names of all participating players as strings. This method provides a convenient way to get participant names for display purposes in messages or administrative interfaces.
      Returns:
      an ArrayList of participant names as Strings
    • timePassedBeforePickup

      public boolean timePassedBeforePickup()
      Checks if enough time has passed before the treasure can be picked up. Some treasures have a minimum time delay before they become available to prevent immediate claiming after spawn.
      Returns:
      true if the pickup delay time has elapsed, false otherwise
    • addParticipant

      public void addParticipant(org.bukkit.entity.Player p)
      Adds a player to the list of treasure hunt participants. This method registers a player as having engaged with the treasure, typically called when they interact with keepers or the treasure itself.
      Parameters:
      p - the Player to add to the participants list
    • clearParticipants

      public void clearParticipants()
      Removes all players from the participants list. This method clears the participant registry, typically used during treasure cleanup or reset operations.
    • isTreasure

      public static boolean isTreasure(org.bukkit.Location loc)
      Checks if the specified location contains an active treasure. This static method examines the given location to determine if any treasure is currently positioned there.
      Parameters:
      loc - the location to check for treasure presence
      Returns:
      true if a treasure exists at the location, false otherwise
    • getTreasureKeeper

      public TreasureKeeper getTreasureKeeper(org.bukkit.entity.LivingEntity e)
      Gets the treasure keeper configuration associated with a specific entity. This method maps spawned keeper entities back to their configuration data for access to behavior settings and properties.
      Parameters:
      e - the LivingEntity to check for keeper association
      Returns:
      the TreasureKeeper configuration, or null if entity is not a keeper
    • getTreasure

      public static Treasure getTreasure(org.bukkit.Location loc)
      Retrieves the treasure instance located at the specified position. This static method searches all active treasures and returns the one positioned at the given location coordinates.
      Parameters:
      loc - the location to search for a treasure
      Returns:
      the Treasure at the location, or null if none exists there
    • mobsCleared

      public boolean mobsCleared()
      Checks if all treasure keeper mobs have been defeated. This method determines if the combat phase is complete by verifying that no living keeper entities remain active.
      Returns:
      true if all keepers are defeated, false if any remain alive
    • getRemainingMobs

      public ArrayList<org.bukkit.entity.Entity> getRemainingMobs()
      Returns a list of all remaining living treasure keeper entities. This method filters the spawned keeper list to return only those entities that are still alive and active in the world.
      Returns:
      an ArrayList of living keeper Entities
    • remainingMobs

      public int remainingMobs()
      Returns the count of remaining living treasure keepers. This method provides a quick way to check how many guardian creatures are still protecting the treasure.
      Returns:
      the number of remaining alive treasure keepers
    • isTreasureKeeper

      public boolean isTreasureKeeper(org.bukkit.entity.LivingEntity e)
      Checks if the specified entity is a treasure keeper for this treasure. This method determines if a given living entity is one of the guardian creatures spawned to protect this treasure.
      Parameters:
      e - the LivingEntity to check for keeper status
      Returns:
      true if the entity is a treasure keeper, false otherwise
    • hologram

      public void hologram()
      Creates and displays holographic text above the treasure. This method generates floating text displays that provide information about the treasure status, requirements, or other relevant details to players.
    • flare

      public void flare()
      Triggers a flare effect to mark the treasure location. This method creates visual effects (particles, sounds, or other indicators) to help players locate the treasure from a distance.
    • enableEffects

      public void enableEffects()
      Activates continuous particle and visual effects around the treasure. This method starts ongoing visual effects that make the treasure more visible and attractive to players, running until the treasure is removed.
    • getHunt

      public Hunt getHunt()
      Returns the hunt instance that owns this treasure. This method provides access to the parent hunt object for retrieving hunt-specific information like duration, start time, and configuration.
      Returns:
      the Hunt instance that created this treasure
    • spawnTreasureKeepers

      public void spawnTreasureKeepers()
      Spawns all configured treasure keeper guardian entities. This method creates and positions the protective creatures around the treasure based on the keeper configurations defined in the treasure data.
    • canBeOpened

      public boolean canBeOpened()
      Checks if the treasure can be opened by players. This method evaluates all conditions required for treasure access including lock status, keeper defeats, time delays, and other configured requirements.
      Returns:
      true if the treasure can be opened, false if conditions are not met
    • create

      public void create()
      Creates and initializes the treasure in the world. This method orchestrates the complete treasure creation process including spawning, effect activation, keeper generation, and announcement to players.
    • getPlayersNearTreasure

      public static ArrayList<org.bukkit.entity.Player> getPlayersNearTreasure(Treasure t)
      Gets all players currently near the specified treasure. This static method finds players within interaction range of the treasure, useful for applying effects or determining who can access the treasure.
      Parameters:
      t - the treasure to check for nearby players
      Returns:
      an ArrayList of Players within range of the treasure
    • isNearTreasure

      public static boolean isNearTreasure(org.bukkit.entity.Player p)
      Checks if the specified player is near any active treasure. This static method determines if a player is within interaction distance of any currently spawned treasure in the game world.
      Parameters:
      p - the player to check for treasure proximity
      Returns:
      true if the player is near a treasure, false otherwise
    • runCommandPrizes

      public void runCommandPrizes(org.bukkit.entity.Player p)
      Executes command-based rewards for the specified player. This method runs all configured console commands as rewards for the player, typically called when they successfully claim or interact with the treasure.
      Parameters:
      p - the player to award command rewards to
    • awardPrizesToTop

      public void awardPrizesToTop(int topPlayers)
      Awards prizes to the top participating players based on damage dealt. This method distributes rewards to the highest-contributing players when the treasure is configured for top-player-only rewards.
      Parameters:
      topPlayers - the number of top players to reward
    • awardPrizes

      public void awardPrizes()
      Distributes all configured rewards to eligible players. This method handles the complete reward distribution process including item rewards, command execution, and notification of successful claims.
    • awardPrize

      public void awardPrize(org.bukkit.entity.Player p)
      Awards all configured prizes to a specific player. This method gives both item and command rewards to the specified player, typically called when they successfully claim the treasure.
      Parameters:
      p - the player to award prizes to
    • removeAll

      public static void removeAll()
      Removes all active treasures from all worlds. This static method performs a complete cleanup of all treasure instances, typically used during server shutdown or plugin reloading.
    • clearMobs

      public void clearMobs()
      Removes all treasure keeper entities from the world. This method despawns and cleans up all guardian creatures associated with this treasure, freeing up server resources.
    • remove

      public void remove(boolean runEffects)
      Completely removes the treasure from the world and performs cleanup. This method handles the full treasure removal process including entity cleanup, block restoration, effect stopping, and hunt deactivation.
    • announceWinner

      public void announceWinner(org.bukkit.entity.Player k)
      Announces a specific player as a treasure hunt winner. This method broadcasts congratulatory messages about the specified player's successful treasure claim to all online players.
      Parameters:
      k - the player to announce as a winner
    • cleanup

      public static void cleanup()
      Runs on startup and cleans up the world of all MysticTreasure related things Only thing not covered by any cleanup is the treasure block -- in case of a hard crash the block will stay in the world