RPG Leveling API
API for external mods to interact with the RPG Leveling system. Mod authors are welcome to integrate with RPG Leveling — use this API to grant XP, listen for level-ups, read player level, and more. See Share XP with teammates for an example (PartyPro); dependency setup and full reference are below. Simple integration! Import the API classes directly. Just declare the dependency inmanifest.json and the plugin must be installed on the server or same mods folder.
Adding as Dependency
Step 1: Declare Dependency in manifest.json
Add to your plugin’smanifest.json:
Step 2: Import and Use
Just import the API classes directly:Quick Start
Adding Experience
XPSource.ENTITY_KILL— XP from killing entitiesXPSource.COMMAND— XP from admin commands
Experience Gained Events
Modify or cancel XP before it’s awarded.All Available Properties
| Property | Type | Description | Mutable |
|---|---|---|---|
getPlayer() | PlayerRef | Player gaining XP | No |
getXpAmount() | double | Current XP amount | Yes (via setXpAmount()) |
setXpAmount(double) | void | Change XP amount | — |
getSource() | XPSource | Source of XP | No |
isCancelled() | boolean | Check if cancelled | Yes (via setCancelled()) |
setCancelled(boolean) | void | Cancel or allow XP | — |
getSourceContext() | Object | Raw source context (nullable) | No |
getEntityKillContext() | EntityKillContext | Entity kill data (for ENTITY_KILL only) | No |
XPSource Properties
| Property | Type | Description |
|---|---|---|
getName() | String | Source name (e.g., “ENTITY_KILL”, “QUEST”) |
getMetadata() | Object | Optional metadata (nullable) |
equals(Object) | boolean | Compare sources by name |
EntityKillContext Properties (for ENTITY_KILL only)
| Property | Type | Description |
|---|---|---|
getEntityUuid() | UUID | UUID of killed entity |
getEntityLevel() | int | Level of killed entity (0 if unknown) |
hasEntityLevel() | boolean | Whether level is known |
Example — Entity Kill
Example — Custom Source
Level Up Events
React when players level up.| Method | Returns | Description |
|---|---|---|
getPlayer() | PlayerRef | Player who leveled up |
getOldLevel() | int | Level before leveling up |
getNewLevel() | int | Level after leveling up |
getLevelsGained() | int | Number of levels gained |
Getting Player Information
When you only have a UUID (e.g. from a command or async context), use the UUID overload. It uses Holder only and may return incorrect data when Holder is null.Common Use Cases
Party XP Sharing
Quest Rewards
Level-Based Actions
API Methods Reference
Availability & Version
| Method | Returns | Description |
|---|---|---|
get() | RPGLevelingAPI | Get API instance (null if not loaded) |
isAvailable() | boolean | Check if API is available |
getVersion() | String | Get API version (e.g., “0.2.0”) |
Listener Management
| Method | Returns | Description |
|---|---|---|
registerExperienceGainedListener(listener) | void | Register XP gain handler |
unregisterExperienceGainedListener(listener) | boolean | Unregister handler (returns true if was registered) |
isExperienceGainedListenerRegistered(listener) | boolean | Check if handler is registered |
getExperienceGainedListenerCount() | int | Get number of registered handlers |
registerLevelUpListener(listener) | void | Register level up handler |
unregisterLevelUpListener(listener) | boolean | Unregister handler (returns true if was registered) |
isLevelUpListenerRegistered(listener) | boolean | Check if handler is registered |
getLevelUpListenerCount() | int | Get number of registered handlers |
Level reads (player and monster)
Use the API for all level reads so behavior is consistent across the plugin and external mods.| Method | Returns | Description |
|---|---|---|
getPlayerLevelInfo(playerUuid) | PlayerLevelInfo or null | Full level/XP info for a player by UUID (Holder-only; use playerRef+store when you have Store for correct data) |
getPlayerLevelInfo(playerRef, store) | PlayerLevelInfo | Full level/XP info for a player by PlayerRef; store required (call from world thread) |
getPlayerLevel(playerUuid) | int | Player level (-1 if not found) |
getMonsterLevel(store, npcRef) | int | Monster/NPC level (1–100, or 0 if unknown). Uses cache, entity overrides (ZoneLevelConfig), or computed from HP/zone. Use when you have the entity Store and Ref (e.g. in damage/defense systems). |
Notes
- All methods are thread-safe
- Level reads: Use
getPlayerLevelInfo/getPlayerLevelfor player level andgetMonsterLevel(store, npcRef)for monster level so behavior is consistent everywhere (plugin and external mods use the same API). When you have an entity Store (e.g. in systems or GUI), callgetPlayerLevelInfo(playerRef, store)— store is required for correct data when Holder is null. - XP amounts must be positive
- Players must be online to receive XP
- Level ups are handled automatically
- Events fire in registration order
- Handler errors are logged but don’t stop other handlers
- API instance is automatically refreshed on plugin reload
