Search in sources :

Example 26 with ListTag

use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.

the class Server method getOfflinePlayerData.

public CompoundTag getOfflinePlayerData(String name) {
    name = name.toLowerCase();
    String path = this.getDataPath() + "players/";
    File file = new File(path + name + ".dat");
    if (this.shouldSavePlayerData() && file.exists()) {
        try {
            return NBTIO.readCompressed(new FileInputStream(file));
        } catch (Exception e) {
            file.renameTo(new File(path + name + ".dat.bak"));
            this.logger.notice(this.getLanguage().translateString("nukkit.data.playerCorrupted", name));
        }
    } else {
        this.logger.notice(this.getLanguage().translateString("nukkit.data.playerNotFound", name));
    }
    Position spawn = this.getDefaultLevel().getSafeSpawn();
    CompoundTag nbt = new CompoundTag().putLong("firstPlayed", System.currentTimeMillis() / 1000).putLong("lastPlayed", System.currentTimeMillis() / 1000).putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("0", spawn.x)).add(new DoubleTag("1", spawn.y)).add(new DoubleTag("2", spawn.z))).putString("Level", this.getDefaultLevel().getName()).putList(new ListTag<>("Inventory")).putCompound("Achievements", new CompoundTag()).putInt("playerGameType", this.getGamemode()).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("0", 0)).add(new DoubleTag("1", 0)).add(new DoubleTag("2", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("0", 0)).add(new FloatTag("1", 0))).putFloat("FallDistance", 0).putShort("Fire", 0).putShort("Air", 300).putBoolean("OnGround", true).putBoolean("Invulnerable", false).putString("NameTag", name);
    this.saveOfflinePlayerData(name, nbt);
    return nbt;
}
Also used : FloatTag(cn.nukkit.nbt.tag.FloatTag) Position(cn.nukkit.level.Position) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 27 with ListTag

use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.

the class EntityHumanType method initEntity.

@Override
protected void initEntity() {
    this.inventory = new PlayerInventory(this);
    if (this.namedTag.contains("Inventory") && this.namedTag.get("Inventory") instanceof ListTag) {
        ListTag<CompoundTag> inventoryList = this.namedTag.getList("Inventory", CompoundTag.class);
        for (CompoundTag item : inventoryList.getAll()) {
            int slot = item.getByte("Slot");
            if (slot >= 0 && slot < 9) {
                // hotbar
                // Old hotbar saving stuff, remove it (useless now)
                inventoryList.remove(item);
            } else if (slot >= 100 && slot < 104) {
                this.inventory.setItem(this.inventory.getSize() + slot - 100, NBTIO.getItemHelper(item));
            } else {
                this.inventory.setItem(slot - 9, NBTIO.getItemHelper(item));
            }
        }
    }
    this.enderChestInventory = new PlayerEnderChestInventory(this);
    if (this.namedTag.contains("EnderItems") && this.namedTag.get("EnderItems") instanceof ListTag) {
        ListTag<CompoundTag> inventoryList = this.namedTag.getList("EnderItems", CompoundTag.class);
        for (CompoundTag item : inventoryList.getAll()) {
            this.enderChestInventory.setItem(item.getByte("Slot"), NBTIO.getItemHelper(item));
        }
    }
    super.initEntity();
}
Also used : PlayerEnderChestInventory(cn.nukkit.inventory.PlayerEnderChestInventory) PlayerInventory(cn.nukkit.inventory.PlayerInventory) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)27 ListTag (cn.nukkit.nbt.tag.ListTag)27 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Entity (cn.nukkit.entity.Entity)5 StringTag (cn.nukkit.nbt.tag.StringTag)5 Tag (cn.nukkit.nbt.tag.Tag)5 BlockRail (cn.nukkit.block.BlockRail)4 BlockEntity (cn.nukkit.blockentity.BlockEntity)4 Rail (cn.nukkit.utils.Rail)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 Player (cn.nukkit.Player)2 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)2 EntityProjectile (cn.nukkit.entity.projectile.EntityProjectile)2 ProjectileLaunchEvent (cn.nukkit.event.entity.ProjectileLaunchEvent)2 FullChunk (cn.nukkit.level.format.FullChunk)2 Random (java.util.Random)2 BlockAir (cn.nukkit.block.BlockAir)1 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1