Search in sources :

Example 1 with LanternDisplaySlot

use of org.lanternpowered.server.scoreboard.LanternDisplaySlot in project LanternServer by LanternPowered.

the class CodecPlayOutScoreboardDisplayObjective method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutScoreboardDisplayObjective message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeByte((byte) ((LanternDisplaySlot) message.getDisplaySlot()).getInternalId());
    String objectiveName = message.getObjectiveName();
    buf.writeString(objectiveName == null ? "" : objectiveName);
    return buf;
}
Also used : LanternDisplaySlot(org.lanternpowered.server.scoreboard.LanternDisplaySlot) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 2 with LanternDisplaySlot

use of org.lanternpowered.server.scoreboard.LanternDisplaySlot in project LanternServer by LanternPowered.

the class DisplaySlotRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    register(new LanternDisplaySlot("minecraft", "list", null, 0));
    register(new LanternDisplaySlot("minecraft", "sidebar", null, 1));
    register(new LanternDisplaySlot("minecraft", "below_name", "belowName", null, 2));
    for (TextColor textColor : Sponge.getRegistry().getAllOf(TextColor.class)) {
        // There is not mapping for "none"
        if (textColor == TextColors.NONE) {
            continue;
        }
        final char character = FormattingCodeTextSerializer.FORMATS_TO_CODE.get(textColor);
        final String id = "below_name_" + textColor.getId();
        final String name = "sidebar.team." + textColor.getId();
        register(new LanternDisplaySlot("minecraft", id, name, textColor, 3 + character));
    }
}
Also used : LanternDisplaySlot(org.lanternpowered.server.scoreboard.LanternDisplaySlot) TextColor(org.spongepowered.api.text.format.TextColor)

Example 3 with LanternDisplaySlot

use of org.lanternpowered.server.scoreboard.LanternDisplaySlot in project LanternServer by LanternPowered.

the class ScoreboardIO method write.

public static void write(Path folder, Scoreboard scoreboard) throws IOException {
    final List<DataView> objectives = scoreboard.getObjectives().stream().map(objective -> DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED).set(NAME, objective.getName()).set(DISPLAY_NAME, ((LanternObjective) objective).getLegacyDisplayName()).set(CRITERION_NAME, objective.getCriterion().getId()).set(DISPLAY_MODE, objective.getDisplayMode().getId())).collect(Collectors.toList());
    final List<DataView> scores = new ArrayList<>();
    for (Score score : scoreboard.getScores()) {
        final Iterator<Objective> it = score.getObjectives().iterator();
        final DataView baseView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED).set(NAME, ((LanternScore) score).getLegacyName()).set(SCORE, score.getScore());
        // TODO: Locked state
        final DataView mainView = baseView.copy().set(OBJECTIVE, it.next().getName());
        final List<String> extraObjectives = new ArrayList<>();
        while (it.hasNext()) {
            final String extraObjectiveName = it.next().getName();
            scores.add(baseView.copy().set(OBJECTIVE, extraObjectiveName).set(INVALID, (byte) 1));
            extraObjectives.add(extraObjectiveName);
        }
        if (!extraObjectives.isEmpty()) {
            mainView.set(EXTRA_OBJECTIVES, extraObjectives);
        }
    }
    final List<DataView> teams = new ArrayList<>();
    for (Team team : scoreboard.getTeams()) {
        final DataView container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED).set(ALLOW_FRIENDLY_FIRE, (byte) (team.allowFriendlyFire() ? 1 : 0)).set(CAN_SEE_FRIENDLY_INVISIBLES, (byte) (team.canSeeFriendlyInvisibles() ? 1 : 0)).set(NAME_TAG_VISIBILITY, team.getNameTagVisibility().getName()).set(NAME, team.getName()).set(DISPLAY_NAME, ((LanternTeam) team).getLegacyDisplayName()).set(DEATH_MESSAGE_VISIBILITY, team.getDeathMessageVisibility().getName()).set(COLLISION_RULE, team.getCollisionRule().getName()).set(PREFIX, ((LanternTeam) team).getLegacyPrefix()).set(SUFFIX, ((LanternTeam) team).getLegacySuffix());
        final TextColor teamColor = team.getColor();
        if (teamColor != TextColors.NONE) {
            container.set(TEAM_COLOR, teamColor.getId());
        }
        final Set<Text> members = team.getMembers();
        container.set(MEMBERS, members.stream().map(LanternTexts::toLegacy).collect(Collectors.toList()));
        teams.add(container);
    }
    final DataContainer rootDataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    final DataView dataView = rootDataContainer.createView(DATA).set(OBJECTIVES, objectives).set(SCORES, scores).set(TEAMS, teams);
    final DataView displaySlots = dataView.createView(DISPLAY_SLOTS);
    ((LanternScoreboard) scoreboard).getObjectivesInSlot().entrySet().forEach(entry -> displaySlots.set(DataQuery.of("slot_" + ((LanternDisplaySlot) entry.getKey()).getInternalId()), entry.getValue().getName()));
    IOHelper.write(folder.resolve(SCOREBOARD_DATA), file -> {
        NbtStreamUtils.write(rootDataContainer, Files.newOutputStream(file), true);
        return true;
    });
}
Also used : CollisionRule(org.spongepowered.api.scoreboard.CollisionRule) Visibility(org.spongepowered.api.scoreboard.Visibility) HashMap(java.util.HashMap) LanternTexts(org.lanternpowered.server.text.LanternTexts) DataQuery(org.spongepowered.api.data.DataQuery) LanternObjective(org.lanternpowered.server.scoreboard.LanternObjective) ArrayList(java.util.ArrayList) ObjectiveDisplayMode(org.spongepowered.api.scoreboard.objective.displaymode.ObjectiveDisplayMode) NbtStreamUtils(org.lanternpowered.server.data.persistence.nbt.NbtStreamUtils) Matcher(java.util.regex.Matcher) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor) Map(java.util.Map) Objective(org.spongepowered.api.scoreboard.objective.Objective) TextColors(org.spongepowered.api.text.format.TextColors) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) DisplaySlotRegistryModule(org.lanternpowered.server.game.registry.type.scoreboard.DisplaySlotRegistryModule) Iterator(java.util.Iterator) Files(java.nio.file.Files) Criterion(org.spongepowered.api.scoreboard.critieria.Criterion) Sponge(org.spongepowered.api.Sponge) DataContainer(org.spongepowered.api.data.DataContainer) Visibilities(org.spongepowered.api.scoreboard.Visibilities) Set(java.util.Set) LanternDisplaySlot(org.lanternpowered.server.scoreboard.LanternDisplaySlot) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) Team(org.spongepowered.api.scoreboard.Team) IOException(java.io.IOException) LanternTeam(org.lanternpowered.server.scoreboard.LanternTeam) Collectors(java.util.stream.Collectors) Score(org.spongepowered.api.scoreboard.Score) Criteria(org.spongepowered.api.scoreboard.critieria.Criteria) LanternScore(org.lanternpowered.server.scoreboard.LanternScore) List(java.util.List) DataView(org.spongepowered.api.data.DataView) CollisionRules(org.spongepowered.api.scoreboard.CollisionRules) Lantern(org.lanternpowered.server.game.Lantern) ObjectiveDisplayModes(org.spongepowered.api.scoreboard.objective.displaymode.ObjectiveDisplayModes) Pattern(java.util.regex.Pattern) LanternScoreboard(org.lanternpowered.server.scoreboard.LanternScoreboard) LanternScore(org.lanternpowered.server.scoreboard.LanternScore) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) DataView(org.spongepowered.api.data.DataView) LanternObjective(org.lanternpowered.server.scoreboard.LanternObjective) Objective(org.spongepowered.api.scoreboard.objective.Objective) Score(org.spongepowered.api.scoreboard.Score) LanternScore(org.lanternpowered.server.scoreboard.LanternScore) DataContainer(org.spongepowered.api.data.DataContainer) LanternDisplaySlot(org.lanternpowered.server.scoreboard.LanternDisplaySlot) LanternTexts(org.lanternpowered.server.text.LanternTexts) LanternScoreboard(org.lanternpowered.server.scoreboard.LanternScoreboard) Team(org.spongepowered.api.scoreboard.Team) LanternTeam(org.lanternpowered.server.scoreboard.LanternTeam) TextColor(org.spongepowered.api.text.format.TextColor) LanternTeam(org.lanternpowered.server.scoreboard.LanternTeam)

Aggregations

LanternDisplaySlot (org.lanternpowered.server.scoreboard.LanternDisplaySlot)3 TextColor (org.spongepowered.api.text.format.TextColor)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 NbtStreamUtils (org.lanternpowered.server.data.persistence.nbt.NbtStreamUtils)1 Lantern (org.lanternpowered.server.game.Lantern)1 DisplaySlotRegistryModule (org.lanternpowered.server.game.registry.type.scoreboard.DisplaySlotRegistryModule)1 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1 LanternObjective (org.lanternpowered.server.scoreboard.LanternObjective)1