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


Java Score.setScore方法代码示例

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


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

示例1: 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

示例2: 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


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