Class Data<T>

java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
xyz.srnyx.annoyingapi.data.Data<T>
Type Parameters:
T - the type of target to manage data for
All Implemented Interfaces:
Annoyable
Direct Known Subclasses:
ItemData, StringData

public abstract class Data<T> extends xyz.srnyx.javautilities.parents.Stringable implements Annoyable
Represents a class that can be used to manage data
  • Field Details

    • plugin

      @NotNull protected final @NotNull AnnoyingPlugin plugin
      The plugin instance
    • target

      @NotNull public final T target
      The target to manage data for
  • Constructor Details

    • Data

      protected Data(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull T target)
      Construct a new Data for the given target
      Parameters:
      plugin - plugin
      target - target
  • Method Details

    • getAnnoyingPlugin

      @NotNull public @NotNull AnnoyingPlugin getAnnoyingPlugin()
      Description copied from interface: Annoyable
      The AnnoyingPlugin instance
      Specified by:
      getAnnoyingPlugin in interface Annoyable
      Returns:
      the plugin instance
    • has

      public boolean has(@NotNull @NotNull String key)
      Check if the data value exists for the given key
      Parameters:
      key - the key to check for
      Returns:
      true if the data value exists, false otherwise
    • get

      @Nullable public abstract @Nullable String get(@NotNull @NotNull String key)
      Get the data value for the given key
      Parameters:
      key - the key to get the data value for
      Returns:
      the data value, or null if not found
    • get

      @NotNull public @NotNull String get(@NotNull @NotNull String key, @NotNull @NotNull String def)
      Get the data value for the given key, or the default value if not found
      Parameters:
      key - the key to get the data value for
      def - the default value to return if the data value is not found
      Returns:
      the data value, or the default value if not found
    • getOptional

      @NotNull public @NotNull Optional<String> getOptional(@NotNull @NotNull String key)
      Get the data value for the given key as an Optional
      Parameters:
      key - the key to get the data value for
      Returns:
      the data value as an Optional
    • set

      protected abstract boolean set(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Set the data value for the given key. If the key already exists, it will be overwritten
      Parameters:
      key - the key to set the data value for
      value - the data value to set
      Returns:
      true if the data value was set successfully, false otherwise
    • set

      public boolean set(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Set the data value for the given key. If the key already exists, it will be overwritten
      Parameters:
      key - the key to set the data value for
      value - the data value to set, or null to remove the data value
      Returns:
      true if the data value was set successfully, false otherwise
    • setChain

      @NotNull public @NotNull Data<T> setChain(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Set the data value for the given key. If the key already exists, it will be overwritten
      Parameters:
      key - the key to set the data value for
      value - the data value to set, or null to remove the data value
      Returns:
      this Data instance for chaining
    • remove

      public abstract boolean remove(@NotNull @NotNull String key)
      Remove the data value with the given key
      Parameters:
      key - the key to remove the data value for
      Returns:
      true if the data value was removed successfully, false otherwise
    • removeChain

      @NotNull public @NotNull Data<T> removeChain(@NotNull @NotNull String key)
      Remove the data value with the given key
      Parameters:
      key - the key to remove the data value for
      Returns:
      this Data instance for chaining
    • sendError

      protected void sendError(@NotNull @NotNull String action, @Nullable @Nullable Throwable t)
      Send an error message to the console
      Parameters:
      action - the action that failed
      t - the Throwable that caused the error