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


Java DataContainer.createNew方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: serialize

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
public static DataView serialize(PotionEffect potionEffect) {
    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    dataView.set(AMPLIFIER, (byte) potionEffect.getAmplifier());
    dataView.set(DURATION, potionEffect.getDuration());
    dataView.set(AMBIENT, (byte) (potionEffect.isAmbient() ? 1 : 0));
    if (potionEffect.getShowParticles()) {
        dataView.set(SHOW_PARTICLES, (byte) 1);
    }
    final LanternPotionEffectType potionEffectType = (LanternPotionEffectType) potionEffect.getType();
    final int internalId = potionEffectType.getInternalId();
    if (internalId > 0xff) {
        dataView.set(IDENTIFIER, internalId);
    } else {
        dataView.set(IDENTIFIER, (byte) internalId);
    }
    return dataView;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:PotionEffectSerializer.java

示例5: 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

示例6: 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

示例7: 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

示例8: applyTileEntityData

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void applyTileEntityData(TileEntity tileEntity, BaseBlock baseBlock) {
    final ObjectStore store = ObjectStoreRegistry.get().get(tileEntity.getClass())
            .orElseThrow(() -> new IllegalStateException("Missing object store for tile " + tileEntity.getType()));
    final CompoundTag tag = baseBlock.getNbtData();
    final DataView dataView = tag == null ? DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED) : DataViewNbt.from(tag);
    store.deserialize(tileEntity, dataView);
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:10,代码来源:LanternWEWorld.java

示例9: applyEntityData

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void applyEntityData(Entity entity, BaseEntity baseEntity) {
    final ObjectStore store = ObjectStoreRegistry.get().get(entity.getClass())
            .orElseThrow(() -> new IllegalStateException("Missing object store for entity " + entity.getType()));
    final CompoundTag tag = baseEntity.getNbtData();
    final DataView dataView = tag == null ? DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED) : DataViewNbt.from(tag);
    for (String field : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
        dataView.remove(DataQuery.of(field));
    }
    store.deserialize(entity, dataView);
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:13,代码来源:LanternWEWorld.java

示例10: serialize

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@Override
public DataView serialize(T object) {
    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    if (this.objectStore instanceof IdentifiableObjectStore) {
        ((IdentifiableObjectStore) this.objectStore).serializeUniqueId(dataView, object.getUniqueId());
    }
    this.objectStore.serialize(object, dataView);
    return dataView;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:IdentifiableObjectSerializer.java

示例11: sendBookView

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@Override
public void sendBookView(BookView bookView) {
    checkNotNull(bookView, "bookView");

    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    WrittenBookItemTypeObjectSerializer.writeBookData(dataView, bookView, this.locale);

    // Written book internal id
    final RawItemStack rawItemStack = new RawItemStack(387, 0, 1, dataView);
    final int slot = this.inventory.getHotbar().getSelectedSlotIndex();
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, rawItemStack));
    this.session.send(new MessagePlayOutOpenBook(HandTypes.MAIN_HAND));
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, this.inventory.getHotbar().getSelectedSlot().peek().orElse(null)));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:15,代码来源:LanternPlayer.java

示例12: write

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@Override
public void write(ByteBuffer buf, @Nullable ItemStack object) throws CodecException {
    if (object == null) {
        buf.write(Types.RAW_ITEM_STACK, null);
    } else {
        final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
        this.store.serialize((LanternItemStack) object, dataView);
        buf.write(Types.RAW_ITEM_STACK, new RawItemStack(ItemRegistryModule.get().getInternalId(object.getType()),
                dataView.getShort(ItemStackStore.DATA).orElse((short) 0), object.getQuantity(),
                dataView.getView(ItemStackStore.TAG).orElse(null)));
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:13,代码来源:Types.java

示例13: toContainer

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@Override
public DataContainer toContainer() {
    final DataContainer dataContainer = DataContainer.createNew();
    dataContainer.set(DataQuery.of("BlockType"), this.baseState.getBlockType().getId());
    for (Map.Entry<BlockTrait<?>, Comparable<?>> entry : this.traitValues.entrySet()) {
        final Object value = entry.getValue();
        dataContainer.set(((LanternBlockTrait) entry.getKey()).getKey().getQuery(), value);
    }
    return dataContainer;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternBlockState.java

示例14: save

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
public static void save(Path dataFolder, AbstractUser player) throws IOException {
    final String fileName = player.getUniqueId().toString() + ".dat";

    final DataContainer dataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    final ObjectStore<AbstractUser> objectStore = ObjectStoreRegistry.get().get(AbstractUser.class).get();
    objectStore.serialize(player, dataContainer);

    final Optional<DataView> optSpongeData = dataContainer.getView(DataQueries.EXTENDED_SPONGE_DATA);
    dataContainer.remove(DataQueries.EXTENDED_SPONGE_DATA);

    Path dataFolder0 = dataFolder.resolve(PLAYER_DATA_FOLDER);
    if (!Files.exists(dataFolder0)) {
        Files.createDirectories(dataFolder0);
    }
    Path dataFile = dataFolder0.resolve(fileName);
    NbtStreamUtils.write(dataContainer, Files.newOutputStream(dataFile), true);

    dataFolder0 = dataFolder.resolve(SPONGE_PLAYER_DATA_FOLDER);
    if (!Files.exists(dataFolder0)) {
        Files.createDirectories(dataFolder0);
    }
    dataFile = dataFolder0.resolve(fileName);
    if (optSpongeData.isPresent()) {
        final DataView spongeData = optSpongeData.get();
        spongeData.set(NAME, player.getName());
        NbtStreamUtils.write(spongeData, Files.newOutputStream(dataFile), true);
    } else {
        Files.deleteIfExists(dataFile);
    }

    final Path statisticsFile = dataFolder.resolve(STATISTICS_FOLDER).resolve(player.getUniqueId().toString() + ".json");
    player.getStatisticMap().save(statisticsFile);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:34,代码来源:UserIO.java

示例15: serialize

import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
@Override
public DataView serialize(LanternEntity object) {
    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    dataView.set(ID, object.getType().getId());
    //noinspection unchecked
    final ObjectStore<LanternEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(object.getClass()).get();
    store.serialize(object, dataView);
    if (store instanceof IdentifiableObjectStore) {
        ((IdentifiableObjectStore) store).serializeUniqueId(dataView, object.getUniqueId());
    }
    return dataView;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:13,代码来源:EntitySerializer.java


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