getPluginPlayerPref

fun <T> getPluginPlayerPref(pluginKey: String, prefKey: String, type: Class<T>, defaultValue: T?): T?

Retrieves a plugin-specific preference with type safety and default value support.

This method provides type-safe access to plugin preferences with automatic type checking and default value fallback. It's the preferred method for retrieving preferences when you know the expected type.

Type Safety: The method uses Class.isInstance() to verify that the stored value matches the expected type before casting, preventing ClassCastException.

Usage Examples:

val enabled = playerData.getPluginPlayerPref("MyPlugin", "enabled", Boolean::class.java, false)
val maxLevel = playerData.getPluginPlayerPref("Skills", "max_level", Int::class.java, 100)
val playerClass = playerData.getPluginPlayerPref("RPG", "class", String::class.java, "warrior")

Return Logic:

  1. Returns the stored value if plugin exists, key exists, and type matches

  2. Returns defaultValue if plugin doesn't exist

  3. Returns defaultValue if key doesn't exist in plugin preferences

  4. Returns defaultValue if stored value type doesn't match expected type

Return

The preference value cast to type T, or defaultValue if not available/valid

Parameters

T

The expected type of the preference value

pluginKey

The plugin identifier/namespace

prefKey

The specific preference key within the plugin namespace

type

The Class object representing the expected type T

defaultValue

The value to return if preference not found or type mismatch

See also


fun getPluginPlayerPref(pluginKey: String, prefKey: String): Any?

Retrieves a plugin-specific preference without type checking.

This method provides raw access to plugin preferences without type safety. Use this when you need to inspect the stored value or when the type is unknown. For type-safe access, use the overloaded version with type parameter.

Usage Examples:

val rawValue = playerData.getPluginPlayerPref("MyPlugin", "complex_data")
val exists = playerData.getPluginPlayerPref("Settings", "theme") != null

Return Behavior:

  • Returns the stored value (of type Any) if found

  • Returns null if plugin namespace doesn't exist

  • Returns null if preference key doesn't exist

  • Calling code must handle type casting manually

Return

The preference value as Any, or null if not found

Parameters

pluginKey

The plugin identifier/namespace

prefKey

The specific preference key within the plugin namespace

See also