Search in sources :

Example 91 with DataContainer

use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.

the class Observe method blockSnapshot.

// Observe
public static Map<String, Object> blockSnapshot(BlockSnapshot block) {
    Map<String, Object> info = new HashMap<>();
    info.put(BLOCK_STATE.asString("_"), toRawData(block.getState().toContainer()));
    DataContainer blockContainer = block.toContainer();
    Optional<List<DataView>> data = blockContainer.getViewList(BLOCK_DATA);
    if (data.isPresent()) {
        info.put(BLOCK_DATA.asString("_"), toRawData(data.get()));
    }
    Optional<Object> unsafe = blockContainer.get(BLOCK_UNSAFE_DATA);
    if (unsafe.isPresent()) {
        info.put(BLOCK_UNSAFE_DATA.asString("_"), toRawData(unsafe.get()));
    }
    return info;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 92 with DataContainer

use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.

the class ReportUtil method name.

public static Text name(BlockSnapshot snapshot, Receiver receiver) {
    BlockType type = snapshot.getState().getType();
    Translation trans = type.getTranslation();
    if (snapshot.getState().getType().getItem().isPresent()) {
        trans = ItemStack.builder().fromBlockSnapshot(snapshot).build().getTranslation();
    }
    Builder builder = Text.builder();
    builder.append(Text.of(GOLD, trans).toBuilder().onHover(showText(Text.of(type.getName()))).build());
    Optional<List<DataView>> items = snapshot.toContainer().getViewList(BlockReport.BLOCK_ITEMS);
    if (items.isPresent() && !items.get().isEmpty()) {
        // TODO lookup config : detailed inventory? click on ∋ to activate/deactivate or using cmd
        builder.append(Text.of(" ∋ ["));
        if (receiver.getLookup().getSettings().showDetailedInventory()) {
            builder.append(Text.of(" "));
            for (DataView dataView : items.get()) {
                DataContainer itemData = DataContainer.createNew();
                itemData.set(DataQuery.of("Count"), dataView.get(DataQuery.of("Count")).get());
                itemData.set(DataQuery.of("ItemType"), dataView.get(DataQuery.of("id")).get());
                Optional<DataView> tag = dataView.getView(DataQuery.of("tag"));
                if (tag.isPresent()) {
                    itemData.set(DataQuery.of("UnsafeData"), tag.get().getValues(false));
                }
                itemData.set(DataQuery.of("UnsafeDamage"), dataView.get(DataQuery.of("Damage")).get());
                ItemStack item = ItemStack.builder().fromContainer(itemData).build();
                builder.append(Text.of(dataView.getInt(DataQuery.of("Slot")).get()).toBuilder().onHover(showItem(item.createSnapshot())).build());
                builder.append(Text.of(" "));
            }
        } else {
            builder.append(Text.of("..."));
        }
        builder.append(Text.of("]"));
    }
    Optional<List<Text>> sign = snapshot.get(Keys.SIGN_LINES);
    if (sign.isPresent()) {
        builder.append(Text.of(" "), Text.of("[I]").toBuilder().onHover(showText(Text.joinWith(Text.NEW_LINE, sign.get()))).build());
    }
    return builder.build();
}
Also used : DataView(org.spongepowered.api.data.DataView) Translation(org.spongepowered.api.text.translation.Translation) DataContainer(org.spongepowered.api.data.DataContainer) BlockType(org.spongepowered.api.block.BlockType) Builder(org.spongepowered.api.text.Text.Builder) List(java.util.List) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 93 with DataContainer

use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.

the class ImmutableKitData method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = DataContainer.createNew();
    container.set(TIMES, this.times);
    container.set(TIME, this.time);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 94 with DataContainer

use of org.spongepowered.api.data.DataContainer in project core by CubeEngine.

the class DataContainerConverter method fromNode.

@Override
public DataContainer fromNode(Node node, Class<? extends DataContainer> type, ConverterManager manager) throws ConversionException {
    DataContainer data = DataContainer.createNew();
    for (Entry<String, Node> entry : ((MapNode) node).getValue().entrySet()) {
        DataQuery key = DataQuery.of('_', ((MapNode) node).getOriginalKey(entry.getKey()));
        data.set(key, toObject(entry.getValue(), manager));
    }
    return data;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) MapNode(org.cubeengine.converter.node.MapNode) ListNode(org.cubeengine.converter.node.ListNode) Node(org.cubeengine.converter.node.Node) DataQuery(org.spongepowered.api.data.DataQuery)

Example 95 with DataContainer

use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.

the class MemoryDataView method copy.

@Override
public DataContainer copy() {
    final DataContainer container = new MemoryDataContainer(this.safety);
    getKeys(false).forEach(query -> get(query).ifPresent(obj -> container.set(query, obj)));
    return container;
}
Also used : Arrays(java.util.Arrays) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TypeToken(com.google.common.reflect.TypeToken) DataQuery(org.spongepowered.api.data.DataQuery) Supplier(java.util.function.Supplier) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) DataSerializable(org.spongepowered.api.data.DataSerializable) LinkedHashMap(java.util.LinkedHashMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) DataTypeSerializer(org.lanternpowered.server.data.persistence.DataTypeSerializer) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects(com.google.common.base.Objects) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) DataQuery.of(org.spongepowered.api.data.DataQuery.of) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BaseValue(org.spongepowered.api.data.value.BaseValue) MoreObjects(com.google.common.base.MoreObjects) CatalogType(org.spongepowered.api.CatalogType) Sponge(org.spongepowered.api.Sponge) DataContainer(org.spongepowered.api.data.DataContainer) Set(java.util.Set) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Stream(java.util.stream.Stream) DataView(org.spongepowered.api.data.DataView) Lantern(org.lanternpowered.server.game.Lantern) Coerce(org.spongepowered.api.util.Coerce) Optional(java.util.Optional) DataContainer(org.spongepowered.api.data.DataContainer)

Aggregations

DataContainer (org.spongepowered.api.data.DataContainer)110 DataView (org.spongepowered.api.data.DataView)30 DataQuery (org.spongepowered.api.data.DataQuery)28 Test (org.junit.Test)24 List (java.util.List)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 Nullable (javax.annotation.Nullable)11 Collection (java.util.Collection)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 IOException (java.io.IOException)9 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CatalogType (org.spongepowered.api.CatalogType)9 Sponge (org.spongepowered.api.Sponge)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 DataSerializable (org.spongepowered.api.data.DataSerializable)7