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;
}
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));
}
}
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;
});
}
Aggregations