Package tk.airshipcraft.commonlib.configuration.impl


package tk.airshipcraft.commonlib.configuration.impl

Provides the classes necessary for managing player preferences within a Bukkit plugin. The preference system allows for persistent storage and retrieval of player-specific settings, which can be used across different plugins.

Classes:

  • PlayerPreference: An abstract class that provides basic implementations of the IPlayerPreference interface methods and handles the reflection logic for annotated fields with the PlayerPref annotation.
  • PreferenceProcessor: A utility class that contains static methods to load and save annotated fields from and to both a file configuration and a MySQL database using reflection.
  • PreferencesManager: Manages all player preferences, providing methods to register, load, save, and reset preferences, as well as to describe them for individual players.

Usage:

To use the preference system, a plugin developer must create a class that implements the IPlayerPreference interface and use the PlayerPref annotation to mark which fields should be managed. The PreferencesManager is then used to handle these preferences.

Usage example in another plugin:


 public class MyPluginPlayerPreferences implements IPlayerPreference {

     @PlayerPref(defaultValue = "defaultTown")
     private String townName;

     @PlayerPref(defaultValue = "defaultNation")
     private String nationName;

     // Constructor, getters and setters, and other methods...

     @Override
     public void load(Player player) {
         // Logic to load preferences (potentially using reflection to read annotated fields)
     }

     @Override
     public void save(Player player) {
         // Logic to save preferences (potentially using reflection to write annotated fields)
     }

     @Override
     public void reset(Player player) {
         // Logic to reset preferences to defaults
     }

     @Override
     public String describe(Player player) {
         // Return a description of all the player's preferences
         return "Town: " + townName + ", Nation: " + nationName;
     }
 }
 

The PreferenceCommand can be used as a template for creating commands that interact with the player preferences, allowing players to set and view their preferences in-game.

Please note that the reflection-based operations require careful exception handling and validation to ensure data integrity and plugin stability.

Since:
2023-11-20
Version:
1.0.0
Author:
notzune
  • Classes
    Class
    Description
    Provides a skeletal implementation of the IPlayerPreference interface to facilitate the creation of player preference classes.
    Provides static utility methods to process player preferences using reflection.
    Manages the preferences of all players on a Minecraft server.