Search in sources :

Example 91 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class PlayerProfile method toNBT.

public CompoundTag toNBT() {
    CompoundTag profileTag = new CompoundTag();
    profileTag.putString("Id", uniqueId.toString());
    profileTag.putString("Name", name);
    CompoundTag propertiesTag = new CompoundTag();
    for (PlayerProperty property : properties) {
        CompoundTag propertyValueTag = new CompoundTag();
        if (property.isSigned()) {
            propertyValueTag.putString("Signature", property.getSignature());
        }
        propertyValueTag.putString("Value", property.getValue());
        propertiesTag.putCompoundList(property.getName(), Arrays.asList(propertyValueTag));
    }
    if (!propertiesTag.isEmpty()) {
        // Only add properties if not empty
        profileTag.putCompound("Properties", propertiesTag);
    }
    return profileTag;
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 92 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class GlowMetaBanner method readNbt.

@Override
void readNbt(CompoundTag tag) {
    super.readNbt(tag);
    if (tag.isCompound("BlockEntityTag")) {
        CompoundTag blockEntityTag = tag.getCompound("BlockEntityTag");
        if (blockEntityTag.isList("Patterns", TagType.COMPOUND)) {
            List<CompoundTag> patterns = blockEntityTag.getCompoundList("Patterns");
            this.patterns = BlockBanner.fromNBT(patterns);
        }
        if (blockEntityTag.isInt("Base")) {
            this.baseColor = DyeColor.getByWoolData((byte) blockEntityTag.getInt("Base"));
        }
    }
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 93 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class SummonCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender))
        return true;
    if (sender instanceof ConsoleCommandSender) {
        sender.sendMessage("This command can only be executed by a player or via command blocks.");
        return true;
    }
    Location location = null;
    if (sender instanceof Player) {
        location = ((Player) sender).getLocation().clone();
    } else if (sender instanceof BlockCommandSender) {
        location = ((BlockCommandSender) sender).getBlock().getLocation().clone();
    }
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    if (args.length >= 4) {
        location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
    }
    if (location == null) {
        return false;
    }
    location.setYaw(0.0f);
    location.setPitch(0.0f);
    CompoundTag tag = null;
    if (args.length >= 5) {
        String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
        try {
            tag = Mojangson.parseCompound(data);
        } catch (MojangsonParseException e) {
            sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage());
        }
    }
    String entityName = args[0];
    if (!checkSummon(sender, entityName)) {
        return true;
    }
    GlowEntity entity;
    if (EntityType.fromName(entityName) != null) {
        entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
    } else {
        Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
        entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
    }
    if (tag != null) {
        EntityStorage.load(entity, tag);
    }
    sender.sendMessage("Object successfully summoned.");
    return true;
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) MojangsonParseException(net.glowstone.util.mojangson.ex.MojangsonParseException) GlowEntity(net.glowstone.entity.GlowEntity) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Example 94 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Dragonet-Legacy by DragonetMC.

the class ProtocolTestUtils method getTag.

public static CompoundTag getTag() {
    CompoundTag tag = new CompoundTag();
    tag.putInt("int", 5);
    tag.putString("string", "text");
    tag.putList("list", TagType.FLOAT, Arrays.asList(1.f, 2.f, 3.f));
    tag.putCompound("compound", new CompoundTag());
    return tag;
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 95 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Dragonet-Legacy by DragonetMC.

the class PEInventorySlot method readSlot.

public static PEInventorySlot readSlot(PEBinaryReader reader) throws IOException {
    // Unsigned
    short id = (short) (reader.readShort() & 0xFFFF);
    if (id <= 0) {
        return new PEInventorySlot((short) 0, (byte) 0, (short) 0);
    }
    byte count = reader.readByte();
    short meta = reader.readShort();
    short lNbt = reader.readShort();
    if (lNbt <= 0) {
        return new PEInventorySlot(id, count, meta);
    }
    byte[] nbtData = reader.read(lNbt);
    NBTInputStream nbtin = new NBTInputStream(new ByteArrayInputStream(nbtData));
    CompoundTag nbt = nbtin.readCompound();
    nbtin.close();
    return new PEInventorySlot(id, count, meta, nbt);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NBTInputStream(net.glowstone.util.nbt.NBTInputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)95 ArrayList (java.util.ArrayList)21 Location (org.bukkit.Location)15 UUID (java.util.UUID)11 IOException (java.io.IOException)8 GlowEntity (net.glowstone.entity.GlowEntity)8 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)8 Material (org.bukkit.Material)7 File (java.io.File)6 NbtOutputStream (net.glowstone.util.nbt.NbtOutputStream)6 BlockEntity (net.glowstone.block.entity.BlockEntity)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 NbtInputStream (net.glowstone.util.nbt.NbtInputStream)5 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 EntityType (org.bukkit.entity.EntityType)4 List (java.util.List)3 GlowBlock (net.glowstone.block.GlowBlock)3 Tag (net.glowstone.util.nbt.Tag)3 Pattern (org.bukkit.block.banner.Pattern)3