use of io.github.plugindustry.wheelcore.interfaces.item.ItemData in project WheelCore by Plugindustry.
the class NBTBasedProvider method getData.
@Nullable
@Override
public ItemData getData(@Nullable ItemStack itemStack) {
if (itemStack == null)
return null;
Optional<NbtWrapper<?>> nbtWrapperOptional = NbtFactory.fromItemOptional((ItemStack) ShadowManager.shadowUnpack(CraftItemStack.asCraftCopy(itemStack)));
if (nbtWrapperOptional.isEmpty())
return null;
NbtWrapper<?> nbtWrapper = nbtWrapperOptional.get();
if (nbtWrapper.getType() != NbtType.TAG_COMPOUND)
return null;
NbtCompound compound = NbtFactory.asCompound(nbtWrapper);
if (!compound.containsKey("wheel_core_item_data"))
return null;
Object data = compound.getObject("wheel_core_item_data");
return data instanceof String ? gson.fromJson((String) data, ItemData.class) : null;
}
use of io.github.plugindustry.wheelcore.interfaces.item.ItemData in project WheelCore by Plugindustry.
the class PersistenceBasedProvider method setData.
@Override
public void setData(@Nonnull ItemStack itemStack, @Nullable ItemData data) {
if (data == null) {
if (itemStack.hasItemMeta()) {
ItemMeta meta = Objects.requireNonNull(itemStack.getItemMeta());
meta.getPersistentDataContainer().remove(ITEM_DATA_KEY);
itemStack.setItemMeta(meta);
}
} else {
ItemMeta meta = itemStack.hasItemMeta() ? Objects.requireNonNull(itemStack.getItemMeta()) : Bukkit.getItemFactory().getItemMeta(itemStack.getType());
Objects.requireNonNull(meta).getPersistentDataContainer().set(ITEM_DATA_KEY, PersistentDataType.STRING, gson.toJson(data, ItemData.class));
itemStack.setItemMeta(meta);
}
}
use of io.github.plugindustry.wheelcore.interfaces.item.ItemData in project WheelCore by Plugindustry.
the class I18n method getOriginalItem.
@Nonnull
private static ItemStack getOriginalItem(@Nonnull ItemStack item) {
ItemData itemData = MainManager.getItemData(item);
if (itemData instanceof TranslatedItemData) {
ItemStack orgItem = Optional.ofNullable(((TranslatedItemData) itemData).originalItem).orElse(item);
orgItem.setAmount(item.getAmount());
return orgItem;
} else
return item;
}
Aggregations