当前位置: 首页>>代码示例>>Java>>正文


Java Score类代码示例

本文整理汇总了Java中org.spongepowered.api.scoreboard.Score的典型用法代码示例。如果您正苦于以下问题:Java Score类的具体用法?Java Score怎么用?Java Score使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Score类属于org.spongepowered.api.scoreboard包,在下文中一共展示了Score类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public void execute(SurvivalGame survivalGame) throws TextMessageException {
    deadPlayer
            .getScoreboard()
            .getObjective(DisplaySlots.SIDEBAR)
            .ifPresent(
                    objective -> {
                        objective.removeScore(Text.of(deadPlayer.getName()));
                        if (killingPlayer != null) {
                            Score k =
                                    objective.getOrCreateScore(
                                            Text.of(killingPlayer.getName()));
                            k.setScore(k.getScore() + 1);
                        }
                    });
}
 
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:17,代码来源:UpdateScoreBoardTask.java

示例2: addToObjective

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
private static Score addToObjective(Objective objective, @Nullable Score score, Text name, int value) {
    if (score == null) {
        score = objective.getOrCreateScore(name);
        score.setScore(value);
    } else {
        objective.addScore(score);
    }
    return score;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:ScoreboardIO.java

示例3: deserialize

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public ScoreText deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    final JsonObject obj = element.getAsJsonObject();
    final Text name = LanternTexts.fromLegacy(obj.get(SCORE_NAME).getAsString());
    // Try to parse the value
    int value = 0;
    try {
        value = Integer.parseInt(obj.get(SCORE_VALUE).getAsString());
    } catch (NumberFormatException ignored) {
    }
    final String baseObjective = obj.get(SCORE_MAIN_OBJECTIVE).getAsString();
    final Set<Objective> objectives = new HashSet<>();
    if (!baseObjective.isEmpty()) {
        this.tryAddObjective(baseObjective, objectives);
    }
    if ((element = obj.get(SCORE_EXTRA_OBJECTIVES)) != null) {
        final JsonArray array = element.getAsJsonArray();
        for (JsonElement jsonElement : array) {
            this.tryAddObjective(jsonElement.getAsString(), objectives);
        }
    }
    String override = null;
    if ((element = obj.get(SCORE_OVERRIDE)) != null) {
        override = element.getAsString();
    }

    final Score score = new LanternScore(name);
    // TODO: How to handle the objectives?
    // We cannot add them to the score without attaching the
    // score to the objective
    score.setScore(value);

    final ScoreText.Builder builder = Text.builder(score).override(override);
    deserialize(obj, builder, context);
    return builder.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:37,代码来源:JsonTextScoreSerializer.java

示例4: createScoreArgumentType

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public Limit<ArgumentType<Integer>> createScoreArgumentType(String name) {
    if (!this.scoreToTypeMap.containsKey(name)) {
        LanternArgumentType<Integer> min = this.createArgumentType("score_" + name + "_min", Integer.class,
                Score.class.getName());
        LanternArgumentType<Integer> max = this.createArgumentType("score_" + name, Integer.class,
                Score.class.getName());
        this.scoreToTypeMap.put(name, new LanternArgumentHolder.LanternLimit<>(min, max));
    }
    return this.scoreToTypeMap.get(name);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:LanternSelectorFactory.java

示例5: addScore

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public void addScore(Score score) throws IllegalArgumentException {
    if (this.scores.containsKey(checkNotNull(score, "score").getName())) {
        throw new IllegalArgumentException(String.format("A score with the name %s already exists!",
                ((LanternScore) score).getLegacyName()));
    }
    this.scores.put(score.getName(), score);
    ((LanternScore) score).addObjective(this);
    this.sendScoreToClient(score);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternObjective.java

示例6: sendScoreToClient

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
private void sendScoreToClient(Score score) {
    if (!this.scoreboards.isEmpty()) {
        List<Message> message = Collections.singletonList(new MessagePlayOutScoreboardScore.CreateOrUpdate(this.getName(),
                LanternTexts.toLegacy(score.getName()), score.getScore()));
        for (Scoreboard scoreboard : this.scoreboards) {
            ((LanternScoreboard) scoreboard).sendToPlayers(() -> message);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:LanternObjective.java

示例7: getOrCreateScore

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public Score getOrCreateScore(Text name) {
    return this.scores.computeIfAbsent(name, name1 -> {
        final LanternScore score = new LanternScore(name1);
        score.addObjective(this);
        this.sendScoreToClient(score);
        return score;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:LanternObjective.java

示例8: removeScore

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public boolean removeScore(Score score) {
    if (this.scores.remove(checkNotNull(score, "score").getName(), score)) {
        ((LanternScore) score).removeObjective(this);
        this.updateClientAfterRemove(score);
        return true;
    }
    return false;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:LanternObjective.java

示例9: updateClientAfterRemove

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
private void updateClientAfterRemove(Score score) {
    final Map<Objective, Message> messages = new HashMap<>();
    for (Scoreboard scoreboard : this.scoreboards) {
        ((LanternScoreboard) scoreboard).sendToPlayers(() -> Collections.singletonList(
                messages.computeIfAbsent(this, obj -> new MessagePlayOutScoreboardScore.Remove(
                        this.getName(), ((LanternScore) score).getLegacyName()))));
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternObjective.java

示例10: createObjectiveInitMessages

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
private List<Message> createObjectiveInitMessages(Objective objective) {
    final List<Message> messages = new ArrayList<>();
    messages.add(new MessagePlayOutScoreboardObjective.Create(
            objective.getName(), ((LanternObjective) objective).getLegacyDisplayName(), objective.getDisplayMode()));
    for (Score score : ((LanternObjective) objective).scores.values()) {
        messages.add(new MessagePlayOutScoreboardScore.CreateOrUpdate(objective.getName(),
                LanternTexts.toLegacy(score.getName()), score.getScore()));
    }
    return messages;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternScoreboard.java

示例11: getScores

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public Set<Score> getScores() {
    final ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
    for (Objective objective : this.objectives.values()) {
        scores.addAll(((LanternObjective) objective).scores.values());
    }
    return scores.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternScoreboard.java

示例12: createPlayerScoreSpec

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
private static CommandSpec createPlayerScoreSpec(BiConsumer<Score, Integer> scoreConsumer) {
    return CommandSpec.builder()
            .arguments(
                    GenericArguments.string(Text.of("target")),
                    GenericArguments.string(Text.of("objective")),
                    GenericArguments.integer(Text.of("score"))
            )
            .executor((src, args) -> {
                // Get the scoreboard of the world the command source is located in
                final Scoreboard scoreboard = CommandHelper.getWorld(src, args).getScoreboard();

                String objectiveName = args.<String>getOne("objective").get();
                Objective objective = scoreboard.getObjective(objectiveName).orElseThrow(
                        () -> new CommandException(t("commands.scoreboard.objectiveNotFound", objectiveName)));
                String target = args.<String>getOne("target").get();

                Collection<Score> scores;
                if (target.equals("*")) {
                    scores = objective.getScores().values();
                } else {
                    scores = Collections.singletonList(objective.getOrCreateScore(Text.of(target)));
                }
                int value = args.<Integer>getOne("score").get();

                scores.forEach(score -> {
                    scoreConsumer.accept(score, value);
                    src.sendMessage(t("commands.scoreboard.players.set.success",
                            objectiveName, ((LanternScore) score).getLegacyName(), score.getScore()));
                });

                return CommandResult.success();
            })
            .build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:35,代码来源:CommandScoreboard.java

示例13: write

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
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;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:69,代码来源:ScoreboardIO.java

示例14: serialize

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public JsonElement serialize(ScoreText src, Type typeOfSrc, JsonSerializationContext context) {
    // Lantern:
    // This is a field added by sponge to be able to override
    // the text provided by this component.
    final Optional<String> override = src.getOverride();
    // If we are using the networking format and there is an override present, just use
    // the override as a literal text object
    if (this.networkingFormat && override.isPresent()) {
        return new JsonPrimitive(override.get());
    }
    // There are here some extra fields to represent the (lantern/sponge) score text object,
    // while they are not supported by sponge itself, it seems worth it to provide this
    // This will still remain compatible with vanilla.
    final JsonObject obj = new JsonObject();
    final Score score = src.getScore();
    obj.addProperty(SCORE_NAME, LanternTexts.toLegacy(score.getName()));
    final Iterator<Objective> it = score.getObjectives().iterator();
    if (it.hasNext()) {
        obj.addProperty(SCORE_MAIN_OBJECTIVE, it.next().getName());
        // Lantern:
        // Provide a list with all the extra objectives that
        // are attached to the score.
        // There is no need to send this to the client.
        if (!this.networkingFormat) {
            if (it.hasNext()) {
                final JsonArray array = new JsonArray();
                while (it.hasNext()) {
                    array.add(new JsonPrimitive(it.next().getName()));
                }
                obj.add(SCORE_EXTRA_OBJECTIVES, array);
            }
        }
    } else {
        // This field must always be specified to be valid score json,
        // making it empty will prevent issues
        obj.addProperty(SCORE_MAIN_OBJECTIVE, "");
    }
    override.ifPresent(v -> obj.addProperty(SCORE_OVERRIDE, override.get()));
    obj.addProperty(SCORE_VALUE, Integer.toString(score.getScore()));
    serialize(obj, src, context);
    return obj;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:44,代码来源:JsonTextScoreSerializer.java

示例15: getScores

import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public Map<Text, Score> getScores() {
    return ImmutableMap.copyOf(this.scores);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternObjective.java


注:本文中的org.spongepowered.api.scoreboard.Score类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。