Search in sources :

Example 86 with DataContainer

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

the class MemoryDataTest method testTest.

@Test
public void testTest() {
    DataContainer containertest = DataContainer.createNew();
    DataContainer containertest2 = DataContainer.createNew();
    containertest.set(DataQuery.of("test1", "test2", "test3"), containertest2);
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) Test(org.junit.Test)

Example 87 with DataContainer

use of org.spongepowered.api.data.DataContainer 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 88 with DataContainer

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

the class FakeSerializable method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = DataContainer.createNew();
    container.set(Queries.CONTENT_VERSION, getContentVersion());
    container.set(DataQuery.of("foo"), this.foo);
    container.set(DataQuery.of("myInt"), this.myInt);
    container.set(DataQuery.of("theDouble"), this.theDouble);
    container.set(DataQuery.of("nested", "compound"), this.nestedCompound);
    container.set(DataQuery.of("MyBoolean"), this.aBoolean);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 89 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeAPI by SpongePowered.

the class ColorTest method testToContainer.

// Ignored by dualspiral, 7th January 2018
// 
// Ignored as Sponge.getDataManager() will fail. It is expected that
// this will move to impl in API 8, thus not too concerned about fixing
// this as of yet.
@Test
@Ignore
public void testToContainer() {
    final Color colorGray = Color.GRAY;
    final Color.Builder builder = new Color.Builder();
    final DataContainer container = colorGray.toContainer();
    final Color deserialized = builder.build(container).get();
    assertTrue(colorGray.equals(deserialized));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 90 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeAPI by SpongePowered.

the class Location method toContainer.

@Override
public DataContainer toContainer() {
    final DataContainer container = DataContainer.createNew();
    container.set(Queries.CONTENT_VERSION, getContentVersion());
    if (getExtent() instanceof World) {
        container.set(Queries.WORLD_NAME, ((World) getExtent()).getName());
        container.set(Queries.WORLD_ID, getExtent().getUniqueId().toString());
    } else if (getExtent() instanceof Chunk) {
        container.set(Queries.CHUNK_X, ((Chunk) getExtent()).getPosition().getX()).set(Queries.CHUNK_Y, ((Chunk) getExtent()).getPosition().getY()).set(Queries.CHUNK_Z, ((Chunk) getExtent()).getPosition().getZ()).set(Queries.WORLD_NAME, ((Chunk) getExtent()).getWorld().getName()).set(Queries.WORLD_ID, ((Chunk) getExtent()).getWorld().getUniqueId().toString());
    }
    container.set(Queries.BLOCK_TYPE, this.getExtent().getBlockType(getBlockPosition()).getId()).set(Queries.POSITION_X, this.getX()).set(Queries.POSITION_Y, this.getY()).set(Queries.POSITION_Z, this.getZ());
    return container;
}
Also used : 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