当前位置: 首页>>代码示例>>Java>>正文


Java DataView类代码示例

本文整理汇总了Java中org.spongepowered.api.data.DataView的典型用法代码示例。如果您正苦于以下问题:Java DataView类的具体用法?Java DataView怎么用?Java DataView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataView类属于org.spongepowered.api.data包,在下文中一共展示了DataView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的org.spongepowered.api.data.DataView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。