Class MonsterExperience

java.lang.Object
de.Keyle.MyPet.api.skill.experience.MonsterExperience

public class MonsterExperience extends Object
Represents the experience value (or range) awarded to a pet when a specific mob type is killed.

Each instance defines a minimum and maximum experience amount for a single mob identifier. When a pet earns experience from a kill, getRandomExp() returns a uniformly distributed random value within that range (or the exact value if min equals max).

The class maintains two static registries:

Resolution order when looking up an entity's experience reward (via getMonsterExperience(Entity)):

  1. MonsterExperienceHook plugins (e.g. MythicMobs)
  2. Custom mob name entries in CUSTOM_MOB_EXP
  3. Vanilla type entries in mobExp
  4. UNKNOWN (0 experience) as a final fallback
  • Field Details

    • mobExp

      public static final Map<String,MonsterExperience> mobExp
      Default experience values for vanilla entity types, keyed by EntityType.name(). Thread-safe: kill events may read it from any region thread while a reload replaces entries.
    • CUSTOM_MOB_EXP

      public static final Map<String,MonsterExperience> CUSTOM_MOB_EXP
      Custom experience entries for named mobs, keyed by the mob's custom display name. Thread-safe: kill events may read it from any region thread while a reload replaces entries. To swap in a whole new table without a window where configured mobs are missing, use replaceCustomExperience(Map) instead of clear() followed by put.
    • UNKNOWN

      public static final MonsterExperience UNKNOWN
      Fallback experience entry used when no mapping exists for a given entity. Always 0 XP.
    • PLUGIN_CONFIG_PATTERN

      public static final Pattern PLUGIN_CONFIG_PATTERN
      Pattern matching plugin-config-style custom names (e.g. [MythicMobs]=BossName).
  • Constructor Details

    • MonsterExperience

      public MonsterExperience(double min, double max, String identifier)
      Creates a monster experience entry with a random range.

      If max < min, the values are swapped internally so that getRandomExp() always produces a value in the correct range.

      Parameters:
      min - the minimum experience awarded
      max - the maximum experience awarded
      identifier - the mob identifier (typically the EntityType name or custom name)
    • MonsterExperience

      public MonsterExperience(double exp, String identifier)
      Creates a monster experience entry with a fixed (non-random) value.
      Parameters:
      exp - the exact experience awarded on kill
      identifier - the mob identifier
  • Method Details

    • addCustomExperience

      public static void addCustomExperience(MonsterExperience experience)
      Registers a custom mob experience entry, keyed by the entry's identifier.
      Parameters:
      experience - the experience entry to register
    • replaceCustomExperience

      public static void replaceCustomExperience(Map<String,MonsterExperience> replacement)
      Replaces the whole custom experience table with the given entries.

      Unlike CUSTOM_MOB_EXP.clear() followed by repeated addCustomExperience(de.Keyle.MyPet.api.skill.experience.MonsterExperience) calls, readers never observe an empty or half-filled table: every key present both before and after the call keeps resolving (to the old entry, then to the new one), and only keys absent from replacement are removed, after the new entries are in place.

      Parameters:
      replacement - the complete new table, keyed by custom name; copied, not retained
    • getMonsterExperience

      public static MonsterExperience getMonsterExperience(Entity entity)
      Resolves the experience entry for a specific entity instance.

      Checks plugin hooks first, then custom-name entries, then vanilla type entries, falling back to UNKNOWN if no match is found.

      Parameters:
      entity - the killed entity
      Returns:
      the matching experience entry (never null)
    • getMonsterExperience

      public static MonsterExperience getMonsterExperience(EntityType type)
      Resolves the experience entry for a Bukkit entity type (vanilla mobs only).
      Parameters:
      type - the entity type
      Returns:
      the matching experience entry, or UNKNOWN if none is registered
    • getMonsterExperience

      public static MonsterExperience getMonsterExperience(String identifier)
      Resolves the experience entry by raw string identifier, checking custom entries first.
      Parameters:
      identifier - the mob identifier (entity type name or custom name)
      Returns:
      the matching experience entry, or UNKNOWN if none is registered
    • getRandomExp

      public double getRandomExp()
      Returns a random experience value uniformly distributed between min and max.

      If min equals max, returns that exact value. The result is truncated to two decimal places.

      Returns:
      a value drawn between the lower and upper bounds
    • setMin

      public void setMin(double min)
      Sets the minimum experience. If the new minimum exceeds the current maximum, the maximum is raised to match.
      Parameters:
      min - the lower bound
    • setMax

      public void setMax(double max)
      Sets the maximum experience. If the new maximum is below the current minimum, the minimum is lowered to match.
      Parameters:
      max - the upper bound
    • setExp

      public void setExp(double exp)
      Sets both min and max to the same value, making this a fixed-experience entry.
      Parameters:
      exp - the fixed amount to award, used as both bounds
    • getMin

      public double getMin()
      Smallest experience this mob can award.
      Returns:
      the lower bound
    • getMax

      public double getMax()
      Largest experience this mob can award.
      Returns:
      the upper bound
    • getIdentifier

      public String getIdentifier()
      The mob type this experience value applies to.
      Returns:
      the Bukkit entity type name