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


Java NbtCompound.put方法代码示例

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


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

示例1: openFor

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@Override
public void openFor(Player player) throws InvocationTargetException {
	if (AuthMeApi.getInstance().isAuthenticated(player)) {
		return;
	}
	PacketContainer fakeBlockChange = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
	PacketContainer updateEntity = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
	PacketContainer sign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
	Location block = player.getLocation().getBlock().getLocation();
	BlockPosition position = new BlockPosition(block.getBlockX(), block.getBlockY() + 1, block.getBlockZ());
	fakeBlockChange.getBlockPositionModifier().write(0, position);
	fakeBlockChange.getBlockData().write(0, WrappedBlockData.createData(Material.SIGN_POST));
	protocolManager.sendServerPacket(player, fakeBlockChange);
	updateEntity.getBlockPositionModifier().write(0, position);
	updateEntity.getIntegers().write(0, 9);
	NbtCompound signNbt = (NbtCompound) updateEntity.getNbtModifier().read(0);
	signNbt = signNbt == null ? NbtFactory.ofCompound("") : signNbt;
	List<String> lines = this.getInfoFor(player);
	for (int i = 0; i < lines.size() || i < 4; i++) {
		signNbt.put("Text" + (i + 1), "{\"text\":\"" + lines.get(i) + "\"}");
	}
	updateEntity.getNbtModifier().write(0, signNbt);
	protocolManager.sendServerPacket(player, updateEntity);
	sign.getBlockPositionModifier().write(0, position);
	protocolManager.sendServerPacket(player, sign);
}
 
开发者ID:lj2000lj,项目名称:AuthMeGUI,代码行数:27,代码来源:SignLoginWindow.java

示例2: saveBackpack

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
static void saveBackpack(Backpack backpack, Path file) throws IOException {
    List<NbtCompound> nbtList = new ArrayList<>();

    try (DataOutputStream dataOutput = new DataOutputStream(new GZIPOutputStream(Files.newOutputStream(file)))) {
        ItemStack[] contents = backpack.getContents();
        for (int i = 0; i < contents.length; i++) {
            ItemStack item = contents[i];
            nbtList.add(ItemUtils.itemStackToNBT(ItemUtils.isEmpty(item)
                    ? new ItemStack(Material.AIR)
                    : item, i + ""));
        }

        NbtCompound backpackNbt = NbtFactory.ofCompound("Backpack");
        backpackNbt.put(NbtFactory.ofCompound("contents", nbtList));
        backpackNbt.put("type", backpack.getType().getId());
        backpackNbt.put("last-use", backpack.getLastUse());
        NbtBinarySerializer.DEFAULT.serialize(backpackNbt, dataOutput);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:20,代码来源:BackpackSerializer.java

示例3: setSkullTexture

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static ItemStack setSkullTexture(ItemStack itemStack, String value) {
    ItemStack newStack = itemStack;
    if (!MinecraftReflection.isCraftItemStack(itemStack)) {
        newStack = MinecraftReflection.getBukkitItemStack(itemStack);
    }

    NbtCompound tag = (NbtCompound) NbtFactory.fromItemTag(newStack);
    NbtCompound skullOwner = NbtFactory.ofCompound("SkullOwner");
    NbtCompound properties = NbtFactory.ofCompound("Properties");

    NbtCompound compound = NbtFactory.ofCompound("");
    compound.put("Value", value);

    NbtList<NbtCompound> textures = NbtFactory.ofList("textures", compound);
    properties.put(textures);
    skullOwner.put("Id", UUID.randomUUID().toString());
    skullOwner.put(properties);
    tag.put(skullOwner);

    NbtFactory.setItemTag(newStack, tag);
    return newStack;
}
 
开发者ID:elsiff,项目名称:MoreFish,代码行数:23,代码来源:SkullUtils.java

示例4: onMapChunk

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
private void onMapChunk( PacketEvent event ) {
	final Player          player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	final Locale          locale = this.i18n.getLocale( player.getUniqueId() );
	
	List handleList = packet.getSpecificModifier( List.class ).read( 0 );
	for ( Object compoundHandle : handleList ) {
		NbtCompound compound = NbtFactory.fromNMSCompound( compoundHandle );
		String id = compound.getString( "id" );
		if ( id.equals( "minecraft:sign" ) || id.equals( "Sign" ) ) {
			for ( int i = 1; i <= 4; ++i ) {
				final String key = "Text" + i;
				String message    = this.gson.fromJson( compound.getString( key ), ChatComponent.class ).getUnformattedText();
				String translated = this.translateMessageIfAppropriate( locale, message );
				
				if ( message != translated ) {
					compound.put( key, WrappedChatComponent.fromText( translated ).getJson() );
				}
			}
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:23,代码来源:InterceptorSign.java

示例5: set

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@Override
public void set(String id, NbtCompound argNbt, CommandSender commandSender, boolean merge) {
	NbtCompound nbt = (NbtCompound) argNbt.deepClone();
	NbtCompound src = get(id, commandSender);
	nbt.put(src.getValue("x"));
	nbt.put(src.getValue("y"));
	nbt.put(src.getValue("z"));
	nbt.put(src.getValue("id"));
	Block block = parseId(id, commandSender);
	Object tileEntity = getTileEntity(block);
	Object nmsNBT = NbtFactory.fromBase(nbt).getHandle();
	if (merge) {
		ReflectionHelper.mergeCompound(nmsNBT, NbtFactory.fromBase(nbt).getHandle());
	}
	ReflectionHelper.tileRead(tileEntity, nmsNBT);
	ReflectionHelper.notifyBlock(ReflectionHelper.toNMSWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
}
 
开发者ID:yushijinhun,项目名称:AdvancedCommands,代码行数:18,代码来源:NBTSourceTile.java

示例6: saveDeathTime

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static void saveDeathTime(ItemStack item, long deathTime) {
    NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));

    if (deathTime == 0) {
        nbt.remove(DEATH_TIME_TAG);
    } else {
        nbt.put(DEATH_TIME_TAG, deathTime);
    }

    NbtFactory.setItemTag(item, nbt);
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:12,代码来源:PetManager.java

示例7: saveHealth

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static void saveHealth(ItemStack item, double health) {
    NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));

    if (health == 0) {
        nbt.remove("pet.health");
    } else {
        nbt.put("pet.health", health);
    }

    NbtFactory.setItemTag(item, nbt);
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:12,代码来源:PetManager.java

示例8: setTag

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static ItemStack setTag(ItemStack item, String tag, String value) {
    item = toBukkitItemStack(item);
    NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));

    if (!nbt.containsKey(tag)) {
        if (UNBREAKABLE_TAG.equals(tag) || HIDE_FLAGS_TAG.equals(tag)) {
            nbt.put(tag, Integer.parseInt(value));
        } else {
            nbt.put(tag, value);
        }
    }
    NbtFactory.setItemTag(item, nbt);

    return item;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:16,代码来源:ItemUtils.java

示例9: getTexturedItem

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@NotNull
public static ItemStack getTexturedItem(String texture) {
    String[] textures = texture.split(":");

    if (Material.getMaterial(textures[0]) == null) {
        RPGInventory.getPluginLogger().warning("Material " + textures[0] + " not found");
        return new ItemStack(Material.AIR);
    }

    ItemStack item = new ItemStack(Material.getMaterial(textures[0]));

    if (textures.length == 2) {
        if (item.getType() == Material.MONSTER_EGG) {
            item = toBukkitItemStack(item);
            NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));
            nbt.put("EntityTag", NbtFactory.ofCompound("temp").put("id", textures[1]));
        } else {
            item.setDurability(Short.parseShort(textures[1]));

            if (isItemHasDurability(item)) {
                item = setTag(item, UNBREAKABLE_TAG, "1");
                item = setTag(item, HIDE_FLAGS_TAG, "63");
            }
        }
    }

    return item;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:29,代码来源:ItemUtils.java

示例10: itemStackToNBT

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static NbtCompound itemStackToNBT(ItemStack originalItem, String name) {
    NbtCompound nbt = NbtFactory.ofCompound(name);

    nbt.put("material", originalItem.getType().name());
    nbt.put("amount", originalItem.getAmount());
    nbt.put("data", originalItem.getDurability());

    ItemStack item = toBukkitItemStack(originalItem.clone());
    NbtCompound tag = ItemUtils.isEmpty(item) ? null : NbtFactory.asCompound(NbtFactory.fromItemTag(item));
    if (tag != null) {
        nbt.put("tag", tag);
    }

    return nbt;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:16,代码来源:ItemUtils.java

示例11: savePlayer

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
static void savePlayer(PlayerWrapper playerWrapper, Path file) throws IOException {
    List<NbtCompound> slotList = new ArrayList<>();
    try (DataOutputStream dataOutput = new DataOutputStream(new GZIPOutputStream(Files.newOutputStream(file)))) {
        for (Slot slot : SlotManager.instance().getSlots()) {
            if (slot.getSlotType() == Slot.SlotType.ARMOR) {
                continue;
            }

            List<NbtCompound> itemList = new ArrayList<>();
            List<Integer> slotIds = slot.getSlotIds();
            Inventory inventory = playerWrapper.getInventory();
            for (int i = 0; i < slotIds.size(); i++) {
                int slotId = slotIds.get(i);
                ItemStack itemStack = inventory.getItem(slotId);
                if (!ItemUtils.isEmpty(itemStack) && !slot.isCup(itemStack)) {
                    itemList.add(ItemUtils.itemStackToNBT(itemStack, i + ""));
                }
            }

            if (itemList.size() > 0 || playerWrapper.isBuyedSlot(slot.getName())) {
                NbtCompound slotNbt = NbtFactory.ofCompound(slot.getName());
                slotNbt.put("type", slot.getSlotType().name());
                if (playerWrapper.isBuyedSlot(slot.getName())) {
                    slotNbt.put("buyed", "true");
                }
                slotNbt.put(NbtFactory.ofCompound("items", itemList));
                slotList.add(slotNbt);
            }
        }

        NbtCompound playerNbt = NbtFactory.ofCompound("Inventory");
        playerNbt.put(NbtFactory.ofCompound("slots", slotList));
        playerNbt.put("buyed-slots", playerWrapper.getBuyedGenericSlots());

        NbtBinarySerializer.DEFAULT.serialize(playerNbt, dataOutput);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:38,代码来源:InventorySerializer.java

示例12: removeAttributes

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
private static ItemStack removeAttributes(ItemStack item) {
	if (!MinecraftReflection.isCraftItemStack(item)) {
		item = MinecraftReflection.getBukkitItemStack(item);
	}
	try {
		NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(item);
		compound.put(NbtFactory.ofList("AttributeModifiers"));
	} catch (IllegalArgumentException e) {
		return item;
	}
	return item;
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:13,代码来源:ItemStackGenerator.java

示例13: addGlow

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
private static void addGlow(ItemStack[] stacks) {
	for (ItemStack stack : stacks) {
		if (stack != null) {
			// Only update those stacks that have our flag enchantment
			if (stack.getEnchantmentLevel(Enchantment.SILK_TOUCH) == 32) {
				NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(stack);
				compound.put(NbtFactory.ofList("ench"));
			}
		}
	}
}
 
开发者ID:bobmandude9889,项目名称:iZenith-PVP,代码行数:12,代码来源:Util.java

示例14: removeAttributes

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static ItemStack removeAttributes(ItemStack item) {
    if (!MinecraftReflection.isCraftItemStack(item)) {
        item = MinecraftReflection.getBukkitItemStack(item);
    }
    NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(item);
    compound.put(NbtFactory.ofList("AttributeModifiers"));
    return item;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:9,代码来源:RPProtocolLib.java

示例15: set

import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@Override
public void set(String id, NbtCompound argNbt, CommandSender commandSender, boolean merge) {
	NbtCompound nbt = (NbtCompound) argNbt.deepClone();
	NbtCompound src = get(id, commandSender);
	nbt.put(src.getValue("UUIDMost"));
	nbt.put(src.getValue("UUIDLeast"));
	Object nmsNBT = NbtFactory.fromBase(nbt).getHandle();
	if (merge) {
		ReflectionHelper.mergeCompound(nmsNBT, NbtFactory.fromBase(src).getHandle());
	}
	ReflectionHelper.entityRead(getEntity(id), nmsNBT);
}
 
开发者ID:yushijinhun,项目名称:AdvancedCommands,代码行数:13,代码来源:NBTSourceEntity.java


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