Class DataTypeMethods
java.lang.Object
io.github.sefiraat.networks.utils.datatypes.DataTypeMethods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,Z> Z getCustom(PersistentDataHolder holder, NamespacedKey key, PersistentDataType<T, Z> type) Get an object based on the providedPersistentDataTypein aPersistentDataContainer, if the key doesn't exist it returns null.static <T,Z> Z getCustom(PersistentDataHolder holder, NamespacedKey key, PersistentDataType<T, Z> type, Z defaultVal) Get an object based on the providedPersistentDataTypein aPersistentDataContaineror the default value if the key doesn't exist.static <T,Z> Optional<Z> getOptionalCustom(PersistentDataHolder holder, NamespacedKey key, PersistentDataType<T, Z> type) This method returns anOptionaldescribing the object defined by thePersistentDataTypefound under the given key.static <T,Z> boolean hasCustom(PersistentDataHolder holder, NamespacedKey key, PersistentDataType<T, Z> type) Checks if the specifiedPersistentDataHolderhas aPersistentDataContainerwith the specified key.static <T,Z> void setCustom(PersistentDataHolder holder, NamespacedKey key, PersistentDataType<T, Z> type, Z obj) Set a customPersistentDataTypein aPersistentDataContainer
-
Constructor Details
-
DataTypeMethods
public DataTypeMethods()
-
-
Method Details
-
getCustom
@Nullable public static <T,Z> Z getCustom(@Nonnull PersistentDataHolder holder, @Nonnull NamespacedKey key, @Nonnull PersistentDataType<T, Z> type) Get an object based on the providedPersistentDataTypein aPersistentDataContainer, if the key doesn't exist it returns null.- Parameters:
holder- ThePersistentDataHolderto retrieve the data fromkey- The key of the data to retrieve- Returns:
- An object associated with this key or null if it doesn't exist
-
getOptionalCustom
@Nonnull public static <T,Z> Optional<Z> getOptionalCustom(@Nonnull PersistentDataHolder holder, @Nonnull NamespacedKey key, @Nonnull PersistentDataType<T, Z> type) This method returns anOptionaldescribing the object defined by thePersistentDataTypefound under the given key. An emptyOptionalwill be returned if no value has been found.- Parameters:
holder- ThePersistentDataHolderto retrieve the data fromkey- The key of the data to retrieve- Returns:
- An
Optionaldescribing the result - See Also:
-
PersistentDataAPI#getCustom(PersistentDataHolder, NamespacedKey, PersistentDataType)
-
getCustom
public static <T,Z> Z getCustom(@Nonnull PersistentDataHolder holder, @Nonnull NamespacedKey key, @Nonnull PersistentDataType<T, Z> type, @Nonnull Z defaultVal) Get an object based on the providedPersistentDataTypein aPersistentDataContaineror the default value if the key doesn't exist.- Parameters:
holder- ThePersistentDataHolderto retrieve the data fromkey- The key of the data to retrievedefaultVal- The default value to use if no key is found- Returns:
- The object associated with this key or the default value if it doesn't exist
-
hasCustom
public static <T,Z> boolean hasCustom(@Nonnull PersistentDataHolder holder, @Nonnull NamespacedKey key, @Nonnull PersistentDataType<T, Z> type) Checks if the specifiedPersistentDataHolderhas aPersistentDataContainerwith the specified key.- Parameters:
holder- ThePersistentDataHolderto checkkey- The key to check for- Returns:
trueif the holder has aPersistentDataContainerwith the specified key.
-
setCustom
public static <T,Z> void setCustom(@Nonnull PersistentDataHolder holder, @Nonnull NamespacedKey key, @Nonnull PersistentDataType<T, Z> type, @Nonnull Z obj) Set a customPersistentDataTypein aPersistentDataContainer- Parameters:
holder- ThePersistentDataHolderto add the data tokey- The key of the data to settype- ThePersistentDataTypeto be used.obj- The object to put in the container
-