Search in sources :

Example 1 with HomeData

use of org.spongepowered.test.myhomes.data.home.HomeData in project SpongeCommon by SpongePowered.

the class HomeDataBuilder method buildContent.

@Override
protected Optional<HomeData> buildContent(DataView container) throws InvalidDataException {
    if (!container.contains(MyHomes.HOMES))
        return Optional.empty();
    HomeData data = new HomeDataImpl();
    container.getView(MyHomes.HOMES.getQuery()).get().getKeys(false).forEach(name -> data.homes().put(name.toString(), container.getSerializable(name, Home.class).orElseThrow(InvalidDataException::new)));
    container.getSerializable(MyHomes.DEFAULT_HOME.getQuery(), Home.class).ifPresent(home -> {
        data.set(MyHomes.DEFAULT_HOME, home);
    });
    return Optional.of(data);
}
Also used : HomeData(org.spongepowered.test.myhomes.data.home.HomeData) ImmutableHomeData(org.spongepowered.test.myhomes.data.home.ImmutableHomeData) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) Home(org.spongepowered.test.myhomes.data.home.Home)

Example 2 with HomeData

use of org.spongepowered.test.myhomes.data.home.HomeData in project SpongeCommon by SpongePowered.

the class HomeDataImpl method fill.

// Only required on mutable implementations
@Override
public Optional<HomeData> fill(DataHolder dataHolder, MergeFunction overlap) {
    HomeData merged = overlap.merge(this, dataHolder.get(HomeData.class).orElse(null));
    this.defaultHome = merged.defaultHome().get();
    this.homes = merged.homes().get();
    return Optional.of(this);
}
Also used : HomeData(org.spongepowered.test.myhomes.data.home.HomeData) ImmutableHomeData(org.spongepowered.test.myhomes.data.home.ImmutableHomeData)

Aggregations

HomeData (org.spongepowered.test.myhomes.data.home.HomeData)2 ImmutableHomeData (org.spongepowered.test.myhomes.data.home.ImmutableHomeData)2 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 Home (org.spongepowered.test.myhomes.data.home.Home)1