本文整理汇总了Java中org.spongepowered.api.data.DataView类的典型用法代码示例。如果您正苦于以下问题:Java DataView类的具体用法?Java DataView怎么用?Java DataView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataView类属于org.spongepowered.api.data包,在下文中一共展示了DataView类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: serializeInventory
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static List<DataView> serializeInventory(Inventory inventory) {
DataContainer container;
List<DataView> slots = new LinkedList<>();
int i = 0;
Optional<ItemStack> stack;
for (Inventory inv : inventory.slots()) {
stack = inv.peek();
if (stack.isPresent()) {
container = new org.spongepowered.api.data.MemoryDataContainer();
container.set(SLOT, i);
container.set(STACK, serializeItemStack(stack.get()));
slots.add(container);
}
i++;
}
return slots;
}
开发者ID:AuraDevelopmentTeam,项目名称:InvSync,代码行数:26,代码来源:InventorySerializer.java
示例2: buildContent
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
protected Optional<ViewerData> buildContent(DataView dataView) {
return Optional.of(new ViewerData(
dataView.getString(VigilateKeys.CAMERA.getQuery()).orElse(""),
dataView.getString(VigilateKeys.OLD_LOCATION_WORLD.getQuery()).orElse("world"),
dataView.getDouble(VigilateKeys.OLD_LOCATION_X.getQuery()).orElse(0.0),
dataView.getDouble(VigilateKeys.OLD_LOCATION_Y.getQuery()).orElse(0.0),
dataView.getDouble(VigilateKeys.OLD_LOCATION_Z.getQuery()).orElse(0.0),
dataView.getCatalogType(VigilateKeys.OLD_GAME_MODE.getQuery(), CatalogTypes.GAME_MODE).orElse(GameModes.NOT_SET),
dataView.getBoolean(VigilateKeys.OLD_IS_FLYING.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_AFFECTS_SPAWNING.getQuery()).orElse(true),
dataView.getBoolean(VigilateKeys.OLD_VANISH.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_VANISH_PREVENTS_TARGETING.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_VANISH_IGNORES_COLLISION.getQuery()).orElse(false),
dataView.getDouble(VigilateKeys.OLD_FLYING_SPEED.getQuery()).orElse(0.02)
));
}
开发者ID:Lergin,项目名称:Vigilate,代码行数:19,代码来源:ViewerDataManipulatorBuilder.java
示例3: makeSpongeStack
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
.orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
.orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
view.set(DATA_VALUE, baseItemStack.getData());
store.deserialize(itemStack, view);
final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
if (!enchantments.isEmpty()) {
itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
.map(entry -> {
final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
.orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
return new ItemEnchantment(enchantment, entry.getValue());
})
.collect(Collectors.toList()));
}
return itemStack;
}
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:23,代码来源:LanternImplAdapter.java
示例4: from
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
private static Object from(Tag tag, @Nullable DataView view) {
if (tag instanceof CompoundTag) {
final Map<String, Tag> map = ((CompoundTag) tag).getValue();
if (view == null) {
view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
}
for (Map.Entry<String, Tag> entry : map.entrySet()) {
if (entry.getValue() instanceof CompoundTag) {
from(tag, view.createView(DataQuery.of(entry.getKey())));
} else {
view.set(DataQuery.of(entry.getKey()), from(entry.getValue(), null));
}
}
return view;
} else if (tag instanceof ListTag) {
return ((ListTag) tag).getValue().stream().map(entry -> from(entry, null)).collect(Collectors.toList());
}
return tag.getValue();
}
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:20,代码来源:DataViewNbt.java
示例5: deserialize
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
public static VirtualChestItem deserialize(VirtualChestPlugin plugin, DataView data) throws InvalidDataException
{
DataView serializedStack = data.getView(ITEM).orElseThrow(() -> new InvalidDataException("Expected Item"));
String requirementString = data.getString(REQUIREMENTS).orElse("");
Tuple<String, CompiledScript> requirements = plugin.getScriptManager().prepare(requirementString);
List<DataView> primaryList = getViewListOrSingletonList(PRIMARY_ACTION, data);
VirtualChestActionDispatcher primaryAction = new VirtualChestActionDispatcher(primaryList);
List<DataView> secondaryList = getViewListOrSingletonList(SECONDARY_ACTION, data);
VirtualChestActionDispatcher secondaryAction = new VirtualChestActionDispatcher(secondaryList);
List<DataView> primaryShiftList = getViewListOrSingletonList(PRIMARY_SHIFT_ACTION, data);
List<DataView> primaryShiftListFinal = primaryShiftList.isEmpty() ? primaryList : primaryShiftList;
VirtualChestActionDispatcher primaryShiftAction = new VirtualChestActionDispatcher(primaryShiftListFinal);
List<DataView> secondaryShiftList = getViewListOrSingletonList(SECONDARY_SHIFT_ACTION, data);
List<DataView> secondaryShiftListFinal = secondaryShiftList.isEmpty() ? secondaryList : secondaryShiftList;
VirtualChestActionDispatcher secondaryShiftAction = new VirtualChestActionDispatcher(secondaryShiftListFinal);
List<String> ignoredPermissions = data.getStringList(IGNORED_PERMISSIONS).orElse(ImmutableList.of());
return new VirtualChestItem(plugin, serializedStack, requirements,
primaryAction, secondaryAction, primaryShiftAction, secondaryShiftAction, ignoredPermissions);
}
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:27,代码来源:VirtualChestItem.java
示例6: VirtualChestItem
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
private VirtualChestItem(
VirtualChestPlugin plugin,
DataView serializedStack,
Tuple<String, CompiledScript> requirements,
VirtualChestActionDispatcher primaryAction,
VirtualChestActionDispatcher secondaryAction,
VirtualChestActionDispatcher primaryShiftAction,
VirtualChestActionDispatcher secondaryShiftAction,
List<String> ignoredPermissions)
{
this.plugin = plugin;
this.serializer = new VirtualChestItemStackSerializer(plugin);
this.serializedStack = serializedStack;
this.requirements = requirements;
this.primaryAction = primaryAction;
this.secondaryAction = secondaryAction;
this.primaryShiftAction = primaryShiftAction;
this.secondaryShiftAction = secondaryShiftAction;
this.ignoredPermissions = ignoredPermissions;
}
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:22,代码来源:VirtualChestItem.java
示例7: VirtualChestActionDispatcher
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
public VirtualChestActionDispatcher(List<DataView> views)
{
this.size = views.size();
ImmutableList.Builder<VirtualChestItemTemplateWithCount> handheldItemBuilder = ImmutableList.builder();
ImmutableList.Builder<Boolean> keepInventoryOpenBuilder = ImmutableList.builder();
ImmutableList.Builder<List<String>> commandsBuilder = ImmutableList.builder();
ImmutableList.Builder<DataContainer> dataContainerBuilder = ImmutableList.builder();
for (DataView view : views)
{
handheldItemBuilder.add(this.parseHandheldItem(view.getView(HANDHELD_ITEM)));
commandsBuilder.add(parseCommand(view.getString(COMMAND).orElse("")));
keepInventoryOpenBuilder.add(view.getBoolean(KEEP_INVENTORY_OPEN).orElse(false));
dataContainerBuilder.add(view.copy());
}
this.commands = commandsBuilder.build();
this.handheldItem = handheldItemBuilder.build();
this.keepInventoryOpen = keepInventoryOpenBuilder.build();
this.views = dataContainerBuilder.build();
}
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:26,代码来源:VirtualChestActionDispatcher.java
示例8: from
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
public static Volume from(DataView data) throws Exception {
int minX = data.getInt(DataQueries.Min.then(DataQueries.X)).get();
int minY = data.getInt(DataQueries.Min.then(DataQueries.Y)).get();
int minZ = data.getInt(DataQueries.Min.then(DataQueries.Z)).get();
Vector3i min = new Vector3i(minX, minY, minZ);
int maxX = data.getInt(DataQueries.Max.then(DataQueries.X)).get();
int maxY = data.getInt(DataQueries.Max.then(DataQueries.Y)).get();
int maxZ = data.getInt(DataQueries.Max.then(DataQueries.Z)).get();
Vector3i max = new Vector3i(maxX, maxY, maxZ);
// @todo where are these quotes coming from...
UUID worldUuid = UUID.fromString(data.getString(DataQueries.World).get().replace("\"", ""));
Optional<World> world = SafeGuard.getGame().getServer().getWorld(worldUuid);
if (!world.isPresent()) {
throw new Exception("Invalid volume data: world");
}
return new CuboidVolume(world.get(), min, max);
}
开发者ID:prism,项目名称:SafeGuard,代码行数:22,代码来源:CuboidVolume.java
示例9: registerAll
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
public static void registerAll() {
// AnnointmentFlagData
Sponge.getDataManager().register(AnnointmentFlagData.class,
ImmutableAnnointmentFlagData.class,
new DataManipulatorBuilder<AnnointmentFlagData, ImmutableAnnointmentFlagData>() {
@Override
public Optional<AnnointmentFlagData> build(
DataView container) throws InvalidDataException {
return AnnointmentFlagData.from(container);
}
@Override
public AnnointmentFlagData create() {
return new AnnointmentFlagData(
EnumSet.noneOf(AnnointmentFlag.class));
}
@Override
public Optional<AnnointmentFlagData>
createFrom(DataHolder dataHolder) {
return AnnointmentFlagData.from(dataHolder);
}
});
// END AnnointmentFlagData
}
开发者ID:kenzierocks,项目名称:Annointment,代码行数:27,代码来源:AnnointmentDataManager.java
示例10: buildContent
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
protected Optional<FlagMapDataImpl> buildContent(DataView container) throws InvalidDataException {
Integer version = (Integer) container.get(Queries.CONTENT_VERSION).get();
if (version != 1) {
return Optional.empty();
}
Optional<DataView> dv = container.getView(FlagHelper.FLAGMAP.getQuery());
if (!dv.isPresent()) {
return Optional.empty();
}
Optional<String> str = dv.get().getString(FlagMap.FLAG);
if (!str.isPresent()) {
return Optional.empty();
}
String val = str.get();
MapTag mt = (MapTag) Denizen2Core.loadFromSaved((e) -> {
throw new InvalidDataException("Denizen2: " + e);
}, val);
return Optional.of(new FlagMapDataImpl(new FlagMap(mt)));
}
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:21,代码来源:FlagMapDataBuilder.java
示例11: buildContent
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected Optional<CustomInventoryData> buildContent(DataView container) throws InvalidDataException {
if(!container.contains(CUSTOM_INVENTORY_ID, CUSTOM_INVENTORY_SLOT_ID_TO_ITEMSTACK,
CUSTOM_INVENTORY_SLOT_ID_TO_FEATURE_ID)) {
return Optional.empty();
}
Optional<String> id = container.getString(CUSTOM_INVENTORY_ID.getQuery());
if(!id.isPresent())
throw new InvalidDataException("Could not access the ID of the inventory data.");
val slotIdToItemStack = (Map<String, ItemStackSnapshot>) container.getMap(
CUSTOM_INVENTORY_SLOT_ID_TO_ITEMSTACK.getQuery()
).orElse(null);
val slotIdToFeatureId = (Map<String, String>) container.getMap(
CUSTOM_INVENTORY_SLOT_ID_TO_FEATURE_ID.getQuery()
).orElse(null);
return Optional.of(new CustomInventoryData(id.get(), slotIdToItemStack, slotIdToFeatureId));
}
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:24,代码来源:CustomInventoryDataBuilder.java
示例12: writeTo
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public void writeTo(DataView data) {
DataList<DataView> blockList = Utils.createListView();
for (Entry<Vector3i, BlockNature> entry : this.trackedBlocks.entrySet()) {
DataView blockDataView = blockList.next();
Vector3i pos = entry.getKey();
BlockNature block = entry.getValue();
blockDataView.set(of("position"), pos);
DataView blockView = blockDataView.createView(of("block"));
blockView.set(of("id"), block.getId());
block.writeDataAt(this, pos, blockView);
BlockData blockData = this.trackedBlockData.get(pos);
if (blockData != null) {
blockDataView.set(of("blockData"), blockData);
}
}
data.set(of("blocks"), blockList.getList());
DataList<DataView> entityList = Utils.createListView();
for (CustomEntity customEntity : this.trackedCustomEntities) {
customEntity.writeTo(entityList.next());
}
data.set(of("entities"), entityList.getList());
}
开发者ID:simon816,项目名称:Industrialization,代码行数:24,代码来源:WorldManager.java
示例13: readFrom
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public void readFrom(DataView data) {
super.readFrom(data);
this.tracker.readFrom(this.world, data);
this.pickaxeStand = (ArmorStand) this.tracker.get("toolStand");
this.block.setStand((ArmorStand) this.tracker.get("blockStand"));
FallingBlock falling = (FallingBlock) this.tracker.get("blockEntity");
this.block.setEntity(falling, false);
if (falling != null) {
// Vanilla serializes this as a byte so we need to set it back to Integer.MIN_VALUE
falling.offer(Keys.FALL_TIME, Integer.MIN_VALUE);
}
this.task.readFrom(data.getView(of("task")).get());
}
开发者ID:simon816,项目名称:Industrialization,代码行数:17,代码来源:TurtleEntity.java
示例14: read
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public ItemStack read(ByteBuffer buf) throws CodecException {
final RawItemStack rawItemStack = buf.read(Types.RAW_ITEM_STACK);
//noinspection ConstantConditions
if (rawItemStack == null) {
return null;
}
final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(rawItemStack.getItemType()).orElse(null);
if (itemType == null) {
return null;
}
final LanternItemStack itemStack = new LanternItemStack(itemType, rawItemStack.getAmount());
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(ItemStackStore.DATA, rawItemStack.getData());
dataView.set(ItemStackStore.QUANTITY, rawItemStack.getAmount());
final DataView tag = rawItemStack.getDataView();
if (tag != null) {
dataView.set(ItemStackStore.TAG, tag);
}
this.store.deserialize(itemStack, dataView);
return itemStack;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:Types.java
示例15: serialize
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<DataView> serialize(TypeToken<?> type, DataTypeSerializerContext ctx, Multimap<?, ?> obj) throws InvalidDataException {
final TypeToken<?> keyType = type.resolveType(this.keyTypeVariable);
final TypeToken<?> valueType = type.resolveType(this.valueTypeVariable);
final DataTypeSerializer keySerial = ctx.getSerializers().getTypeSerializer(keyType)
.orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for: " + keyType.toString()));
final DataTypeSerializer valueSerial = ctx.getSerializers().getTypeSerializer(valueType)
.orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for: " + valueType.toString()));
final List<DataView> dataViews = new ArrayList<>();
for (Object key : obj.keySet()) {
final DataContainer dataContainer = DataContainer.createNew();
dataContainer.set(KEY, keySerial.serialize(keyType, ctx, key));
final Collection<Object> values = ((Multimap) obj).get(key);
if (values.size() == 1) {
dataContainer.set(VALUE, valueSerial.serialize(valueType, ctx, values.iterator().next()));
} else {
dataContainer.set(ENTRIES, values.stream().map(v -> valueSerial.serialize(valueType, ctx, v)).collect(Collectors.toList()));
}
dataViews.add(dataContainer);
}
return dataViews;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:24,代码来源:DataTypeSerializers.java
示例16: readLimitedDataView
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Nullable
@Override
public DataView readLimitedDataView(int maximumDepth, int maxBytes) {
final int index = this.buf.readerIndex();
if (this.buf.readByte() == 0) {
return null;
}
this.buf.readerIndex(index);
try {
try (NbtDataContainerInputStream input = new NbtDataContainerInputStream(
new LimitInputStream(new ByteBufInputStream(this.buf), maxBytes), false, maximumDepth)) {
return input.read();
}
} catch (IOException e) {
throw new CodecException(e);
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LanternByteBuffer.java
示例17: deserialize
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Map<?, ?> deserialize(TypeToken<?> type, DataTypeSerializerContext ctx, List<DataView> entries) throws InvalidDataException {
final TypeToken<?> keyType = type.resolveType(this.keyTypeVariable);
final TypeToken<?> valueType = type.resolveType(this.valueTypeVariable);
final DataTypeSerializer keySerial = ctx.getSerializers().getTypeSerializer(keyType)
.orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for: " + keyType.toString()));
final DataTypeSerializer valueSerial = ctx.getSerializers().getTypeSerializer(valueType)
.orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for: " + valueType.toString()));
final Map map = new HashMap<>();
for (DataView entry : entries) {
final Object key = keySerial.deserialize(type, ctx, entry.get(KEY)
.orElseThrow(() -> new InvalidDataException("Entry is missing a key.")));
final Object value = valueSerial.deserialize(type, ctx, entry.get(VALUE)
.orElseThrow(() -> new InvalidDataException("Entry is missing a value.")));
map.put(key, value);
}
return map;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:DataTypeSerializers.java
示例18: getIntArray
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
/**
* Attempts to get a int array from the {@link DataView}
* for the specific {@link DataQuery} path.
*
* @param dataView The data view
* @param path The path
* @return The int array
*/
public static Optional<int[]> getIntArray(DataView dataView, DataQuery path) {
final Optional<Object> optObject = dataView.get(path);
if (optObject.isPresent() && optObject.get() instanceof int[]) {
return (Optional) optObject;
}
return dataView.getIntegerList(path).map(list -> {
if (list instanceof IntList) {
return ((IntList) list).toIntArray();
}
final int[] array = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
return array;
});
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java
示例19: translate
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public LocalDate translate(DataView view) throws InvalidDataException {
final int year = view.getInt(DataQueries.LOCAL_DATE_YEAR).orElseThrow(invalidDataQuery(DataQueries.LOCAL_DATE_YEAR));
final int month = view.getInt(DataQueries.LOCAL_DATE_MONTH).orElseThrow(invalidDataQuery(DataQueries.LOCAL_DATE_MONTH));
final int day = view.getInt(DataQueries.LOCAL_DATE_DAY).orElseThrow(invalidDataQuery(DataQueries.LOCAL_DATE_DAY));
if (!ChronoField.YEAR.range().isValidValue(year)) {
throw new InvalidDataException("Invalid year: " + year);
}
if (!ChronoField.MONTH_OF_YEAR.range().isValidValue(month)) {
throw new InvalidDataException("Invalid month of year: " + month);
}
if (!ChronoField.DAY_OF_MONTH.range().isValidValue(day)) {
throw new InvalidDataException("Invalid day of month: " + day);
}
return LocalDate.of(year, month, day);
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:DataTranslators.java
示例20: deserializeValues
import org.spongepowered.api.data.DataView; //导入依赖的package包/类
@Override
public void deserializeValues(ItemStack itemStack, SimpleValueContainer valueContainer, DataView dataView) {
super.deserializeValues(itemStack, valueContainer, dataView);
final Optional<Integer> dataValue = dataView.getInt(DATA_VALUE);
if (dataValue.isPresent()) {
int internalId = dataValue.get();
if (this.dataValueToInternalId != null) {
internalId = this.dataValueToInternalId.apply(internalId);
}
final Optional<T> catalogType = this.registryModule.getByInternalId(internalId);
if (catalogType.isPresent()) {
valueContainer.set(this.key, catalogType.get());
} else {
Lantern.getLogger().warn("Deserialize an unknown catalog type {} with internal id {}",
this.key.getElementToken(), internalId);
}
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:DataValueItemTypeObjectSerializer.java
注:本文中的org.spongepowered.api.data.DataView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论