Search in sources :

Example 1 with ObjectiveBridge

use of org.spongepowered.common.bridge.world.scores.ObjectiveBridge in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method resetPlayerScore.

@Override
public void resetPlayerScore(final String name, final net.minecraft.world.scores.Objective objective) {
    final LegacyComponentSerializer lcs = LegacyComponentSerializer.legacySection();
    if (objective != null) {
        final SpongeObjective spongeObjective = ((ObjectiveBridge) objective).bridge$getSpongeObjective();
        final Optional<org.spongepowered.api.scoreboard.Score> score = spongeObjective.findScore(lcs.deserialize(name));
        if (score.isPresent()) {
            spongeObjective.removeScore(score.get());
        } else {
            SpongeCommon.logger().warn("Objective {} did have have the score", name);
        }
    } else {
        final Component textName = lcs.deserialize(name);
        for (final net.minecraft.world.scores.Objective scoreObjective : this.getObjectives()) {
            ((ObjectiveBridge) scoreObjective).bridge$getSpongeObjective().removeScore(textName);
        }
    }
}
Also used : Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) ObjectiveBridge(org.spongepowered.common.bridge.world.scores.ObjectiveBridge) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Component(net.kyori.adventure.text.Component) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)

Example 2 with ObjectiveBridge

use of org.spongepowered.common.bridge.world.scores.ObjectiveBridge in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin_API method removeScores.

@Override
public void removeScores(final Component name) {
    Objects.requireNonNull(name);
    for (final net.minecraft.world.scores.Objective objective : ((ScoreboardAccessor) this).accessor$objectivesByName().values()) {
        final SpongeObjective spongeObjective = ((ObjectiveBridge) objective).bridge$getSpongeObjective();
        spongeObjective.findScore(name).ifPresent(spongeObjective::removeScore);
    }
}
Also used : ObjectiveBridge(org.spongepowered.common.bridge.world.scores.ObjectiveBridge) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective)

Aggregations

ObjectiveBridge (org.spongepowered.common.bridge.world.scores.ObjectiveBridge)2 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)2 Component (net.kyori.adventure.text.Component)1 LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)1 Score (net.minecraft.world.scores.Score)1 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)1