ClassProvider

Implement it to make your plugin's classes available via Classes. Register it in onLoad via Mimic.registerClassProvider. To read or change classes of players, use Classes 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. Your plugin may have one slot or many.

It replaces the deprecated ClassSystem API, which supports only a flat list of class names.

What to implement

IDs

Mimic adds your provider id as the namespace, so return slot and class IDs without it: warrior becomes myplugin:warrior. Don't change id later, it breaks consumers' configs. Class IDs are unique within your provider, regardless of the slot.

If your plugin has its own namespaced IDs, convert them to paths:

  • Drop your plugin's own namespace: origins:human ->human.

  • Keep other namespaces as the first path part: myaddon:elf ->myaddon/elf.

Other rules:

  • Allowed characters: a-z, 0-9, ., _, - and /. Slots and classes with other characters are ignored.

  • To convert other IDs, lowercase them and replace other characters with _. Keep a map back to the original IDs.

  • If two IDs become the same (Warrior and warrior), log a warning and keep one of them.

Rules

  • Only online players are passed to the provider.

  • Never throw. If the player's data isn't loaded yet, return null or empty from reads and false from writes.

  • Don't change data until the player's data is loaded, even if your plugin's API allows it.

  • Report only active classes. Unlocked but inactive classes, classes the player has left, jobs and professions aren't classes here.

  • Report a placeholder meaning "no class yet", like a starting class, as an empty slot, so consumers can tell whether the player has picked a class. A default that is a real choice, like a starting race, is a class.

  • Reads may be called from any thread. If your plugin can't read data there, return null or empty instead of throwing.

  • Writes are expected on the main thread (on Folia - on the player's thread), but Mimic doesn't enforce it.

Mimic does the rest: selects the provider by the ID namespace, finds subclasses using ClassDefinition.parents, and catches errors thrown by the provider.

Since

0.10.0

Types

Link copied to clipboard
class ClassDefinition @JvmOverloads constructor(@KeyPattern.Value val id: String, val name: Component, val parents: Set<String> = emptySet(), @KeyPattern.Value val levelTrack: String? = null)

Class of a ClassProvider. Classes are immutable, so they can be cached and reused.

Link copied to clipboard
class Slot(@KeyPattern.Value val id: String, val name: Component)

Slot of a ClassProvider. Slots are immutable, so they can be cached and reused.

Properties

Link copied to clipboard

All classes this provider knows, regardless of players. The list may change at runtime, so it is read on every request.

Link copied to clipboard

All slots this provider knows, regardless of players. The list may change at runtime, so it is read on every request.

Inherited properties

Link copied to clipboard
open val id: String
Link copied to clipboard
open val isEnabled: Boolean

Functions

Link copied to clipboard

Returns classes the player has, where key is a slot ID. Empty slots are omitted. Return the same ClassDefinition.parents and ClassDefinition.levelTrack as in allClasses.

Link copied to clipboard
abstract fun getPrimarySlot(player: Player): ClassProvider.Slot?

Returns the slot holding the class that best represents the player's class, or null if there is no such slot.

Link copied to clipboard
open fun setClass(player: Player, @KeyPattern.Value classId: String, @KeyPattern.Value slotId: String?): Boolean

Sets the class with classId in the slot with slotId, or in the slot chosen by your plugin if slotId is null. Do the same as your plugin's admin command changing the class, with its usual side effects. Check that classId is one of your classes, and that the class can be held in the slot.