Skip to content

Instantly share code, notes, and snippets.

@gepron1x
Last active February 1, 2021 14:57
Show Gist options
  • Save gepron1x/b6f76e5f67db721e8e2d3a98ffba4ef3 to your computer and use it in GitHub Desktop.
Save gepron1x/b6f76e5f67db721e8e2d3a98ffba4ef3 to your computer and use it in GitHub Desktop.
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