use of org.spongepowered.api.data.DataContainer in project TotalEconomy by Erigitic.
the class ShopManager method removeShopItemData.
/**
* Removes ShopItemData from an ItemStack.
*
* @param itemStack The ItemStack to remove ShopItemData from
* @return ItemStack An ItemStack with ShopItemData removed
*/
private ItemStack removeShopItemData(ItemStack itemStack) {
itemStack.remove(Keys.ITEM_LORE);
itemStack.remove(ShopKeys.SHOP_ITEM);
// Remove the DataQuery for lore, otherwise an empty NBT tag will be attached to the item
DataContainer dataContainer = itemStack.toContainer().remove(DataQuery.of("DefaultReplacement", "UnsafeData", "display", "Lore")).copy();
itemStack = ItemStack.builder().fromContainer(dataContainer).itemType(itemStack.getItem()).quantity(1).build();
return itemStack;
}
use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.
the class IImmutableDataHolder method toContainer.
@Override
default DataContainer toContainer() {
final DataContainer dataContainer = DataContainer.createNew();
DataHelper.serializeRawData(dataContainer, this);
return dataContainer;
}
use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.
the class DataSerializableTypeSerializer method serialize.
@Override
public void serialize(TypeToken<?> type, DataSerializable obj, ConfigurationNode value) throws ObjectMappingException {
final DataContainer container = obj.toContainer();
value.setValue(ConfigurateTranslator.instance().translate(container));
}
use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.
the class LanternTextHelper method raw.
public static RawAction raw(HoverAction<?> hoverAction) {
if (hoverAction instanceof HoverAction.ShowText) {
return new RawAction("show_text", ((HoverAction.ShowText) hoverAction).getResult());
} else if (hoverAction instanceof HoverAction.ShowEntity) {
final HoverAction.ShowEntity.Ref ref = ((HoverAction.ShowEntity) hoverAction).getResult();
final DataContainer dataContainer = DataContainer.createNew().set(SHOW_ENTITY_ID, ref.getUniqueId().toString()).set(SHOW_ENTITY_NAME, ref.getName());
ref.getType().ifPresent(type -> dataContainer.set(SHOW_ENTITY_TYPE, type.getId()));
try {
return new RawAction("show_entity", JsonDataFormat.writeAsString(dataContainer));
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else if (hoverAction instanceof HoverAction.ShowItem) {
final ItemStackSnapshot itemStackSnapshot = ((HoverAction.ShowItem) hoverAction).getResult();
final LanternItemStack itemStack = (LanternItemStack) itemStackSnapshot.createStack();
final DataView dataView = ItemStackStore.INSTANCE.serialize(itemStack);
try {
return new RawAction("show_item", JsonDataFormat.writeAsString(dataView));
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
throw new IllegalArgumentException("Unknown hover action type: " + hoverAction.getClass().getName());
}
}
use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.
the class MemoryDataView method copy.
@Override
public DataContainer copy(SafetyMode safety) {
final DataContainer container = new MemoryDataContainer(safety);
getKeys(false).forEach(query -> get(query).ifPresent(obj -> container.set(query, obj)));
return container;
}
Aggregations