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


Java DataContainer类代码示例

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


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

示例1: serializeInventory

import org.spongepowered.api.data.DataContainer; //导入依赖的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: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer toContainer() {
    return super.toContainer()
            .set(VigilateKeys.CAMERA, this.camera)
            .set(VigilateKeys.OLD_LOCATION_X, this.locX)
            .set(VigilateKeys.OLD_LOCATION_Y, this.locY)
            .set(VigilateKeys.OLD_LOCATION_Z, this.locZ)
            .set(VigilateKeys.OLD_LOCATION_WORLD, this.world)
            .set(VigilateKeys.OLD_GAME_MODE, this.gameMode)
            .set(VigilateKeys.OLD_IS_FLYING, this.isFlying)
            .set(VigilateKeys.OLD_AFFECTS_SPAWNING, this.affectsSpawning)
            .set(VigilateKeys.OLD_VANISH, this.vanish)
            .set(VigilateKeys.OLD_VANISH_PREVENTS_TARGETING, this.vanishPreventsTargeting)
            .set(VigilateKeys.OLD_VANISH_IGNORES_COLLISION, this.vanishIgnoresCollision)
            .set(VigilateKeys.OLD_FLYING_SPEED, this.flyingSpeed);
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:17,代码来源:ImmutableViewerDataManipulator.java

示例3: makeSpongeStack

import org.spongepowered.api.data.DataContainer; //导入依赖的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.DataContainer; //导入依赖的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: serialize

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
public static DataContainer serialize(VirtualChestPlugin plugin, VirtualChestItem item) throws InvalidDataException
{
    DataContainer container = new MemoryDataContainer();
    container.set(ITEM, item.serializedStack);
    item.primaryAction.getObjectForSerialization().ifPresent(o -> container.set(PRIMARY_ACTION, o));
    item.secondaryAction.getObjectForSerialization().ifPresent(o -> container.set(SECONDARY_ACTION, o));
    if (!item.requirements.getFirst().isEmpty())
    {
        container.set(REQUIREMENTS, item.requirements.getFirst());
    }
    if (!item.ignoredPermissions.isEmpty())
    {
        container.set(IGNORED_PERMISSIONS, item.ignoredPermissions);
    }
    return container;
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:17,代码来源:VirtualChestItem.java

示例6: VirtualChestActionDispatcher

import org.spongepowered.api.data.DataContainer; //导入依赖的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

示例7: loadZones

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
/**
 * Loads zones from save files.
 *
 * @throws IOException
 */
public static void loadZones() throws IOException {
    File dir = new File(parentDirectory.getAbsolutePath() + "/zones");
    if (dir.exists()) {
        Files.walk(Paths.get(parentDirectory.getAbsolutePath() + "/zones")).forEach(filePath -> {
            if (Files.isRegularFile(filePath) && filePath.toString().endsWith(".json")) {
                try {
                    FileReader reader = new FileReader(filePath.toString());
                    JsonObject json = new JsonParser().parse(reader).getAsJsonObject();

                    // Convert to a data container
                    DataContainer data = DataUtil.jsonToDataContainer(json);

                    // Create a zone
                    zoneManager.add(Zone.from(data));

                    reader.close();
                } catch (Exception e) {
                    logger.error("Json Exception for file " + filePath.toString());
                    e.printStackTrace();
                }
            }
        });
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:30,代码来源:SafeGuard.java

示例8: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer toContainer() {
    List<String> ownerContainers = new ArrayList<String>();
    for (GameProfile profile : owners) {
        ownerContainers.add(profile.getUniqueId().toString());
    }

    DataContainer data = new MemoryDataContainer();
    data.set(DataQueries.Uuid, uuid.toString());
    data.set(DataQueries.ZoneName, name);
    data.set(DataQueries.Owners, ownerContainers);
    data.set(DataQueries.ZonePermissions, permissions);

    // Zone permissions
    Map<String, DataContainer> profileMap = new HashMap<String, DataContainer>();
    for (Entry<GameProfile, ZonePermissions> entry : userPermissions.entrySet()) {
        profileMap.put(entry.getKey().getUniqueId().toString(), entry.getValue().toContainer());
    }

    data.set(DataQueries.UserPermissions, profileMap);

    // Volume
    data.set(DataQueries.Volume, volume.toContainer());

    return data;
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:27,代码来源:Zone.java

示例9: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer toContainer() {
    // Volume
    DataContainer data = new MemoryDataContainer();

    // Min Coord
    DataContainer minData = new MemoryDataContainer();
    minData.set(DataQueries.X, min.getX());
    minData.set(DataQueries.Y, min.getY());
    minData.set(DataQueries.Z, min.getZ());
    data.set(DataQueries.Min, minData);

    // Max Coord
    DataContainer maxData = new MemoryDataContainer();
    maxData.set(DataQueries.X, max.getX());
    maxData.set(DataQueries.Y, max.getY());
    maxData.set(DataQueries.Z, max.getZ());
    data.set(DataQueries.Max, maxData);

    // World
    data.set(DataQueries.World, extent.getUniqueId().toString());

    return data;
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:25,代码来源:CuboidVolume.java

示例10: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer toContainer() {
    final DataContainer container = DataContainer.createNew()
            .set(UNIQUE_ID, this.uniqueId.toString());
    if (this.name != null) {
        container.set(NAME, this.name);
    }
    if (!this.properties.isEmpty()) {
        final DataContainer propertiesMap = DataContainer.createNew();
        for (String key : this.properties.keySet()) {
            final List<DataContainer> entries = new ArrayList<>();
            for (ProfileProperty property : this.properties.get(key)) {
                final DataContainer entry = DataContainer.createNew()
                        .set(VALUE, property.getValue());
                property.getSignature().ifPresent(signature -> entry.set(SIGNATURE, signature));
                entries.add(entry);
            }
            propertiesMap.set(DataQuery.of(key), entries);
        }
        container.set(PROPERTIES, propertiesMap);
    }
    return container;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:24,代码来源:LanternGameProfile.java

示例11: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer toContainer() {
	DataContainer container = new MemoryDataContainer();
	if (restrictions != null) {
		container = container.set(NKeys.CUSTOM_ITEM_DATA_RESTRICTIONS.getQuery(), this.restrictions);
	}
	if (enchantements != null) {
		container = container.set(NKeys.CUSTOM_ITEM_DATA_ENCHANTEMENTS.getQuery(), this.enchantements);
	}
	if (itemLevel != null) {
		container = container.set(NKeys.CUSTOM_ITEM_DATA_ITEM_LEVEL.getQuery(), this.itemLevel);
	}

	if (rarity != null) {
		container = container.set(NKeys.ITEM_RARITY.getQuery(), this.rarity);
	}

	if (socketCount != null) {
		container = container.set(NKeys.CUSTOM_ITEM_DATA_SOCKET_COUNT.getQuery(), this.socketCount);
	}
	return container;
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:23,代码来源:CustomItemData.java

示例12: read

import org.spongepowered.api.data.DataContainer; //导入依赖的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

示例13: translate

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
public DataContainer translate(ConfigurationNode node) throws InvalidDataException {
    checkNotNull(node, "node");
    final DataContainer container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    final Object value = node.getValue();
    final Object key = node.getKey();
    if (value != null) {
        if (key == null || value instanceof Map || value instanceof List) {
            if (value instanceof Map) {
                //noinspection unchecked
                for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) value).entrySet()) {
                    container.set(DataQuery.of('.', entry.getKey().toString()), entry.getValue());
                }
            } else if (key != null) {
                container.set(DataQuery.of(key.toString()), value);
            }
        } else {
            container.set(DataQuery.of('.', key.toString()), value);
        }
    }
    return container;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:ConfigurateTranslator.java

示例14: toContainer

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
public static DataContainer toContainer(IValueContainer valueContainer) {
    final DataContainer dataContainer = DataContainer.createNew();
    final ValueCollection valueCollection = valueContainer.getValueCollection();
    final LanternDataManager dataManager = Lantern.getGame().getDataManager();
    for (KeyRegistration<?,?> registration : valueCollection.getAll()) {
        if (!(registration instanceof Element)) {
            continue;
        }
        final Key<?> key = registration.getKey();
        final DataQuery dataQuery = key.getQuery();
        final TypeToken<?> typeToken = key.getElementToken();
        final DataTypeSerializer typeSerializer = dataManager.getTypeSerializer(typeToken)
                .orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for the element type: " + typeToken.toString()));
        final DataTypeSerializerContext context = dataManager.getTypeSerializerContext();
        // The value's shouldn't be null inside a data manipulator,
        // since it doesn't support removal of values
        dataContainer.set(dataQuery, typeSerializer.serialize(typeToken, context,
                checkNotNull(((Element) registration).get(), "element")));
    }
    return dataContainer;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:DataHelper.java

示例15: setBlock

import org.spongepowered.api.data.DataContainer; //导入依赖的package包/类
@Override
    public void setBlock(WarLocation location, WarBlock block) {
        Location<World> sloc = getSpongeLocation(location);
        String blockName = block.getBlockName();
        // attempt to make blocks from Bukkit variant usable.
        if (!blockName.contains(":")) {
            blockName = "minecraft:" + blockName.toLowerCase();
        }
        Optional<BlockType> type = game.getRegistry().getType(BlockType.class, blockName);
        if (!type.isPresent()) {
            throw new IllegalStateException("Failed to get block type for block " + blockName);
        }
        if (block.getData() == null && !block.getSerialized().isEmpty()) {
            DataContainer container = translator.translateFrom(block.getSerialized());
            Optional<BlockSnapshot> build = BlockSnapshot.builder().build(container);
            if (build.isPresent()) {
                build.get().withLocation(sloc).restore(true, false);
            }
//                    .position(sloc.getBlockPosition())
//                    .world(sloc.getExtent().getProperties())
//                    .blockState(BlockState.builder().blockType(type.get()).build())
//                    .build().withContainer(container).restore(true, false);
        }
//        sloc.setBlockType(type.get(), false);
    }
 
开发者ID:cmastudios,项目名称:war-sponge,代码行数:26,代码来源:WarPlugin.java


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