Class MonsterExperience
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:
mobExp-- default experience values for vanilla entity types, populated in a static initializer block.CUSTOM_MOB_EXP-- experience values for custom-named mobs, populated at runtime viaaddCustomExperience(MonsterExperience).
Resolution order when looking up an entity's experience reward (via
getMonsterExperience(Entity)):
MonsterExperienceHookplugins (e.g. MythicMobs)- Custom mob name entries in
CUSTOM_MOB_EXP - Vanilla type entries in
mobExp UNKNOWN(0 experience) as a final fallback
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<String, MonsterExperience> Custom experience entries for named mobs, keyed by the mob's custom display name.static final Map<String, MonsterExperience> Default experience values for vanilla entity types, keyed byEntityType.name().static final PatternPattern matching plugin-config-style custom names (e.g.static final MonsterExperienceFallback experience entry used when no mapping exists for a given entity. -
Constructor Summary
ConstructorsConstructorDescriptionMonsterExperience(double min, double max, String identifier) Creates a monster experience entry with a random range.MonsterExperience(double exp, String identifier) Creates a monster experience entry with a fixed (non-random) value. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCustomExperience(MonsterExperience experience) Registers a custom mob experience entry, keyed by the entry's identifier.The mob type this experience value applies to.doublegetMax()Largest experience this mob can award.doublegetMin()Smallest experience this mob can award.static MonsterExperiencegetMonsterExperience(String identifier) Resolves the experience entry by raw string identifier, checking custom entries first.static MonsterExperiencegetMonsterExperience(Entity entity) Resolves the experience entry for a specific entity instance.static MonsterExperienceResolves the experience entry for a Bukkit entity type (vanilla mobs only).doubleReturns a random experience value uniformly distributed betweenminandmax.static voidreplaceCustomExperience(Map<String, MonsterExperience> replacement) Replaces the whole custom experience table with the given entries.voidsetExp(double exp) Sets both min and max to the same value, making this a fixed-experience entry.voidsetMax(double max) Sets the maximum experience.voidsetMin(double min) Sets the minimum experience.
-
Field Details
-
mobExp
Default experience values for vanilla entity types, keyed byEntityType.name(). Thread-safe: kill events may read it from any region thread while a reload replaces entries. -
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, usereplaceCustomExperience(Map)instead ofclear()followed byput. -
UNKNOWN
Fallback experience entry used when no mapping exists for a given entity. Always 0 XP. -
PLUGIN_CONFIG_PATTERN
Pattern matching plugin-config-style custom names (e.g.[MythicMobs]=BossName).
-
-
Constructor Details
-
MonsterExperience
Creates a monster experience entry with a random range.If
max < min, the values are swapped internally so thatgetRandomExp()always produces a value in the correct range.- Parameters:
min- the minimum experience awardedmax- the maximum experience awardedidentifier- the mob identifier (typically theEntityTypename or custom name)
-
MonsterExperience
Creates a monster experience entry with a fixed (non-random) value.- Parameters:
exp- the exact experience awarded on killidentifier- the mob identifier
-
-
Method Details
-
addCustomExperience
Registers a custom mob experience entry, keyed by the entry's identifier.- Parameters:
experience- the experience entry to register
-
replaceCustomExperience
Replaces the whole custom experience table with the given entries.Unlike
CUSTOM_MOB_EXP.clear()followed by repeatedaddCustomExperience(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 fromreplacementare removed, after the new entries are in place.- Parameters:
replacement- the complete new table, keyed by custom name; copied, not retained
-
getMonsterExperience
Resolves the experience entry for a specific entity instance.Checks plugin hooks first, then custom-name entries, then vanilla type entries, falling back to
UNKNOWNif no match is found.- Parameters:
entity- the killed entity- Returns:
- the matching experience entry (never
null)
-
getMonsterExperience
Resolves the experience entry for a Bukkit entity type (vanilla mobs only).- Parameters:
type- the entity type- Returns:
- the matching experience entry, or
UNKNOWNif none is registered
-
getMonsterExperience
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
UNKNOWNif none is registered
-
getRandomExp
public double getRandomExp()Returns a random experience value uniformly distributed betweenminandmax.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
The mob type this experience value applies to.- Returns:
- the Bukkit entity type name
-