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


Java Key类代码示例

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


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

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
    Entity entity = entityTag.getInternal();
    MapTag propertyMap = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    for (Map.Entry<String, AbstractTagObject> mapEntry : propertyMap.getInternal().entrySet()) {
        if (mapEntry.getKey().equalsIgnoreCase("rotation")) {
            LocationTag rot = LocationTag.getFor(queue.error, mapEntry.getValue());
            entity.setRotation(rot.getInternal().toVector3d());
        }
        else {
            Key found = DataKeys.getKeyForName(mapEntry.getKey());
            if (found == null) {
                queue.handleError(entry, "Invalid property '" + mapEntry.getKey() + "' in EditEntity command!");
                return;
            }
            DataKeys.tryApply(entity, found, mapEntry.getValue(), queue.error);
        }
    }
    if (queue.shouldShowGood()) {
        queue.outGood("Edited the entity "
                + ColorSet.emphasis + entityTag.debug() + ColorSet.good
                + " to have the following properties: "
                + ColorSet.emphasis + propertyMap.debug());
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:27,代码来源:EditEntityCommand.java

示例3: getAllKeys

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
public static MapTag getAllKeys(DataHolder dataHolder) {
    MapTag temp = new MapTag();
    updateKeys();
    for (Key key : keys) {
        if (!dataHolder.supports(key)) {
            continue;
        }
        if (dataHolder.getOrNull(key) == null) {
            // Nope nope nope!
            continue;
        }
        AbstractTagObject ato = getValue(dataHolder, key, (s) -> {
            Debug.error("Failed to read key '" + key.getId() + "': " + s);
        });
        if (ato != null && !(ato instanceof NullTag)) {
            temp.getInternal().put(key.getId(), ato);
        }
    }
    return temp;
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:21,代码来源:DataKeys.java

示例4: parse

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <B extends BaseValue<T>, T> KeyValue<B, T> parse(String key_string, ConfigurationNode value) throws IllegalArgumentException {
	
	if (!key_string.contains(":")) {
		key_string = "sponge:" + key_string;
	}
	
	Optional<Key> optKey = Sponge.getGame().getRegistry().getType(Key.class, key_string);
	if (!optKey.isPresent()) throw new IllegalArgumentException();
	Key<B> key = optKey.get();
	
	try {
		return new KeyValue<B, T>(key, UtilsKeys.get((TypeToken<T>) key.getElementToken(), value));
	} catch (Exception e) {
		throw new IllegalArgumentException();
	}
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:18,代码来源:UtilsKeys.java

示例5: tryPlace

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
public BehaviorResult tryPlace(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
    final BlockSnapshot.Builder builder = BlockSnapshotBuilder.createPositionless();
    final Optional<ItemStack> optItem = context.getContext(ContextKeys.USED_ITEM_STACK);
    if (optItem.isPresent()) {
        builder.blockState(optItem.get().getType().getBlock().get().getDefaultState());
        optItem.get().getValues().forEach(value -> builder.add((Key) value.getKey(), value.get()));
    } else {
        final Optional<BlockState> optState = context.getContext(ContextKeys.USED_BLOCK_STATE);
        if (optState.isPresent()) {
            builder.blockState(optState.get());
        } else {
            throw new IllegalStateException();
        }
    }
    context.populateBlockSnapshot(builder, BehaviorContext.PopulationFlags.CREATOR | BehaviorContext.PopulationFlags.NOTIFIER);
    context.addContext(ContextKeys.BLOCK_SNAPSHOT, builder.build());
    return BehaviorResult.CONTINUE;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:BlockSnapshotProviderPlaceBehavior.java

示例6: deserializeEnchantments

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
private void deserializeEnchantments(DataView dataView, DataQuery query, Key<ListValue<Enchantment>> key,
        SimpleValueContainer valueContainer) {
    dataView.getViewList(query).ifPresent(views -> {
        if (!views.isEmpty()) {
            final List<Enchantment> enchantments = new ArrayList<>();
            views.forEach(view -> {
                final Optional<EnchantmentType> enchantmentType = EnchantmentTypeRegistryModule.get()
                        .getByInternalId(view.getInt(ENCHANTMENT_ID).get());
                if (enchantmentType.isPresent()) {
                    final int level = view.getInt(ENCHANTMENT_LEVEL).get();
                    enchantments.add(Enchantment.of(enchantmentType.get(), level));
                } else {
                    Lantern.getLogger().warn("Attempted to deserialize a enchantment with unknown id: {}", view.getInt(ENCHANTMENT_ID).get());
                }
            });
            valueContainer.set(key, enchantments);
        }
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:ItemStackStore.java

示例7: transform

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
public <E> M transform(Key<? extends BaseValue<E>> key, Function<E, E> function) {
    checkNotNull(key, "key");
    checkNotNull(function, "function");

    // Check the local key registration
    final KeyRegistration<BaseValue<E>, E> localKeyRegistration = getValueCollection().get(key).orElse(null);
    if (localKeyRegistration != null) {
        return transformWith(function, (Processor<BaseValue<E>, E>) localKeyRegistration);
    }

    // Check for a global registration
    final Optional<ValueProcessorKeyRegistration<BaseValue<E>, E>> globalRegistration = LanternValueFactory.get().getKeyRegistration(key);
    if (globalRegistration.isPresent()) {
        return transformWith(function, (Processor<BaseValue<E>, E>) globalRegistration.get());
    }

    throwUnsupportedKeyException(key);
    return (M) this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:AbstractData.java

示例8: LanternBlockState

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
LanternBlockState(LanternBlockStateMap baseState, ImmutableMap<BlockTrait<?>, Comparable<?>> traitValues) {
    this.traitValues = traitValues;
    this.baseState = baseState;

    ImmutableBiMap.Builder<Key<Value<?>>, BlockTrait<?>> builder = ImmutableBiMap.builder();
    for (BlockTrait trait : traitValues.keySet()) {
        builder.put(((LanternBlockTrait) trait).getKey(), trait);
    }
    this.keyToBlockTrait = builder.build();

    final StringBuilder idBuilder = new StringBuilder();
    idBuilder.append(baseState.getBlockType().getId().substring(baseState.getBlockType().getPluginId().length() + 1));
    if (!traitValues.isEmpty()) {
        idBuilder.append('[');
        final Joiner joiner = Joiner.on(',');
        final List<String> propertyValues = new ArrayList<>();
        for (Map.Entry<BlockTrait<?>, Comparable<?>> entry : traitValues.entrySet()) {
            propertyValues.add(entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase(Locale.ENGLISH));
        }
        idBuilder.append(joiner.join(propertyValues));
        idBuilder.append(']');
    }
    this.name = idBuilder.toString();
    this.id = baseState.getBlockType().getPluginId() + ':' + this.name;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:26,代码来源:LanternBlockState.java

示例9: set

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
public <E> M set(Key<? extends BaseValue<E>> key, E value) {
    checkNotNull(key, "key");
    checkNotNull(value, "value");

    // Check the local key registration
    final KeyRegistration<BaseValue<E>, E> localKeyRegistration = getValueCollection().get(key).orElse(null);
    if (localKeyRegistration != null) {
        ((Processor<?, E>) localKeyRegistration).offerTo(this, value);
        return (M) this;
    }

    // Check for a global registration
    final Optional<ValueProcessorKeyRegistration<BaseValue<E>, E>> globalRegistration = LanternValueFactory.get().getKeyRegistration(key);
    if (globalRegistration.isPresent()) {
        ((Processor<BaseValue<E>, E>) globalRegistration.get()).offerTo(this, value);
        return (M) this;
    }

    throwUnsupportedKeyException(key);
    return (M) this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:AbstractData.java

示例10: with

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
public <E> Optional<ImmutableViewerDataManipulator> with(Key<? extends BaseValue<E>> key, E e) {
    if (this.supports(key)) {
        return Optional.of(asMutable().set(key, e).asImmutable());
    } else {
        return Optional.empty();
    }
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:9,代码来源:ImmutableViewerDataManipulator.java

示例11: set

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
protected boolean set(EntityAuraNode dataHolder, Map<Key<?>, Object> keyValues) {
    final int amount = (int) keyValues.get(ThaumicKeys.AURA_NODE_SIZE);
    final Aspect aspect = (Aspect) keyValues.get(ThaumicKeys.AURA_NODE_ASPECT);
    final boolean stable = (boolean) keyValues.get(ThaumicKeys.AURA_NODE_IS_STABLE);
    final AuraNodeType nodeType = (AuraNodeType) keyValues.get(ThaumicKeys.AURA_NODE_TYPE);
    dataHolder.setNodeSize(amount);
    dataHolder.setNodeType(((IMixinNodeType) nodeType).getNodeType());
    dataHolder.setAspectTag(aspect.getId());
    ((IMixinAura) dataHolder).setStabilized(stable);
    return true;
}
 
开发者ID:gabizou,项目名称:ThaumicSponge,代码行数:13,代码来源:AuraNodeDataProcessor.java

示例12: getValues

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@Override
protected Map<Key<?>, ?> getValues(EntityAuraNode dataHolder) {
    ImmutableMap.Builder<Key<?>, Object> builder = ImmutableMap.builder();
    thaumcraft.api.aspects.Aspect aspect = dataHolder.getAspect();
    builder.put(ThaumicKeys.AURA_NODE_ASPECT, aspect == null ? Aspects.AER : aspect);
    builder.put(ThaumicKeys.AURA_NODE_IS_STABLE, ((IMixinAura) dataHolder).isStable());
    builder.put(ThaumicKeys.AURA_NODE_SIZE, dataHolder.getNodeSize());
    builder.put(ThaumicKeys.AURA_NODE_TYPE, NodeType.nodeTypes[dataHolder.getNodeType()]);
    return builder.build();
}
 
开发者ID:gabizou,项目名称:ThaumicSponge,代码行数:11,代码来源:AuraNodeDataProcessor.java

示例13: with

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <E> Optional<ImmutableAnnointmentFlagData>
        with(Key<? extends BaseValue<E>> key, E value) {
    if (!AnnointmentDataManager.ANNOINMENT_FLAGS.equals(key)) {
        return Optional.empty();
    }
    return Optional.of(
            new ImmutableAnnointmentFlagData((Set<AnnointmentFlag>) value));
}
 
开发者ID:kenzierocks,项目名称:Annointment,代码行数:11,代码来源:ImmutableAnnointmentFlagData.java

示例14: updateKeys

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
private static void updateKeys() {
    int currentTime = Sponge.getServer().getRunningTimeTicks();
    if (currentTime != lastUpdate) {
        lastUpdate = currentTime;
        keys = new HashSet<>(Sponge.getRegistry().getAllOf(Key.class));
        keys.add(FlagHelper.FLAGMAP); // TODO: Make this not needed! GetAllOf shouldn't require manual key registration!
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:9,代码来源:DataKeys.java

示例15: getKeyForName

import org.spongepowered.api.data.key.Key; //导入依赖的package包/类
public static Key getKeyForName(String name) {
    updateKeys();
    name = CoreUtilities.toLowerCase(name);
    for (Key key : keys) {
        if (name.equals(CoreUtilities.after(key.getId(), ":"))
                || name.equals(key.getId())) {
            return key;
        }
    }
    return null;
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:12,代码来源:DataKeys.java


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