Class EntityData

  • All Implemented Interfaces:
    Annoyable

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

      Fields 
      Modifier and Type Field Description
      static @NotNull java.lang.String TABLE_NAME
      The name of the table in the database to store entity data
    • Constructor Summary

      Constructors 
      Constructor Description
      EntityData​(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.entity.Entity entity)
      Construct a new EntityData for the given entity
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData()
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and keys set to null
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(boolean onlyTryOnce)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to true and keys set to null
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(boolean onlyTryOnce, @NotNull java.lang.String... keys)
      Calls convertOldData(boolean, Collection) with the given keys
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(boolean onlyTryOnce, @Nullable java.util.Collection<java.lang.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)
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(@NotNull java.lang.String... keys)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and the given keys
      @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(@NotNull java.util.Collection<java.lang.String> keys)
      Calls convertOldData(boolean, Collection) with onlyTryOnce set to false and the given keys
      • Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

        toString, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • TABLE_NAME

        @NotNull
        public static final @NotNull java.lang.String TABLE_NAME
        The name of the table in the database to store entity data
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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 Detail

      • convertOldData

        @Nullable
        public @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(boolean onlyTryOnce,
                                                                                               @Nullable
                                                                                               @Nullable java.util.Collection<java.lang.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 java.util.Map<java.lang.String,​java.lang.String> convertOldData​(boolean onlyTryOnce,
                                                                                               @NotNull
                                                                                               @NotNull java.lang.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(boolean, Collection)
      • convertOldData

        @Nullable
        public @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(@NotNull
                                                                                               @NotNull java.util.Collection<java.lang.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(boolean, Collection)
      • convertOldData

        @Nullable
        public @Nullable java.util.Map<java.lang.String,​java.lang.String> convertOldData​(@NotNull
                                                                                               @NotNull java.lang.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(boolean, Collection)
      • convertOldData

        @Nullable
        public @Nullable java.util.Map<java.lang.String,​java.lang.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(boolean, Collection)
      • convertOldData

        @Nullable
        public @Nullable java.util.Map<java.lang.String,​java.lang.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:
        convertOldData(boolean, Collection)