Search in sources :

Example 56 with CompoundTag

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

the class NbtScoreboardIoWriter method writeScores.

private static void writeScores(CompoundTag root, GlowScoreboard scoreboard) {
    List<CompoundTag> scores = new ArrayList<>();
    for (String objective : scoreboard.getEntries()) {
        for (Score score : scoreboard.getScores(objective)) {
            CompoundTag scoreNbt = new CompoundTag();
            scoreNbt.putInt("Score", score.getScore());
            scoreNbt.putString("Name", score.getEntry());
            scoreNbt.putString("Objective", score.getObjective().getName());
            scoreNbt.putByte("Locked", score.getLocked() ? 1 : 0);
            scores.add(scoreNbt);
        }
    }
    root.putCompoundList("PlayerScores", scores);
}
Also used : Score(org.bukkit.scoreboard.Score) ArrayList(java.util.ArrayList) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 57 with CompoundTag

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

the class NbtScoreboardIoWriter method writeTeams.

private static void writeTeams(CompoundTag root, GlowScoreboard scoreboard) {
    List<CompoundTag> teams = new ArrayList<>();
    for (Team team : scoreboard.getTeams()) {
        CompoundTag teamNbt = new CompoundTag();
        teamNbt.putByte("AllowFriendlyFire", team.allowFriendlyFire() ? 1 : 0);
        teamNbt.putByte("SeeFriendlyInvisibles", team.canSeeFriendlyInvisibles() ? 1 : 0);
        teamNbt.putString("NameTagVisibility", team.getOption(Team.Option.NAME_TAG_VISIBILITY).name().toLowerCase());
        switch(team.getOption(Team.Option.DEATH_MESSAGE_VISIBILITY)) {
            case NEVER:
                teamNbt.putString("DeathMessageVisibility", "never");
                break;
            case FOR_OTHER_TEAMS:
                teamNbt.putString("DeathMessageVisibility", "hideForOtherTeams");
                break;
            case FOR_OWN_TEAM:
                teamNbt.putString("DeathMessageVisibility", "hideForOwnTeam");
                break;
            default:
                teamNbt.putString("DeathMessageVisibility", "always");
        }
        switch(team.getOption(Team.Option.COLLISION_RULE)) {
            case NEVER:
                teamNbt.putString("CollisionRule", "never");
                break;
            case FOR_OTHER_TEAMS:
                teamNbt.putString("CollisionRule", "pushOtherTeams");
                break;
            case FOR_OWN_TEAM:
                teamNbt.putString("CollisionRule", "pushOwnTeam");
                break;
            default:
                teamNbt.putString("CollisionRule", "always");
        }
        teamNbt.putString("DisplayName", team.getDisplayName());
        teamNbt.putString("Name", team.getName());
        teamNbt.putString("Prefix", team.getPrefix());
        teamNbt.putString("Suffix", team.getSuffix());
        teamNbt.putString("TeamColor", team.getColor().name().toLowerCase());
        List<String> players = team.getEntries().stream().collect(Collectors.toList());
        teamNbt.putList("Players", TagType.STRING, players);
        teams.add(teamNbt);
    }
    root.putCompoundList("Teams", teams);
}
Also used : ArrayList(java.util.ArrayList) Team(org.bukkit.scoreboard.Team) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 58 with CompoundTag

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

the class NbtScoreboardIoWriter method writeDisplaySlots.

private static void writeDisplaySlots(CompoundTag root, GlowScoreboard scoreboard) {
    CompoundTag slots = new CompoundTag();
    if (scoreboard.getObjective(DisplaySlot.PLAYER_LIST) != null) {
        slots.putString("slot_0", scoreboard.getObjective(DisplaySlot.PLAYER_LIST).getName());
    }
    if (scoreboard.getObjective(DisplaySlot.SIDEBAR) != null) {
        slots.putString("slot_1", scoreboard.getObjective(DisplaySlot.SIDEBAR).getName());
    }
    if (scoreboard.getObjective(DisplaySlot.BELOW_NAME) != null) {
        slots.putString("slot_2", scoreboard.getObjective(DisplaySlot.BELOW_NAME).getName());
    }
    root.putCompound("DisplaySlots", slots);
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)58 ArrayList (java.util.ArrayList)9 NBTInputStream (net.glowstone.util.nbt.NBTInputStream)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)3 BlockEntity (net.glowstone.block.entity.BlockEntity)3 GlowEntity (net.glowstone.entity.GlowEntity)3 ByteBuf (io.netty.buffer.ByteBuf)2 FileOutputStream (java.io.FileOutputStream)2 UUID (java.util.UUID)2 ChunkSection (net.glowstone.chunk.ChunkSection)2 AttributeManager (net.glowstone.entity.AttributeManager)2 Modifier (net.glowstone.entity.AttributeManager.Modifier)2 GlowStructure (net.glowstone.generator.structures.GlowStructure)2 StructureBoundingBox (net.glowstone.generator.structures.util.StructureBoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 Material (org.bukkit.Material)2