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


Java DataQuery类代码示例

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


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

示例1: createTicket

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/***
 * Create a ticket, requested from the Ticket Manager which returns an Optional
 * @param world the world which the ticket should associate with
 * @return A LoadingTicket for force loading chunks
 */
private LoadingTicket createTicket(World world) {
	Optional<LoadingTicket> opTicket = ticketManager.createTicket(world);
	LoadingTicket newTicket = null;

	if (opTicket.isPresent()) {
		newTicket = opTicket.get();
		newTicket.getCompanionData().set(DataQuery.of("type"), getType().toString());
		this.isValid = true;
	} else {
		logger.error("Requested ticket was not provided; maximum tickets may have been reached.");
		this.isValid = false;
	}

	return newTicket;
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:21,代码来源:LoadedRegion.java

示例2: getCrateKey

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/***
 * Retrieve the crate item
 * @since 0.10.2
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateKey(int quantity){
    ItemStack key = ItemStack.builder()
            .itemType(keyType)
            .quantity(quantity)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Key")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }
    String keyUUID = registerKey(quantity);
    if(keyUUID == null){
        HuskyCrates.instance.logger.error("Throwing NullPointerException: Key failed to register.");
        throw new NullPointerException();
    }
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id).set(DataQuery.of("UnsafeData","keyUUID"),keyUUID)).build();//

}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:26,代码来源:VirtualCrate.java

示例3: getCrateWand

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/***
 * Retrieve the crate item
 * @since 1.2.1
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateWand(){
    ItemStack key = ItemStack.builder()
            .itemType(ItemTypes.BLAZE_ROD)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Wand")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A wand for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }

    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id)).build();//

}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:21,代码来源:VirtualCrate.java

示例4: from

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

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

示例6: equalTo

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
static private boolean equalTo(ItemStack item, ItemStack needle) {
	if (item.equalTo(needle))
		return true;
	for (Entry<DataQuery, Object> pair : needle.toContainer().getValues(true).entrySet()) {
		if (pair.getKey().toString().equals("ItemType")
				|| pair.getKey().toString().equals("UnsafeDamage")
				|| pair.getKey().toString().equals("UnsafeData.ench")
				|| pair.getKey().toString().equals("UnsafeData.StoredEnchantments")
				|| pair.getKey().toString().equals("UnsafeData.Potion")
				|| pair.getKey().toString().equals("UnsafeData.EntityTag")) {
			Optional<Object> other = item.toContainer().get(pair.getKey());
			if (!other.isPresent() || !pair.getValue().toString().equals(other.get().toString())) {
				return false;
			}
		}
	}

	return true;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:20,代码来源:Shop.java

示例7: teleport

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
public boolean teleport(final World world, final Vector3d vector){
	if (this.getVehicle().isPresent()){
		final Entity horse = this.getVehicle().get();
		if (horse.toContainer().getView(DataQuery.of("UnsafeData")).isPresent()){
			if (horse.toContainer().getView(DataQuery.of("UnsafeData")).get().getString(DataQuery.of("OwnerUUID")).isPresent()){
				UUID owner = UUID.fromString(horse.toContainer().getView(DataQuery.of("UnsafeData")).get().getString(DataQuery.of("OwnerUUID")).get());
				if (this.getUniqueId().equals(owner)){
					this.setVehicle(null);
					horse.transferToWorld(world, vector);
					
					if (this.setLocation(world.getLocation(vector))) {
						this.setVehicle(horse);
						return true;
					}
				}
			}
		}
	}
	
	return this.setLocation(world.getLocation(vector));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:22,代码来源:EPlayer.java

示例8: getByteArray

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/**
 * Attempts to get a byte array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The byte array
 */
public static Optional<byte[]> getByteArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof byte[]) {
        return (Optional) optObject;
    }
    return dataView.getByteList(path).map(list -> {
        if (list instanceof ByteList) {
            return ((ByteList) list).toByteArray();
        }
        final byte[] array = new byte[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例9: getIntArray

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/**
 * Attempts to get a int array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The int array
 */
public static Optional<int[]> getIntArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof int[]) {
        return (Optional) optObject;
    }
    return dataView.getIntegerList(path).map(list -> {
        if (list instanceof IntList) {
            return ((IntList) list).toIntArray();
        }
        final int[] array = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例10: getLongArray

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<long[]> getLongArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof long[]) {
        return (Optional) optObject;
    }
    return dataView.getLongList(path).map(list -> {
        if (list instanceof LongList) {
            return ((LongList) list).toLongArray();
        }
        final long[] array = new long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例11: getDoubleArray

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<double[]> getDoubleArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof double[]) {
        return (Optional) optObject;
    }
    return dataView.getDoubleList(path).map(list -> {
        if (list instanceof DoubleList) {
            return ((DoubleList) list).toDoubleArray();
        }
        final double[] array = new double[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例12: getFloatArray

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<float[]> getFloatArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof float[]) {
        return (Optional) optObject;
    }
    return dataView.getFloatList(path).map(list -> {
        if (list instanceof FloatList) {
            return ((FloatList) list).toFloatArray();
        }
        final float[] array = new float[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例13: remove

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
@Override
public DataView remove(DataQuery path) {
    checkNotNull(path, "path");
    final List<String> parts = path.getParts();
    if (parts.size() > 1) {
        final String subKey = parts.get(0);
        final DataQuery subQuery = of(subKey);
        final Optional<DataView> subViewOptional = getUnsafeView(subQuery);
        if (!subViewOptional.isPresent()) {
            return this;
        }
        final DataView subView = subViewOptional.get();
        subView.remove(path.popFirst());
    } else {
        this.map.remove(parts.get(0));
    }
    return this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:MemoryDataView.java

示例14: createView

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
@Override
public DataView createView(DataQuery path) {
    checkNotNull(path, "path");
    final List<String> queryParts = path.getParts();
    final int sz = queryParts.size();

    checkArgument(sz != 0, "The size of the query must be at least 1");

    final String key = queryParts.get(0);
    final DataQuery keyQuery = of(key);

    if (sz == 1) {
        final DataView result = new MemoryDataView(this, keyQuery, this.safety);
        this.map.put(key, result);
        return result;
    }
    final DataQuery subQuery = path.popFirst();
    final DataView subView = (DataView) this.map.computeIfAbsent(key,
            key1 -> new MemoryDataView(this.parent, keyQuery, this.safety));
    return subView.createView(subQuery);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:MemoryDataView.java

示例15: getMap

import org.spongepowered.api.data.DataQuery; //导入依赖的package包/类
@Override
public Optional<? extends Map<?, ?>> getMap(DataQuery path) {
    final Optional<Object> val = get(path);
    if (val.isPresent()) {
        if (val.get() instanceof DataView) {
            final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
            for (Map.Entry<DataQuery, Object> entry : ((DataView) val.get()).getValues(false).entrySet()) {
                builder.put(entry.getKey().asString('.'), ensureMappingOf(entry.getValue()));
            }
            return Optional.of(builder.build());
        } else if (val.get() instanceof Map) {
            return Optional.of((Map<?, ?>) ensureMappingOf(val.get()));
        }
    }
    return Optional.empty();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:MemoryDataView.java


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