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


Java Key.getElementToken方法代码示例

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


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

示例1: deserializeForKeys

import org.spongepowered.api.data.key.Key; //导入方法依赖的package包/类
private <T, U extends BaseValue<T>> void deserializeForKeys(
        ConfigurationNode node, DataQuery dataQuery, BiConsumer<Key<U>, T> consumer) throws InvalidDataException
{
    if (KEYS.containsKey(dataQuery))
    {
        try
        {
            @SuppressWarnings("unchecked")
            Key<U> key = (Key<U>) KEYS.get(dataQuery);
            @SuppressWarnings("unchecked")
            TypeToken<T> elementToken = (TypeToken<T>) key.getElementToken();
            consumer.accept(key, Optional.ofNullable(node.getValue(elementToken))
                    .orElseThrow(() -> new InvalidDataException("No value present")));
        }
        catch (ObjectMappingException e)
        {
            throw new InvalidDataException(e);
        }
    }
    else if (!EXCEPTIONS.contains(dataQuery))
    {
        throw new InvalidDataException("No matched query present");
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:25,代码来源:VirtualChestItemStackSerializer.java

示例2: toContainer

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

示例3: serializeRawRegisteredKeyData

import org.spongepowered.api.data.key.Key; //导入方法依赖的package包/类
public static void serializeRawRegisteredKeyData(DataView dataView, IValueContainer valueContainer,
        Set<Key> ignoredKeys) {
    DataView view = null;
    final ValueCollection valueCollection = valueContainer.getValueCollection();
    final LanternDataManager dataManager = Lantern.getGame().getDataManager();
    final DataTypeSerializerContext context = dataManager.getTypeSerializerContext();
    for (KeyRegistration<?,?> registration : valueCollection.getAll()) {
        final Key<?> key = registration.getKey();
        if (!(registration instanceof Element)
                || ignoredKeys.contains(key)
                || key == LanternKeys.FAILED_DATA_MANIPULATORS
                || key == LanternKeys.FAILED_DATA_VALUES) {
            continue;
        }
        final Element element = (Element) registration;
        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 Object object = element.get();
        if (object == null) {
            continue;
        }
        final Object value = typeSerializer.serialize(typeToken, context, object);
        if (view == null) {
            view = dataView.createView(DataQueries.DATA_VALUES);
        }
        view.set(key.getQuery(), value);
    }
    Element<DataView> holder = valueCollection.getElement(LanternKeys.FAILED_DATA_VALUES).orElse(null);
    if (holder != null) {
        if (view == null) {
            view = dataView.createView(DataQueries.DATA_VALUES);
        }
        for (Map.Entry<DataQuery, Object> entry : holder.get().getValues(false).entrySet()) {
            if (!view.contains(entry.getKey())) {
                view.set(entry.getKey(), entry.getValue());
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:42,代码来源:DataHelper.java


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