Class EntityData

java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
All Implemented Interfaces:
Annoyable

public class EntityData extends StringData
Utility class for adding and getting data from entities
  • Field Details

    • TABLE_NAME

      @NotNull public static final @NotNull String TABLE_NAME
      The name of the table in the database to store entity data
      See Also:
  • Constructor Details

    • EntityData

      public EntityData(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.entity.Entity entity)
      Construct a new EntityData for the given entity
      Parameters:
      plugin - Data.plugin
      entity - entity and Data.target (uses entity UUID)
  • Method Details

    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData(boolean onlyTryOnce, @Nullable @Nullable Collection<String> keys)
      Convert all data from the old data storage system (PDC/file) to the new one (SQL)
      This does not run automatically, you must call this method manually (for example, on PlayerJoinEvent)!
      For 1.14+ (PDC), the entity will receive the CONVERTED_KEY key which indicates that the data has been converted, this will avoid duplicate conversion checks
      All old data (PDC/file) will be removed after conversion (to avoid duplicate/overwriting data)
      Parameters:
      onlyTryOnce - 1.14+ only | true to only try once to convert the data, even if it fails (so if run again, nothing will happen). If false, the conversion failed previously, and this is run again, it will try to convert again. If the data is successfully converted, this option doesn't matter
      keys - only applicable for 1.14-1.16, otherwise it will convert all keys (no matter what is provided)
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData(boolean onlyTryOnce, @NotNull @NotNull String... keys)
      Calls convertOldData(boolean, Collection) with the given keys
      Parameters:
      onlyTryOnce - 1.14+ only | true to only try once to convert the data, even if it fails (so if run again, nothing will happen). If false, the conversion failed previously, and this is run again, it will try to convert again. If the data is successfully converted, this option doesn't matter
      keys - only applicable for 1.14-1.16, otherwise it will convert all keys (no matter what is provided)
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
      See Also:
    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData(@NotNull @NotNull Collection<String> keys)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and the given keys
      Parameters:
      keys - only applicable for 1.14-1.16, otherwise it will convert all keys (no matter what is provided)
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
      See Also:
    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData(@NotNull @NotNull String... keys)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and the given keys
      Parameters:
      keys - only applicable for 1.14-1.16, otherwise it will convert all keys (no matter what is provided)
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
      See Also:
    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData(boolean onlyTryOnce)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to true and keys set to null
      Parameters:
      onlyTryOnce - 1.14+ only | true to only try once to convert the data, even if it fails (so if run again, nothing will happen). If false, the conversion failed previously, and this is run again, it will try to convert again. If the data is successfully converted, this option doesn't matter
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
      See Also:
    • convertOldData

      @Nullable public @Nullable Map<String,String> convertOldData()
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and keys set to null
      Returns:
      a map of keys that failed to convert (key, value) or null if an error occurred (only returns null if 1.14+ fails)
      See Also: