Search in sources :

Example 41 with DataContainer

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

the class ConfigurateDataViewTest method testEmptyNodeToData.

@Test
void testEmptyNodeToData() {
    final ConfigurationNode source = BasicConfigurationNode.root();
    final DataContainer container = ConfigurateTranslator.instance().translate(source);
    assertTrue(container.isEmpty());
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 42 with DataContainer

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

the class ConfigurateDataViewTest method testRespawnLocationData.

@Test
void testRespawnLocationData() throws IOException {
    final Map<ResourceKey, RespawnLocation> m = new HashMap<>();
    for (int i = 0; i < 5; i++) {
        final ResourceKey key = ResourceKey.sponge("overworld" + i);
        final RespawnLocation loc = RespawnLocation.builder().world(key).position(Vector3d.ZERO).build();
        m.put(key, loc);
    }
    final DataContainer container = DataContainer.createNew().set(DataQuery.of("respawn_locations"), m);
    final ConfigurationNode node = ConfigurateTranslator.instance().translate(container);
    final DataContainer dc = ConfigurateTranslator.instance().translate(node);
    assertEquals(container, dc);
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) RespawnLocation(org.spongepowered.api.util.RespawnLocation) HashMap(java.util.HashMap) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ResourceKey(org.spongepowered.api.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 43 with DataContainer

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

the class SimpleData method toContainer.

@Override
public DataContainer toContainer() {
    final DataContainer container = DataContainer.createNew();
    container.set(DataQuery.of("myInt"), this.testInt);
    container.set(DataQuery.of("myDouble"), this.testDouble);
    container.set(DataQuery.of("myString"), this.testString);
    container.set(DataQuery.of("myStringList"), Arrays.asList(this.testList));
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Aggregations

DataContainer (org.spongepowered.api.data.persistence.DataContainer)43 ResourceKey (org.spongepowered.api.ResourceKey)14 DataView (org.spongepowered.api.data.persistence.DataView)12 CompoundTag (net.minecraft.nbt.CompoundTag)9 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DataQuery (org.spongepowered.api.data.persistence.DataQuery)7 BasicConfigurationNode (org.spongepowered.configurate.BasicConfigurationNode)7 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)7 ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)7 Optional (java.util.Optional)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 Map (java.util.Map)5 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Sponge (org.spongepowered.api.Sponge)5 DataTranslator (org.spongepowered.api.data.persistence.DataTranslator)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Collection (java.util.Collection)4 DataManager (org.spongepowered.api.data.DataManager)4