Classes
Classes of players from all RPG plugins supported by Mimic. Get it via Mimic.classes. To make your own plugin's classes available here, implement ClassProvider instead.
A slot holds at most one of the player's classes: a class group, a primary or secondary class, a race. Races are classes too, held in a race slot. A player may have classes from several plugins at once, for example a class from one plugin and a race from another.
It replaces the deprecated ClassSystem API, which supports only a flat list of class names.
Quick start
// Check the class, a paladin is a warrior too if it is a subclass of a warrior
if (classes.hasClass(player, Key.key("fabled:warrior"))) { ... }
// Check the level of the player's class, server owners choose its plugin in Mimic config
CharacterClass playerClass = classes.getPrimaryClass(player);
if (playerClass == null) return; // The player hasn't picked a class yet
Key levelTrack = playerClass.levelTrack();
if (levelTrack != null && levels.hasLevel(player, levelTrack, 20)) { ... }IDs
Slots and classes are identified by Key, which consists of a namespace and a path:
The namespace is the ID of the plugin providing the slot or class:
fabled,heroes.The path is the slot or class within that plugin:
race,warrior.
For example, a class plugin may provide slots fabled:class and fabled:race, and classes fabled:warrior and fabled:elf.
The namespace is required, since the same path in different plugins means a different class. Note that Key.key("warrior") turns into minecraft:warrior, so validate class IDs read from configs against getAllClasses. Classes of plugins using the deprecated ClassSystem API are missing from getAllClasses.
Rules
Works only with online players.
null,falseor empty means "not possible right now": the class doesn't exist, the plugin doesn't support this action, or the player's data isn't loaded yet.A slot holds at most one class. An empty slot is normal: the player hasn't picked a class there yet.
Don't cache results. Read them again each time you need them.
Read from any thread. Change classes only on the main thread (on Folia - on the player's thread).
Since
0.10.0
Functions
Returns all classes of all providers, regardless of players. Use it for discovery and config validation. Classes are sorted by provider priority, then in the order the provider returns them.
Returns all slots of all providers, regardless of players. Slots are sorted by provider priority, then in the order the provider returns them.
Returns classes the player has, where key is a slot ID. Empty slots are omitted. Entries are sorted by provider priority, then in the order the provider returns them.
Returns the class that best represents the player's class, or null if there is no such class.
Sets the class with classId in the slot chosen by the plugin. It works like the plugin's admin command changing the class, with its usual side effects: the plugin may keep or reset the class progress, give items, or run commands.