本文整理汇总了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);
}
});
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
});
}
示例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;
}
示例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()))));
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
});
}
示例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;
}
示例15: getScores
import org.spongepowered.api.scoreboard.Score; //导入依赖的package包/类
@Override
public Map<Text, Score> getScores() {
return ImmutableMap.copyOf(this.scores);
}