Last active
February 1, 2021 14:57
-
-
Save gepron1x/b6f76e5f67db721e8e2d3a98ffba4ef3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.gepron1x.decaliumcustomitems.utils.persistentdatatype; | |
import me.gepron1x.decaliumcustomitems.DecaliumCustomItems; | |
import org.bukkit.NamespacedKey; | |
import org.bukkit.persistence.PersistentDataAdapterContext; | |
import org.bukkit.persistence.PersistentDataContainer; | |
import org.bukkit.persistence.PersistentDataType; | |
import java.util.UUID; | |
public class UUIDDataType implements PersistentDataType<PersistentDataContainer, UUID> { | |
private static final NamespacedKey MOST = new NamespacedKey(DecaliumCustomItems.get(), "uuid_most"); | |
private static final NamespacedKey LEAST = new NamespacedKey(DecaliumCustomItems.get(), "uuid_least"); | |
@Override | |
public Class<PersistentDataContainer> getPrimitiveType() { | |
return PersistentDataContainer.class; | |
} | |
@Override | |
public Class<UUID> getComplexType() { | |
return UUID.class; | |
} | |
@Override | |
public PersistentDataContainer toPrimitive(UUID uuid, PersistentDataAdapterContext context) { | |
PersistentDataContainer container = context.newPersistentDataContainer(); | |
container.set(MOST,PersistentDataType.LONG, uuid.getMostSignificantBits()); | |
container.set(LEAST,PersistentDataType.LONG, uuid.getLeastSignificantBits()); | |
return container; | |
} | |
@Override | |
public UUID fromPrimitive(PersistentDataContainer container, PersistentDataAdapterContext persistentDataAdapterContext) { | |
return new UUID( | |
container.get(MOST, PersistentDataType.LONG), | |
container.get(LEAST ,PersistentDataType.LONG) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment