Search in sources :

Example 71 with DataView

use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testLists.

@Test
public void testLists() {
    DataContainer container = DataContainer.createNew();
    DataQuery query = of("foo");
    List<DataView> list = Lists.newArrayList();
    for (int i = 0; i < 1; i++) {
        DataContainer internal = DataContainer.createNew();
        internal.set(of("foo", "bar"), "foo.bar" + i);
        int[] ints = new int[] { 0, 1, 2, 3, i };
        internal.set(of("ints"), Arrays.asList(ints));
        list.add(internal);
    }
    container.set(query, list);
    assertTrue(container.contains(query));
    List<DataView> queriedList = container.getViewList(query).get();
    assertTrue(queriedList.equals(list));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 72 with DataView

use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testMaps.

@Test
public void testMaps() {
    Map<String, Object> myMap = Maps.newHashMap();
    myMap.put("foo", "bar");
    myMap.put("myNumber", 1);
    List<String> stringList = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        stringList.add("Foo" + i);
    }
    myMap.put("myList", stringList);
    DataView view = DataContainer.createNew();
    view.set(of("Foo"), myMap);
    Map<?, ?> retrievedMap = view.getMap(of("Foo")).get();
    assertTrue(myMap.keySet().equals(retrievedMap.keySet()));
    assertTrue(myMap.entrySet().equals(retrievedMap.entrySet()));
}
Also used : DataView(org.spongepowered.api.data.DataView) Test(org.junit.Test)

Example 73 with DataView

use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testGetKeys.

@Test
public void testGetKeys() {
    Set<DataQuery> queries = Sets.newHashSet();
    queries.add(of("foo"));
    queries.add(of("foo", "bar"));
    queries.add(of("foo", "bar", "baz"));
    queries.add(of("bar"));
    DataView view = DataContainer.createNew();
    view.set(of("foo"), "foo");
    view.set(of("foo", "bar"), "foobar");
    view.set(of("foo", "bar", "baz"), "foobarbaz");
    view.set(of("bar"), 1);
    Set<DataQuery> testQueries = Sets.newHashSet();
    testQueries.add(of("foo"));
    testQueries.add(of("bar"));
    Set<DataQuery> shallowKeys = view.getKeys(false);
    assertTrue(shallowKeys.equals(testQueries));
    Set<DataQuery> deepKeys = view.getKeys(true);
    assertTrue(deepKeys.containsAll(queries));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 74 with DataView

use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testNodeToData.

@Test
public void testNodeToData() {
    ConfigurationNode node = SimpleConfigurationNode.root();
    node.getNode("foo", "int").setValue(1);
    node.getNode("foo", "double").setValue(10.0D);
    node.getNode("foo", "long").setValue(Long.MAX_VALUE);
    List<String> stringList = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        stringList.add("String" + i);
    }
    node.getNode("foo", "stringList").setValue(stringList);
    List<SimpleData> dataList = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        dataList.add(new SimpleData(i, 10.0 + i, "String" + i, Collections.<String>emptyList()));
    }
    node.getNode("foo", "nested", "Data").setValue(dataList);
    DataContainer manual = DataContainer.createNew();
    manual.set(DataQuery.of("foo", "int"), 1).set(DataQuery.of("foo", "double"), 10.0D).set(DataQuery.of("foo", "long"), Long.MAX_VALUE).set(DataQuery.of("foo", "stringList"), stringList).set(DataQuery.of("foo", "nested", "Data"), dataList);
    DataView container = ConfigurateTranslator.instance().translate(node);
    assertTrue(manual.equals(container));
    ConfigurationNode translated = ConfigurateTranslator.instance().translate(container);
// assertTrue(node.equals(translated)); // TODO Pending Configurate equals implementation
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Test(org.junit.Test)

Example 75 with DataView

use of org.spongepowered.api.data.DataView 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)

Aggregations

DataView (org.spongepowered.api.data.DataView)100 DataContainer (org.spongepowered.api.data.DataContainer)30 DataQuery (org.spongepowered.api.data.DataQuery)24 ArrayList (java.util.ArrayList)21 Map (java.util.Map)17 List (java.util.List)13 Vector3i (com.flowpowered.math.vector.Vector3i)11 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11 UUID (java.util.UUID)10 Nullable (javax.annotation.Nullable)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)10 ImmutableList (com.google.common.collect.ImmutableList)8 IOException (java.io.IOException)8 Test (org.junit.Test)8 CatalogType (org.spongepowered.api.CatalogType)8 Path (java.nio.file.Path)7 DataTypeSerializer (org.lanternpowered.server.data.persistence.DataTypeSerializer)7 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)7 ImmutableMap (com.google.common.collect.ImmutableMap)6