From 2468fdde8bd840b4ee695195a468de303ea9561f Mon Sep 17 00:00:00 2001 From: lbenav8095 Date: Tue, 20 Aug 2024 05:18:04 -0400 Subject: [PATCH] Fixes UniqueAPI --- .../java/us/mytheria/bloblib/UniqueAPI.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/us/mytheria/bloblib/UniqueAPI.java b/src/main/java/us/mytheria/bloblib/UniqueAPI.java index ea522c1..9157212 100644 --- a/src/main/java/us/mytheria/bloblib/UniqueAPI.java +++ b/src/main/java/us/mytheria/bloblib/UniqueAPI.java @@ -1,8 +1,13 @@ package us.mytheria.bloblib; import org.bukkit.NamespacedKey; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataHolder; +import org.bukkit.persistence.PersistentDataType; import us.mytheria.bloblib.itemapi.DiscriminatorItemAPI; +import java.util.UUID; + public class UniqueAPI implements DiscriminatorItemAPI { private static UniqueAPI instance; private final NamespacedKey namespacedKey; @@ -24,7 +29,19 @@ public static UniqueAPI getInstance() { return getInstance(null); } + @Override + public void set(PersistentDataHolder holder) { + UUID random = UUID.randomUUID(); + holder.getPersistentDataContainer().set(namespacedKey, PersistentDataType.STRING, random.toString()); + } + + @Override + public boolean isInstance(PersistentDataHolder holder) { + PersistentDataContainer container = holder.getPersistentDataContainer(); + return container.has(namespacedKey, PersistentDataType.STRING); + } + public NamespacedKey getNamespacedKey() { return namespacedKey; } -} +} \ No newline at end of file