Class PlayerPreference

java.lang.Object
tk.airshipcraft.commonlib.configuration.impl.PlayerPreference
All Implemented Interfaces:
IPlayerPreference

public abstract class PlayerPreference extends Object implements IPlayerPreference

Provides a skeletal implementation of the IPlayerPreference interface to facilitate the creation of player preference classes. This abstract class is designed to minimize the effort required in implementing the IPlayerPreference interface by providing basic implementations and structure for handling player preferences.

Subclasses are expected to provide concrete implementations of the load, save, and describePart methods. The reset method can be overridden if custom reset behavior is desired. Each subclass can represent a different set of preferences for players, allowing for modular and flexible preference management within the plugin.

Example Usage:


 public class MyPluginPlayerPreferences extends PlayerPreference {
     @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;
     }
 }
 

This example shows how to create a `PlayerPreference` class that manages preferences for a player's town and nation./p>

Since:
2023-11-20
Version:
1.0.0
Author:
notzune
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected UUID
    Player UUID associated with this preference instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlayerPreference(org.bukkit.entity.Player player)
    Constructs a PlayerPreference instance associated with the given player.
  • Method Summary

    Modifier and Type
    Method
    Description
    describe(org.bukkit.entity.Player player)
    Provides a string representation of the player's current preferences.
    protected abstract String
    Provides a part of the description of player preferences specific to the subclass.
    abstract void
    load(org.bukkit.entity.Player player)
    Loads the player's preferences from a persistent data store.
    void
    reset(org.bukkit.entity.Player player)
    Provides a default implementation for resetting player preferences.
    abstract void
    save(org.bukkit.entity.Player player)
    Saves the current state of the player's preferences to a persistent data store.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • playerUuid

      protected UUID playerUuid
      Player UUID associated with this preference instance.
  • Constructor Details

    • PlayerPreference

      public PlayerPreference(org.bukkit.entity.Player player)
      Constructs a PlayerPreference instance associated with the given player. The player's UUID is used internally for preference management.
      Parameters:
      player - The player whose preferences are managed by this class.
  • Method Details

    • load

      public abstract void load(org.bukkit.entity.Player player)
      Loads the player's preferences from a persistent data store. This method should be implemented to retrieve the stored preferences of a player and apply them. It's typically called when a player joins the server or a reload of preferences is needed. Subclasses should provide an implementation that loads preferences specific to the player.
      Specified by:
      load in interface IPlayerPreference
      Parameters:
      player - The player whose preferences are to be loaded.
    • save

      public abstract void save(org.bukkit.entity.Player player)
      Saves the current state of the player's preferences to a persistent data store. Implementations should ensure that any changes made to the preferences are persisted. This method is usually called when a player leaves the server or when preferences are changed. Subclasses should provide an implementation that saves the current state of preferences for the player.
      Specified by:
      save in interface IPlayerPreference
      Parameters:
      player - The player whose preferences are to be saved.
    • reset

      public void reset(org.bukkit.entity.Player player)
      Provides a default implementation for resetting player preferences. This method can be overridden by subclasses to implement custom reset behavior.
      Specified by:
      reset in interface IPlayerPreference
      Parameters:
      player - The player whose preferences are to be reset.
    • describe

      public String describe(org.bukkit.entity.Player player)
      Provides a string representation of the player's current preferences. This can be used to display the preferences to the player, for logging, or for administrative purposes. The format and detail level of the description can vary depending on the implementation. This implementation combines descriptions from various parts (handled by describePart method) to create a full description of the player's preferences.
      Specified by:
      describe in interface IPlayerPreference
      Parameters:
      player - The player whose preference summary is to be retrieved.
      Returns:
      A concatenated string representation of the player's preferences.
    • describePart

      protected abstract String describePart()
      Provides a part of the description of player preferences specific to the subclass. Subclasses should override this method to contribute to the overall description of the player's preferences.
      Returns:
      A string representing a part of the player's preference description.