本文整理汇总了Java中com.comphenix.protocol.wrappers.nbt.NbtCompound类的典型用法代码示例。如果您正苦于以下问题:Java NbtCompound类的具体用法?Java NbtCompound怎么用?Java NbtCompound使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NbtCompound类属于com.comphenix.protocol.wrappers.nbt包,在下文中一共展示了NbtCompound类的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);
}
示例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);
}
}
示例3: loadBackpack
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
@Nullable
static Backpack loadBackpack(Path file) throws IOException {
Backpack backpack;
try (DataInputStream dataInput = new DataInputStream(new GZIPInputStream(Files.newInputStream(file)))) {
NbtCompound nbtList = NbtBinarySerializer.DEFAULT.deserializeCompound(dataInput);
BackpackType type = BackpackManager.getBackpackType(nbtList.getString("type"));
if (type == null) {
return null;
}
long lastUse = (nbtList.containsKey("last-use")) ? nbtList.getLong("last-use") : System.currentTimeMillis();
backpack = new Backpack(type, UUID.fromString(FileUtils.stripExtension(file.getFileName().toString())));
backpack.setLastUse(lastUse);
NbtCompound itemList = nbtList.getCompound("contents");
ItemStack[] contents = new ItemStack[type.getSize()];
for (int i = 0; i < type.getSize() && itemList.containsKey(i + ""); i++) {
NbtCompound compound = itemList.getCompound(i + "");
contents[i] = compound == null ? new ItemStack(Material.AIR) : ItemUtils.nbtToItemStack(compound);
}
backpack.setContents(contents);
}
return backpack;
}
示例4: isExploit
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
public boolean isExploit(ItemStack stack) {
try {
if (stack == null) {
return false;
}
if (stack.getType() == Material.SKULL || stack.getType() == Material.SKULL_ITEM) {
// Check human
if (stack.getDurability() == 3) {
NbtCompound tag = (NbtCompound) NbtFactory.fromItemTag(stack);
if (isExploit(tag)) {
return true;
}
}
}
} catch (Exception e) {
//nbt read error
}
return false;
}
示例5: values
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
public Iterable<Attribute> values()
{
return new Iterable<Attribute>() {
@Override
public Iterator<Attribute> iterator()
{
// Generics disgust me sometimes
return Iterators.transform(attributes.getValue().iterator(), new Function<NbtBase<Map<String, NbtBase<?>>>, Attribute>() {
@Override
public Attribute apply(@Nullable NbtBase<Map<String, NbtBase<?>>> element)
{
return new Attribute((NbtCompound) element);
}
});
}
};
}
示例6: 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;
}
示例7: 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() );
}
}
}
}
}
示例8: sendNbt
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
private void sendNbt(Vector pos, NbtCompound compound) {
Player player = this.<Player>getPlayer().parent;
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
PacketContainer blockNbt = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
blockNbt.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()));
blockNbt.getIntegers().write(0, 7);
blockNbt.getNbtModifier().write(0, compound);
try {
manager.sendServerPacket(player, blockNbt);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例9: 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());
}
示例10: call
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
@Override
public Var call(Var[] args, FunctionContext context) {
throwArgsLengthExceptionIf(args.length != 2);
checkType(args, 0, "nbt");
NbtBase<?> tag = (NbtBase<?>) args[0].getValue();
if (tag instanceof NbtCompound) {
checkType(args, 1, "string");
((NbtCompound) tag).remove((String) args[1].getValue());
} else if (tag instanceof NbtList<?>) {
checkType(args, 1, "int");
((NbtList<?>) tag).getValue().remove(((Integer) args[1].getValue()).intValue());
} else {
throw new IllegalArgumentException("Cannot fetch child of " + tag);
}
return null;
}
示例11: call
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Var call(Var[] args, FunctionContext context) {
throwArgsLengthExceptionIf((args.length < 2) || (args.length > 3));
checkType(args, 0, "nbt");
checkType(args, 1, "nbt");
NbtBase<?> tag = (NbtBase<?>) args[0].getValue();
@SuppressWarnings("rawtypes")
NbtBase child = (NbtBase<?>) args[1].getValue();
if (tag instanceof NbtCompound) {
throwArgsLengthExceptionIf(args.length != 3);
checkType(args, 2, "string");
((NbtCompound) tag).put((String) args[2].getValue(), child);
} else if (tag instanceof NbtList<?>) {
if (args.length > 2) {
checkType(args, 2, "int");
int index = (Integer) args[2].getValue();
((NbtList<?>) tag).getValue().set(index, child);
} else {
((NbtList<?>) tag).add(child);
}
} else {
throw new IllegalArgumentException("Cannot fetch child of " + tag);
}
return null;
}
示例12: call
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
@Override
public Var call(Var[] args, FunctionContext context) {
throwArgsLengthExceptionIf(args.length != 2);
checkType(args, 0, "nbt");
NbtBase<?> tag = (NbtBase<?>) args[0].getValue();
NbtBase<?> child;
if (tag instanceof NbtCompound) {
checkType(args, 1, "string");
child = ((NbtCompound) tag).getValue((String) args[1].getValue());
} else if (tag instanceof NbtList<?>) {
checkType(args, 1, "int");
child = ((NbtList<?>) tag).getValue().get((Integer) args[1].getValue());
} else {
throw new IllegalArgumentException("Cannot fetch child of " + tag);
}
if (child == null) {
return null;
}
return new Var(context.getCommandContext().getDataTypes().get("nbt"), child);
}
示例13: 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);
}
示例14: getDeathTime
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入依赖的package包/类
public static long getDeathTime(ItemStack item) {
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item.clone()));
if (!nbt.containsKey(DEATH_TIME_TAG)) {
return 0;
}
return nbt.getLong(DEATH_TIME_TAG);
}
示例15: 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);
}