Class PlayerData

java.lang.Object
com.sucy.skill.api.player.PlayerData

public class PlayerData extends Object
Represents one account for a player which can contain one class from each group and the skills in each of those classes. You should not instantiate this class yourself and instead get it from the SkillAPI static methods.

In order to get a player's data, use "SkillAPI.getPlayerData(...)". Do NOT try to instantaite your own PlayerData object.

  • Field Details

    • attributes

      public final HashMap<String,Integer> attributes
    • attribPoints

      public int attribPoints
  • Method Details

    • getPlayer

      public org.bukkit.entity.Player getPlayer()
      Retrieves the Bukkit player object of the owner
      Returns:
      Bukkit player object of the owner or null if offline
    • getPlayerName

      public String getPlayerName()
      Retrieves the name of the owner
      Returns:
      name of the owner
    • getUUID

      public UUID getUUID()
    • getSkillBar

      public PlayerSkillBar getSkillBar()
      Retrieves the skill bar data for the owner
      Returns:
      skill bar data of the owner
    • getCastBars

      public PlayerCastBars getCastBars()
      Returns:
      cast bars data for the player
    • getComboData

      public PlayerCombos getComboData()
      Returns the data for the player's combos
      Returns:
      combo data for the player
    • getExtraData

      public mc.promcteam.engine.mccore.config.parse.DataSection getExtraData()
      Returns:
      extra data attached to the player's account
    • getEquips

      public PlayerEquips getEquips()
      Returns:
      equipped item data
    • getLastHealth

      public double getLastHealth()
      Returns:
      health during last logout
    • setLastHealth

      public void setLastHealth(double health)
      Used by the API for restoring health - do not use this.
      Parameters:
      health - health logged off with
    • getHungerValue

      public double getHungerValue()
      The hunger value here is not representative of the player's total hunger, rather the amount left of the next hunger point. This is manipulated by attributes were if an attribute says a player has twice as much "hunger" as normal, this will go down by decimals to slow the decay of hunger.
      Returns:
      amount of the next hunger point the player has
    • setHungerValue

      public void setHungerValue(double hungerValue)
      Parameters:
      hungerValue - new hunger value
      See Also:
    • subtractHungerValue

      public int subtractHungerValue(double amount)
    • endInit

      public void endInit()
      Ends the initialization flag for the data. Used by the API to avoid async issues. Do not use this in other plugins.
    • getScheme

      public String getScheme()
      Retrieves the name of the active map menu scheme for the player
      Returns:
      map menu scheme name
    • setScheme

      public void setScheme(String name)
      Sets the active scheme name for the player
      Parameters:
      name - name of the scheme
    • getAttributes

      public HashMap<String,Integer> getAttributes()
      Retrieves a map of all player attribute totals. Modifying the map will not change actual player attributes.
      Returns:
      attribute totals
    • getInvestedAttributes

      public HashMap<String,Integer> getInvestedAttributes()
      Retrieves a map of all attributes the player invested. This doesn't count base attributes from classes or bonus attributes from effects. Modifying the map will not change actual player attributes.
      Returns:
      attribute totals
    • getAttribute

      public int getAttribute(String key)
      Gets the number of attribute points the player has between invested and bonus sources.
      Parameters:
      key - attribute key
      Returns:
      number of total points
    • getInvestedAttribute

      public int getInvestedAttribute(String key)
      Gets the number of attribute points invested in the given attribute
      Parameters:
      key - attribute key
      Returns:
      number of invested points
    • hasAttribute

      public boolean hasAttribute(String key)
      Checks whether the player has any points invested in a given attribute
      Parameters:
      key - attribute key
      Returns:
      true if any points are invested, false otherwise
    • upAttribute

      public boolean upAttribute(String key)
      Invests a point in the attribute if the player has any remaining attribute points. If the player has no remaining points, this will do nothing.
      Parameters:
      key - attribute key
      Returns:
      whether it was successfully upgraded
    • giveAttribute

      public void giveAttribute(String key, int amount)
      Gives the player attribute points without costing attribute points.
      Parameters:
      key - attribute to give points for
      amount - amount to give
    • addStatModifier

      public void addStatModifier(String key, PlayerStatModifier modifier, boolean update)
      Adds stat modifier to the player. These bypass min/max invest amount and cannot be refunded.
      Parameters:
      key - stat key
      modifier - The player stat modifier
      update - calculate player stat immediately and apply to him
    • getStatModifiers

      public List<PlayerStatModifier> getStatModifiers(String key)
      Get all stat modifier from the player.
      Parameters:
      key - stat key
      Returns:
      stat modifier list of the attribute given
    • addAttributeModifier

      public void addAttributeModifier(String key, PlayerAttributeModifier modifier, boolean update)
      Adds attribute modifier to the player. These bypass min/max invest amount and cannot be refunded.
      Parameters:
      key - attribute key
      modifier - The player attribute modifier
      update - calculate player stat immediately and apply to him
    • getAttributeModifiers

      public List<PlayerAttributeModifier> getAttributeModifiers(String key)
      Get all attribute modifier from the player.
      Parameters:
      key - attribute key
      Returns:
      attribute modifier list of the attribute given
    • refundAttribute

      public boolean refundAttribute(String key)
      Refunds an attribute point from the given attribute if there are any points invested in it. If there are none, this will do nothing.
      Parameters:
      key - attribute key
    • refundAttributes

      public void refundAttributes(String key)
      Refunds all spent attribute points for a specific attribute
    • refundAttributes

      public void refundAttributes()
      Refunds all spent attribute points
    • getAttributePoints

      public int getAttributePoints()
      Retrieves the current number of attribute points the player has
      Returns:
      attribute point total
    • giveAttribPoints

      public void giveAttribPoints(int amount)
      Gives the player attribute points
      Parameters:
      amount - amount of attribute points
    • setAttribPoints

      public void setAttribPoints(int amount)
      Sets the current amount of attribute points
      Parameters:
      amount - amount of points to have
    • scaleStat

      public double scaleStat(String stat, double baseValue)
      Scales a stat value using the player's attributes
      Parameters:
      stat - stat key
      baseValue - the default value come with vanilla Minecraft, Only needed for custom stats and Speed
      Returns:
      modified value
    • scaleStat

      public double scaleStat(String stat, double defaultValue, double min, double max)
      Scales a stat value using the player's attributes
      Parameters:
      stat - stat key
      defaultValue - the default value come with vanilla Minecraft, Only needed for custom stats and Speed
      min - min value
      max - max value
      Returns:
      modified value
    • scaleDynamic

      public double scaleDynamic(EffectComponent component, String key, double value)
      Scales a dynamic skill's value using global modifiers
      Parameters:
      component - component holding the value
      key - key of the value
      value - unmodified value
      Returns:
      the modified value
    • openAttributeMenu

      public boolean openAttributeMenu()
      Opens the attribute menu for the player
      Returns:
      true if successfully opened, false if conditions weren't met
    • getAttributeData

      public HashMap<String,Integer> getAttributeData()
      Retrieves the player's attribute data. Modifying this will modify the player's actual data.
      Returns:
      the player's attribute data
    • hasSkill

      public boolean hasSkill(String name)
      Checks if the owner has a skill by name. This is not case-sensitive and does not check to see if the skill is unlocked. It only checks if the skill is available to upgrade/use.
      Parameters:
      name - name of the skill
      Returns:
      true if has the skill, false otherwise
    • getSkill

      public PlayerSkill getSkill(String name)
      Retrieves a skill of the owner by name. This is not case-sensitive.
      Parameters:
      name - name of the skill
      Returns:
      data for the skill or null if the player doesn't have the skill
    • getInvestedSkillPoints

      public int getInvestedSkillPoints()
    • getSkills

      public Collection<PlayerSkill> getSkills()
      Retrieves all of the skill data the player has. Modifying this collection will not modify the player's owned skills but modifying one of the elements will change that element's data for the player.
      Returns:
      collection of skill data for the owner
    • getExternallyAddedSkills

      public Set<PlayerData.ExternallyAddedSkill> getExternallyAddedSkills()
    • getSkillLevel

      public int getSkillLevel(String name)
      Retrieves the level of a skill for the owner. This is not case-sensitive.
      Parameters:
      name - name of the skill
      Returns:
      level of the skill or 0 if not found
    • giveSkill

      public void giveSkill(Skill skill)
      Gives the player a skill outside of the normal class skills. This skill will not show up in a skill tree.
      Parameters:
      skill - skill to give the player
    • giveSkill

      public void giveSkill(Skill skill, PlayerClass parent)
      Gives the player a skill using the class data as a parent. This skill will not show up in a skill tree.
      Parameters:
      skill - skill to give the player
      parent - parent class data
    • addSkill

      public void addSkill(Skill skill, PlayerClass parent)
    • addSkillExternally

      public void addSkillExternally(Skill skill, PlayerClass parent, org.bukkit.NamespacedKey namespacedKey, int level)
    • removeSkillExternally

      public void removeSkillExternally(Skill skill, org.bukkit.NamespacedKey namespacedKey)
    • autoLevel

      public void autoLevel()
      Attempts to auto-level any skills that are able to do so
    • upgradeSkill

      public boolean upgradeSkill(Skill skill)
      Upgrades a skill owned by the player. The player must own the skill, have enough skill points, meet the level and skill requirements, and not have maxed out the skill already in order to upgrade the skill. This will consume the skill point cost while upgrading the skill.
      Parameters:
      skill - skill to upgrade
      Returns:
      true if successfully was upgraded, false otherwise
    • forceUpSkill

      public void forceUpSkill(PlayerSkill skill)
      Forcefully upgrades a skill, not letting other plugins cancel it and ignoring any requirements to do so
      Parameters:
      skill - skill to forcefully upgrade
    • forceUpSkill

      public void forceUpSkill(PlayerSkill skill, int amount)
    • downgradeSkill

      public boolean downgradeSkill(Skill skill)
      Downgrades a skill owned by the player. The player must own the skill and it must not currently be level 0 for the player to downgrade the skill. This will refund the skill point cost when downgrading the skill.
      Parameters:
      skill - skill to downgrade
      Returns:
      true if successfully downgraded, false otherwise
    • forceDownSkill

      public void forceDownSkill(PlayerSkill skill)
      Forcefully downgrades a skill, not letting other plugins stop it and ignoring any skill requirements to do so.
      Parameters:
      skill - skill to forcefully downgrade
    • forceDownSkill

      public void forceDownSkill(PlayerSkill skill, int amount)
    • refundSkill

      public void refundSkill(PlayerSkill skill)
      Refunds a skill for the player, resetting it down to level 0 and giving back any invested skill points.
      Parameters:
      skill - skill to refund
    • refundSkills

      public void refundSkills()
      Refunds all skills for the player
    • showSkills

      public void showSkills()
      Shows the skill tree for the player. If the player has multiple trees, this will show the list of skill trees they can view.
    • showDetails

      public boolean showDetails(org.bukkit.entity.Player player)
      Shows the class details for the player
      Parameters:
      player - player to show to
      Returns:
      true if shown, false if nothing to show
    • showProfession

      public boolean showProfession(org.bukkit.entity.Player player)
      Shows profession options of the first class group available
      Parameters:
      player - player to show profession options for
      Returns:
      true if shown profession options, false if none available
    • showSkills

      public boolean showSkills(org.bukkit.entity.Player player)
      Shows the skill tree for the player. If the player has multiple trees, this will show the list of skill trees they can view.
      Parameters:
      player - player to show the skill tree for
      Returns:
      true if able to show the player, false otherwise
    • showSkills

      public boolean showSkills(org.bukkit.entity.Player player, PlayerClass playerClass)
      Shows the skill tree to the player for the given class
      Parameters:
      player - player to show
      playerClass - class to look for
      Returns:
      true if succeeded, false otherwise
    • getShownClassName

      public String getShownClassName()
      Retrieves the name of the class shown in the skill tree
      Returns:
      class name
    • hasClass

      public boolean hasClass()
      Checks whether the player has as least one class they have professed as.
      Returns:
      true if professed, false otherwise
    • hasClass

      public boolean hasClass(String group)
      Checks whether a player has a class within the given group
      Parameters:
      group - class group to check
      Returns:
      true if has a class in the group, false otherwise
    • getClasses

      public Collection<PlayerClass> getClasses()
      Retrieves the collection of the data for classes the player has professed as.
      Returns:
      collection of the data for professed classes
    • getClass

      public PlayerClass getClass(String group)
      Retrieves the data of a class the player professed as by group. This is case-sensitive.
      Parameters:
      group - group to get the profession for
      Returns:
      professed class data or null if not professed for the group
    • getMainClass

      @Nullable public @Nullable PlayerClass getMainClass()
      Retrieves the data of the professed class under the main class group. The "main" group is determined by the setting in the config.
      Returns:
      main professed class data or null if not professed for the main group
    • setClass

      public PlayerClass setClass(RPGClass previous, RPGClass rpgClass, boolean reset)
      Sets the professed class for the player for the corresponding group. This will not save any skills, experience, or levels of the previous class if there was any. The new class will start at level 1 with 0 experience.
      Parameters:
      rpgClass - class to assign to the player
      Returns:
      the player-specific data for the new class
    • isExactClass

      public boolean isExactClass(RPGClass rpgClass)
      Checks whether the player is professed as the class without checking child classes.
      Parameters:
      rpgClass - class to check
      Returns:
      true if professed as the specific class, false otherwise
    • isClass

      public boolean isClass(RPGClass rpgClass)
      Checks whether the player is professed as the class or any of its children.
      Parameters:
      rpgClass - class to check
      Returns:
      true if professed as the class or one of its children, false otherwise
    • canProfess

      public boolean canProfess(RPGClass rpgClass)
      Checks whether the player can profess into the given class. This checks to make sure the player is currently professed as the parent of the given class and is high enough of a level to do so.
      Parameters:
      rpgClass - class to check
      Returns:
      true if can profess, false otherwise
    • reset

      public int reset(String group, boolean toSubclass)
      Resets the class data for the owner under the given group. This will remove the profession entirely, leaving no remaining data until the player professes again to a starting class.
      Parameters:
      group - group to reset
      toSubclass - - whether we are professing to a subclass of the previous class
      Returns:
      the number of skill points to be refunded
    • resetAll

      public void resetAll()
      Resets all profession data for the player. This clears all professions the player has, leaving no remaining data until the player professes again to a starting class.
    • resetAttribs

      public void resetAttribs()
      Resets attributes for the player
    • profess

      public boolean profess(RPGClass rpgClass)
      Professes the player into the class if they are able to. This will reset the class data if the group options are set to reset upon profession. Otherwise, all skills, experience, and levels of the current class under the group will be retained and carried over into the new profession.
      Parameters:
      rpgClass - class to profess into
      Returns:
      true if successfully professed, false otherwise
    • giveExp

      public void giveExp(double amount, ExpSource source)
      Gives experience to the player from the given source
      Parameters:
      amount - amount of experience to give
      source - source of the experience
    • giveExp

      public void giveExp(double amount, ExpSource source, boolean message)
      Gives experience to the player from the given source
      Parameters:
      amount - amount of experience to give
      source - source of the experience
      message - whether to show the configured message if enabled
    • loseExp

      public void loseExp(double amount, boolean percent, boolean changeLevel)
      Causes the player to lose experience This will launch a PlayerExperienceLostEvent event before taking the experience.
      Parameters:
      amount - percent of experience to lose
      percent - whether to take the amount as a percentage
    • loseExp

      public void loseExp()
      Causes the player to lose experience as a penalty (generally for dying)
    • giveLevels

      public boolean giveLevels(int amount, ExpSource source)
      Gives levels to the player for all classes matching the experience source
      Parameters:
      amount - amount of levels to give
      source - source of the levels
    • loseLevels

      public void loseLevels(int amount)
      Causes the player to lose levels
    • givePoints

      public void givePoints(int amount, ExpSource source)
      Gives skill points to the player for all classes matching the experience source
      Parameters:
      amount - amount of levels to give
      source - source of the levels
    • updatePlayerStat

      public void updatePlayerStat(org.bukkit.entity.Player player)
      Updates all the stats of a player based on their current attributes This method is very heavy, consume resources and notable by player Checkout other method such as updateWalkSpeed(Player) for a light refresh
      This also does not update the player equipment You will need to call PlayerEquips.update(Player) before this function to update attribute/stats that comes with equipments
    • updateWalkSpeed

      public void updateWalkSpeed(org.bukkit.entity.Player player)
      Updates walk speed of a player based on their current attributes and apply
      Parameters:
      player - the player
    • updateHealth

      public void updateHealth(org.bukkit.entity.Player player)
      Updates health of a player based on their current attributes and apply
      Parameters:
      player - the player
    • getMana

      public double getMana()
      Retrieves the amount of mana the player currently has.
      Returns:
      current player mana
    • setMana

      public void setMana(double amount)
      Sets the player's amount of mana without launching events
      Parameters:
      amount - current mana
    • hasMana

      public boolean hasMana(double amount)
      Checks whether the player has at least the specified amount of mana
      Parameters:
      amount - required mana amount
      Returns:
      true if has the amount of mana, false otherwise
    • getMaxMana

      public double getMaxMana()
      Retrieves the max amount of mana the player can have including bonus mana
      Returns:
      max amount of mana the player can have
    • regenMana

      public void regenMana()
      Regenerates mana for the player based on the regen amounts of professed classes
    • giveMana

      public void giveMana(double amount)
      Gives mana to the player from an unknown source. This will not cause the player's mana to go above their max amount.
      Parameters:
      amount - amount of mana to give
    • giveMana

      public void giveMana(double amount, ManaSource source)
      Gives mana to the player from the given mana source. This will not cause the player's mana to go above the max amount.
      Parameters:
      amount - amount of mana to give
      source - source of the mana
    • useMana

      public void useMana(double amount)
      Takes mana away from the player for an unknown reason. This will not cause the player to fall below 0 mana.
      Parameters:
      amount - amount of mana to take away
    • useMana

      public void useMana(double amount, ManaCost cost)
      Takes mana away from the player for the specified reason. This will not cause the player to fall below 0 mana.
      Parameters:
      amount - amount of mana to take away
      cost - source of the mana cost
    • removeStatModifier

      public void removeStatModifier(UUID uuid, boolean update)
      Remove stat modifier with the exact uuid
      Parameters:
      uuid - The uuid
      update - calculate player stat immediately and apply to him
    • clearStatModifier

      public void clearStatModifier()
      Clear all stat modifier which is not persistent
    • removeAttributeModifier

      public void removeAttributeModifier(UUID uuid, boolean update)
      Remove attribute modifier with the exact uuid
      Parameters:
      uuid - The uuid
      update - calculate player stat immediately and apply to him
    • clearAttributeModifiers

      public void clearAttributeModifiers()
      Clear all attribute modifier which is not persistent
    • clearAllModifiers

      public void clearAllModifiers()
      Clear all of the modifiers including stat modifier and attribute modifier
    • getBoundSkill

      public PlayerSkill getBoundSkill(org.bukkit.Material mat)
      Retrieves a skill the player has bound by material
      Parameters:
      mat - material to get the bind for
      Returns:
      skill bound to the material or null if none are bound
    • getBinds

      public HashMap<org.bukkit.Material,PlayerSkill> getBinds()
      Retrieves the bound data for the player. Modifying this map will modify the bindings the player has.
      Returns:
      the skill binds data for the player
    • isBound

      public boolean isBound(org.bukkit.Material mat)
      Checks whether the material has a skill bound to it
      Parameters:
      mat - material to check
      Returns:
      true if a skill is bound to it, false otherwise
    • bind

      public boolean bind(org.bukkit.Material mat, PlayerSkill skill)
      Binds a skill to a material for the player. The bind will not work if the skill was already bound to the material.
      Parameters:
      mat - material to bind the skill to
      skill - skill to bind to the material
      Returns:
      true if was able to bind the skill, false otherwise
    • clearBind

      public boolean clearBind(org.bukkit.Material mat)
      Clears a skill binding on the material. If there is no binding on the material, this will do nothing.
      Parameters:
      mat - material to clear bindings from
      Returns:
      true if a binding was cleared, false otherwise
    • clearBinds

      public void clearBinds(Skill skill)
      Clears the skill binding for the given skill. This will remove the bindings on all materials involving the skill.
      Parameters:
      skill - skill to unbind
    • clearAllBinds

      public void clearAllBinds()
      Clears all binds the player currently has
    • record

      public void record(org.bukkit.entity.Player player)
      Records any data to save with class data
      Parameters:
      player - player to record for
    • updateScoreboard

      public void updateScoreboard()
      Updates the scoreboard with the player's current class. This is already done by the API and doesn't need to be done by other plugins.
    • startPassives

      public void startPassives(org.bukkit.entity.Player player)
      Starts passive abilities for the player if they are online. This is already called by the API and shouldn't be called by other plugins.
      Parameters:
      player - player to set the passive skills up for
    • stopPassives

      public void stopPassives(org.bukkit.entity.Player player)
      Stops passive abilities for the player if they are online. This is already called by the API and shouldn't be called by other plugins.
      Parameters:
      player - player to stop the passive skills for
    • cast

      public boolean cast(String skillName)
      Casts a skill by name for the player. In order to cast the skill, the player must be online, have the skill unlocked, have enough mana, have the skill off cooldown, and have a proper target if applicable.
      Parameters:
      skillName - name of the skill ot cast
      Returns:
      true if successfully cast the skill, false otherwise
    • cast

      public boolean cast(PlayerSkill skill)
      Casts a skill for the player. In order to cast the skill, the player must be online, have the skill unlocked, have enough mana, have the skill off cooldown, and have a proper target if applicable.
      Parameters:
      skill - skill to cast
      Returns:
      true if successfully cast the skill, false otherwise
    • check

      public boolean check(PlayerSkill skill, boolean cooldown, boolean mana)
      Checks the cooldown and mana requirements for a skill
      Parameters:
      skill - skill to check for
      cooldown - whether to check cooldowns
      mana - whether to check mana requirements
      Returns:
      true if can use
    • init

      public void init(org.bukkit.entity.Player player)
      Initializes the application of the data for the player
      Parameters:
      player - player to set up for