use of org.spongepowered.test.myhomes.data.home.Home in project SpongeCommon by SpongePowered.
the class HomeDataImpl method from.
// Only required on mutable implementations
@Override
public Optional<HomeData> from(DataContainer container) {
if (!container.contains(MyHomes.DEFAULT_HOME, MyHomes.HOMES)) {
return Optional.empty();
}
// Loads the structure defined in toContainer
this.defaultHome = container.getSerializable(MyHomes.DEFAULT_HOME.getQuery(), Home.class).get();
// Loads the map of homes
this.homes = Maps.newHashMap();
DataView homes = container.getView(MyHomes.HOMES.getQuery()).get();
for (DataQuery homeQuery : homes.getKeys(false)) {
homes.getSerializable(homeQuery, Home.class).ifPresent(home -> this.homes.put(homeQuery.toString(), home));
}
return Optional.of(this);
}
use of org.spongepowered.test.myhomes.data.home.Home in project SpongeCommon by SpongePowered.
the class HomeBuilder method buildContent.
@Override
protected Optional<Home> buildContent(DataView content) throws InvalidDataException {
if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY, Home.ROTATION_QUERY, Home.NAME_QUERY)) {
return Optional.empty();
}
World world = Sponge.getServer().getWorld(content.getObject(Home.WORLD_QUERY, UUID.class).get()).orElseThrow(InvalidDataException::new);
Vector3d position = content.getObject(Home.POSITION_QUERY, Vector3d.class).get();
Vector3d rotation = content.getObject(Home.ROTATION_QUERY, Vector3d.class).get();
String name = content.getString(Home.NAME_QUERY).get();
Transform<World> transform = new Transform<>(world, position, rotation);
return Optional.of(new Home(transform, name));
}
use of org.spongepowered.test.myhomes.data.home.Home 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);
}
use of org.spongepowered.test.myhomes.data.home.Home in project SpongeCommon by SpongePowered.
the class HomeTranslator method translate.
@Override
public Home translate(final DataView content) throws InvalidDataException {
content.getInt(Queries.CONTENT_VERSION).ifPresent(version -> {
if (version != CONTENT_VERSION) {
throw new InvalidDataException("Version incompatible: " + version);
}
});
if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY, Home.ROTATION_QUERY, Home.NAME_QUERY)) {
throw new InvalidDataException("Incomplete data");
}
World world = Sponge.getServer().getWorld(content.getObject(Home.WORLD_QUERY, UUID.class).get()).orElseThrow(InvalidDataException::new);
Vector3d position = content.getObject(Home.POSITION_QUERY, Vector3d.class).get();
Vector3d rotation = content.getObject(Home.ROTATION_QUERY, Vector3d.class).get();
String name = content.getString(Home.NAME_QUERY).get();
Transform<World> transform = new Transform<>(world, position, rotation);
return new Home(transform, name);
}
Aggregations