Package net.glowstone.util.nbt

Examples of net.glowstone.util.nbt.CompoundTag


    }

    @Override
    public void readData(GlowPlayer player) {
        File playerFile = getPlayerFile(player.getUniqueId());
        CompoundTag playerTag = new CompoundTag();
        if (playerFile.exists()) {
            try (NBTInputStream in = new NBTInputStream(new FileInputStream(playerFile))) {
                playerTag = in.readCompound();
            } catch (IOException e) {
                player.kickPlayer("Failed to read player data!");
View Full Code Here


    }

    @Override
    public void writeData(GlowPlayer player) {
        File playerFile = getPlayerFile(player.getUniqueId());
        CompoundTag tag = new CompoundTag();
        EntityStorage.save(player, tag);
        try (NBTOutputStream out = new NBTOutputStream(new FileOutputStream(playerFile))) {
            out.writeTag(tag);
        } catch (IOException e) {
            player.kickPlayer("Failed to save player data!");
View Full Code Here

        @Override
        public long getFirstPlayed() {
            checkOpen();
            if (tag.isCompound("bukkit")) {
                CompoundTag bukkit = tag.getCompound("bukkit");
                if (bukkit.isLong("firstPlayed")) {
                    return bukkit.getLong("firstPlayed");
                }
            }
            return 0;
        }
View Full Code Here

        @Override
        public long getLastPlayed() {
            checkOpen();
            if (tag.isCompound("bukkit")) {
                CompoundTag bukkit = tag.getCompound("bukkit");
                if (bukkit.isLong("lastPlayed")) {
                    return bukkit.getLong("lastPlayed");
                }
            }
            return 0;
        }
View Full Code Here

        @Override
        public String getLastKnownName() {
            checkOpen();
            if (tag.isCompound("bukkit")) {
                CompoundTag bukkit = tag.getCompound("bukkit");
                if (bukkit.isString("lastKnownName")) {
                    return bukkit.getString("lastKnownName");
                }
            }
            return null;
        }
View Full Code Here

     * @param stack The stack to write, or null.
     * @param slot The slot, or negative to omit.
     * @return The resulting tag.
     */
    public static CompoundTag writeItem(ItemStack stack, int slot) {
        CompoundTag tag = new CompoundTag();
        if (stack == null || stack.getType() == Material.AIR) {
            return tag;
        }
        tag.putString("id", ItemIds.getName(stack.getType()));
        tag.putShort("Damage", stack.getDurability());
        tag.putByte("Count", stack.getAmount());
        if (slot >= 0) {
            tag.putByte("Slot", slot);
        }
        CompoundTag meta = GlowItemFactory.instance().writeNbt(stack.getItemMeta());
        if (meta != null) {
            tag.putCompound("tag", meta);
        }
        return tag;
    }
View Full Code Here

        if (uid == null) {
            uid = UUID.randomUUID();
        }

        // read in world information
        CompoundTag level = new CompoundTag();
        File levelFile = new File(dir, "level.dat");
        if (levelFile.exists()) {
            try (NBTInputStream in = new NBTInputStream(new FileInputStream(levelFile))) {
                level = in.readCompound();
                if (level.isCompound("Data")) {
                    level = level.getCompound("Data");
                } else {
                    server.getLogger().warning("Loading world \"" + world.getName() + "\": reading from root, not Data");
                }
            } catch (IOException e) {
                handleWorldException("level.dat", e);
            }
        }

        // seed
        long seed = 0L;
        if (level.isLong("RandomSeed")) {
            seed = level.getLong("RandomSeed");
            level.remove("RandomSeed");
        }

        // time of day and weather status
        if (level.isByte("thundering")) {
            world.setThundering(level.getBool("thundering"));
            level.remove("thundering");
        }
        if (level.isByte("raining")) {
            world.setStorm(level.getBool("raining"));
            level.remove("raining");
        }
        if (level.isInt("thunderTime")) {
            world.setThunderDuration(level.getInt("thunderTime"));
            level.remove("thunderTime");
        }
        if (level.isInt("rainTime")) {
            world.setWeatherDuration(level.getInt("rainTime"));
            level.remove("rainTime");
        }
        if (level.isLong("Time")) {
            world.setFullTime(level.getLong("Time"));
            level.remove("Time");
        }
        if (level.isLong("DayTime")) {
            world.setTime(level.getLong("DayTime"));
            level.remove("DayTime");
        }

        // spawn position
        if (level.isInt("SpawnX") && level.isInt("SpawnY") && level.isInt("SpawnZ")) {
            world.setSpawnLocation(level.getInt("SpawnX"), level.getInt("SpawnY"), level.getInt("SpawnZ"));
            level.remove("SpawnX");
            level.remove("SpawnY");
            level.remove("SpawnZ");
        }

        // game rules
        if (level.isCompound("GameRules")) {
            CompoundTag gameRules = level.getCompound("GameRules");
            for (String key : gameRules.getValue().keySet()) {
                if (gameRules.isString(key)) {
                    world.setGameRuleValue(key, gameRules.getString(key));
                }
            }
            level.remove("GameRules");
        }
View Full Code Here

        if (BlockSkull.canRotate((Skull) getBlock().getState().getData())) {
            rotation = tag.getByte("Rot");
        }
        if (tag.containsKey("Owner")) {
            CompoundTag ownerTag = tag.getCompound("Owner");
            owner = PlayerProfile.fromNBT(ownerTag);
        } else if (tag.containsKey("ExtraType")) {
            // Pre-1.8 uses just a name, instead of a profile object
            String name = tag.getString("ExtraType");
            if (name != null && !name.isEmpty()) {
View Full Code Here

    }

    @Override
    public void update(GlowPlayer player) {
        super.update(player);
        CompoundTag nbt = new CompoundTag();
        saveNbt(nbt);
        player.sendBlockEntityChange(getBlock().getLocation(), GlowBlockEntity.SKULL, nbt);
    }
View Full Code Here

                ", " + properties.size() + " properties" +
                '}';
    }

    public CompoundTag toNBT() {
        CompoundTag profileTag = new CompoundTag();
        profileTag.putString("Id", uuid.toString());
        profileTag.putString("Name", name);

        CompoundTag propertiesTag = new CompoundTag();
        for (PlayerProperty property : properties) {
            CompoundTag propertyValueTag = new CompoundTag();
            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);
View Full Code Here

TOP

Related Classes of net.glowstone.util.nbt.CompoundTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.