本文整理汇总了Java中org.spongepowered.api.data.value.BaseValue类的典型用法代码示例。如果您正苦于以下问题:Java BaseValue类的具体用法?Java BaseValue怎么用?Java BaseValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseValue类属于org.spongepowered.api.data.value包,在下文中一共展示了BaseValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeForKeys
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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");
}
}
示例2: parse
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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();
}
}
示例3: getKeys
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
default Set<Key<?>> getKeys() {
final ImmutableSet.Builder<Key<?>> keys = ImmutableSet.builder();
// Check local registrations
keys.addAll(getValueCollection().getKeys());
// Check for global registrations
LanternValueFactory.get().getKeyRegistrations().stream()
.filter(registration -> ((Processor<BaseValue<?>, ?>) registration).isApplicableTo(this))
.forEach(registration -> keys.add(registration.getKey()));
// Check if custom data is supported by this container
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<?> containers = ((AdditionalContainerHolder<?>) this).getAdditionalContainers();
containers.getAll().forEach(manipulator -> keys.addAll(manipulator.getKeys()));
}
return keys.build();
}
示例4: transform
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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;
}
示例5: LanternKey
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
LanternKey(LanternKeyBuilder<?, V> builder) {
this.valueToken = builder.valueToken;
this.name = builder.name;
this.query = builder.query;
this.elementToken = this.valueToken.resolveType(BaseValue.class.getTypeParameters()[0]);
final PluginContainer plugin = CauseStack.current().first(PluginContainer.class).get();
final String id = builder.id;
if (id.indexOf(':') == -1) {
this.id = plugin.getId() + ':' + id;
} else {
this.id = id;
if (loggedPlugins.add(plugin.getId())) {
Lantern.getLogger().warn(plugin.getId() + ": It is no longer required to include the plugin id when specifying a "
+ "Key id through Key.Builder#id. This is deprecated and may be removed later. The plugin id will be retrieved from the "
+ "current PluginContainer in the cause stack. ");
}
}
}
示例6: set
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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;
}
示例7: with
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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();
}
}
示例8: with
import org.spongepowered.api.data.value.BaseValue; //导入依赖的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));
}
示例9: getValue
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
public static AbstractTagObject getValue(DataHolder dataHolder, Key key, Action<String> error) {
Class clazz = key.getElementToken().getRawType();
if (!dataHolder.supports(key)) {
if (FlagMap.class.isAssignableFrom(clazz)) {
return new MapTag();
}
error.run("This data holder does not support the key '" + key.getId() + "'!");
return new NullTag();
}
if (Boolean.class.isAssignableFrom(clazz)) {
return new BooleanTag(dataHolder.getOrElse((Key<BaseValue<Boolean>>) key, false));
}
else if (CatalogType.class.isAssignableFrom(clazz)) {
return new TextTag(dataHolder.getValue((Key<BaseValue<CatalogType>>) key).orElseThrow(() -> new ErrorInducedException("Value not present!")).get().getId());
}
else if (Double.class.isAssignableFrom(clazz)) {
return new NumberTag(dataHolder.getOrElse((Key<BaseValue<Double>>) key, 0.0));
}
else if (Enum.class.isAssignableFrom(clazz)) {
return new TextTag(dataHolder.getValue((Key<BaseValue<Enum>>) key).orElseThrow(() -> new ErrorInducedException("Empty enum value!")).get().name());
}
else if (Integer.class.isAssignableFrom(clazz)) {
return new IntegerTag(dataHolder.getOrElse((Key<BaseValue<Integer>>) key, 0));
}
else if (Vector3d.class.isAssignableFrom(clazz)) {
return new LocationTag(dataHolder.getOrElse((Key<BaseValue<Vector3d>>) key, new Vector3d(0, 0, 0)));
}
else if (Text.class.isAssignableFrom(clazz)) {
return new FormattedTextTag(dataHolder.getOrElse((Key<BaseValue<Text>>) key, Text.EMPTY));
}
else if (FlagMap.class.isAssignableFrom(clazz)) {
return new MapTag(dataHolder.getOrElse((Key<BaseValue<FlagMap>>) key, new FlagMap(new MapTag())).flags.getInternal());
}
else {
error.run("The value type '" + clazz.getName() + "' is not supported yet!");
return new NullTag();
}
}
示例10: getRawValueFor
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
@Override
public <E, V extends BaseValue<E>> Optional<V> getRawValueFor(Key<V> key) {
if (!supports(key)) {
return Optional.empty();
}
final BlockTrait<?> blockTrait = this.keyToBlockTrait.get(key);
return Optional.of((V) new LanternValue(key, this.traitValues.get(blockTrait)));
}
示例11: removeNoEvents
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
default DataTransactionResult removeNoEvents(Key<?> key) {
checkNotNull(key, "key");
// Check the local key registration
final KeyRegistration<?, ?> localKeyRegistration = (KeyRegistration<?, ?>) getValueCollection().get((Key) key).orElse(null);
if (localKeyRegistration != null) {
return ((Processor<BaseValue<?>, ?>) localKeyRegistration).removeFrom(this);
}
// Check for a global registration
final Optional<ValueProcessorKeyRegistration> globalRegistration = LanternValueFactory.get().getKeyRegistration((Key) key);
if (globalRegistration.isPresent()) {
return ((Processor<BaseValue<?>, ?>) globalRegistration.get()).removeFrom(this);
}
// Check if custom data is supported by this container
if (this instanceof AdditionalContainerHolder) {
// Check for the custom value containers
final AdditionalContainerCollection<H> containers = ((AdditionalContainerHolder<H>) this).getAdditionalContainers();
for (H valueContainer : containers.getAll()) {
if (valueContainer.supports(key)) {
if (valueContainer instanceof ICompositeValueStore) {
return ((ICompositeValueStore) valueContainer).removeNoEvents(key);
} else if (valueContainer instanceof CompositeValueStore) {
return ((CompositeValueStore) valueContainer).remove(key);
}
return DataTransactionResult.failNoData();
}
}
}
return DataTransactionResult.failNoData();
}
示例12: get
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
@Override
public <E> Optional<E> get(int x, int y, int z, Key<? extends BaseValue<E>> key) {
if (!this.loaded) {
return Optional.empty();
}
final BlockState blockState = getBlock(x, y, z);
Optional<E> value = blockState.get(key);
if (!value.isPresent()) {
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
if (tileEntity.isPresent()) {
value = tileEntity.get().get(key);
}
}
return value;
}
示例13: getValue
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
@Override
public <E, V extends BaseValue<E>> Optional<V> getValue(int x, int y, int z, Key<V> key) {
if (!this.loaded) {
return Optional.empty();
}
final BlockState blockState = getBlock(x, y, z);
Optional<V> value = blockState.getValue(key);
if (!value.isPresent()) {
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
if (tileEntity.isPresent()) {
value = tileEntity.get().getValue(key);
}
}
return value;
}
示例14: offerFastNoEvents
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
default <E> boolean offerFastNoEvents(BaseValue<E> value) {
checkNotNull(value, "value");
final Key<? extends BaseValue<E>> key = value.getKey();
// Check the local key registration
final KeyRegistration<?, ?> localKeyRegistration = (KeyRegistration<?, ?>) getValueCollection().get((Key) key).orElse(null);
if (localKeyRegistration != null) {
return ((Processor<BaseValue<E>, E>) localKeyRegistration).offerFastTo(this, value);
}
// Check for a global registration
final Optional<ValueProcessorKeyRegistration> globalRegistration = LanternValueFactory.get().getKeyRegistration((Key) key);
if (globalRegistration.isPresent()) {
return ((Processor<BaseValue<E>, E>) globalRegistration.get()).offerFastTo(this, value);
}
// Check if custom data is supported by this container
if (this instanceof AdditionalContainerHolder) {
// Check for the custom value containers
final AdditionalContainerCollection<H> containers = ((AdditionalContainerHolder<H>) this).getAdditionalContainers();
for (H valueContainer : containers.getAll()) {
if (valueContainer.supports(key)) {
if (valueContainer instanceof ICompositeValueStore) {
return ((ICompositeValueStore) valueContainer).offerFastNoEvents(value);
} else if (valueContainer instanceof CompositeValueStore) {
return ((CompositeValueStore) valueContainer).offer(value).isSuccessful();
} else if (valueContainer instanceof DataManipulator) {
((DataManipulator) valueContainer).set(value);
return true;
} else {
// TODO: Support immutable manipulators?
return false;
}
}
}
}
return false;
}
示例15: get
import org.spongepowered.api.data.value.BaseValue; //导入依赖的package包/类
@Override
public <E> Optional<E> get(Key<? extends BaseValue<E>> key) {
if (!supports(key)) {
return Optional.empty();
}
return Optional.ofNullable((E) this.traitValues.get(this.keyToBlockTrait.get(key)));
}