private void copyDataView(DataQuery path, DataView value) { Collection<DataQuery> valueKeys = value.getKeys(true); for (DataQuery oldKey : valueKeys) { set(path.then(oldKey), value.get(oldKey).get()); } }
private Optional<Text> findText(DataView container, DataQuery query) { if (container.contains(query)) { return Optional.of(getText(container.get(query).get())); } return Optional.empty(); }
public DataView formatBlockData(DataView finalBlock, @Nonnull Object optionalLocation) { Preconditions.checkNotNull(optionalLocation, "The location you are formatting cannot be null."); DataView location = (DataView) optionalLocation; DataView position = DataContainer.createNew(); position.set(DataQueries.X, location.get(DataQueries.X).get()); position.set(DataQueries.Y, location.get(DataQueries.Y).get()); position.set(DataQueries.Z, location.get(DataQueries.Z).get()); finalBlock.set(DataQueries.Position, position); finalBlock.set(DataQueries.WorldUuid, location.get(DataQueries.WorldUuid).get()); int blockStateVersion = finalBlock.getInt(DataQueries.BlockState.then(DataQueries.ContentVersion)).orElse(1); if (blockStateVersion == 1) { // Unsafe data includes coordinates Optional<Object> optionalUnsafeData = finalBlock.get(DataQueries.UnsafeData); if (optionalUnsafeData.isPresent()) { DataView unsafeData = (DataView) optionalUnsafeData.get(); unsafeData.set(DataQueries.X, location.get(DataQueries.X).get()); unsafeData.set(DataQueries.Y, location.get(DataQueries.Y).get()); unsafeData.set(DataQueries.Z, location.get(DataQueries.Z).get()); finalBlock.set(DataQueries.UnsafeData, unsafeData); } } return finalBlock; }
private void copyDataView(DataQuery path, DataView value) { Collection<DataQuery> valueKeys = value.getKeys(true); for (DataQuery oldKey : valueKeys) { set(path.then(oldKey), value.get(oldKey).get()); } }
int y = location.getInt(DataQueries.Y).orElse(0); int z = location.getInt(DataQueries.Z).orElse(0); World world = location.get(DataQueries.WorldUuid).flatMap(TypeUtil::uuidFromObject).flatMap(Sponge.getServer()::getWorld).orElse(null);
@Override protected Optional<Text> buildContent(DataView container) throws InvalidDataException { try { return container.get(Queries.JSON).map(json -> TextSerializers.JSON.deserialize(json.toString())); } catch (TextParseException e) { throw new InvalidDataException(e); } }
Optional<Object> optional = view.get(query); if (optional.isPresent()) { String key = query.asString(".");
@Override protected Optional<BookView> buildContent(DataView container) throws InvalidDataException { BookView.Builder builder = BookView.builder(); findText(container, TEXT_TITLE).ifPresent(builder::title); findText(container, TEXT_AUTHOR).ifPresent(builder::author); if (container.contains(TEXT_PAGE_LIST)) { Object pageList = container.get(TEXT_PAGE_LIST).get(); if (!(pageList instanceof List)) { throw new InvalidDataException("Expected List"); } ((List<?>) pageList).forEach(textView -> builder.addPage(getText(textView))); } return Optional.of(builder.build()); }
Optional<Object> optional = view.get(query); if (optional.isPresent()) { String key = query.asString(".");
return subView.get(path.popFirst());
data.set(key, extra.get(key).get());
private Optional<Text> findText(DataView container, DataQuery query) { if (container.contains(query)) { return Optional.of(getText(container.get(query).get())); } return Optional.empty(); }
data.set(key, extra.get(key).get());
@Override protected Optional<Text> buildContent(DataView container) throws InvalidDataException { try { return container.get(Queries.JSON).map(json -> TextSerializers.JSON.deserialize(json.toString())); } catch (TextParseException e) { throw new InvalidDataException(e); } }
@Override protected Optional<BookView> buildContent(DataView container) throws InvalidDataException { BookView.Builder builder = BookView.builder(); findText(container, TEXT_TITLE).ifPresent(builder::title); findText(container, TEXT_AUTHOR).ifPresent(builder::author); if (container.contains(TEXT_PAGE_LIST)) { Object pageList = container.get(TEXT_PAGE_LIST).get(); if (!(pageList instanceof List)) { throw new InvalidDataException("Expected List"); } ((List<?>) pageList).forEach(textView -> builder.addPage(getText(textView))); } return Optional.of(builder.build()); }
return subView.get(path.popFirst());