Search in sources :

Example 1 with SpongeObjective

use of org.spongepowered.common.scoreboard.SpongeObjective in project SpongeCommon by SpongePowered.

the class MixinScoreboardLogic method scoreboard$removeObjective.

@SuppressWarnings({ "rawtypes" })
public void scoreboard$removeObjective(Objective objective) {
    ScoreObjective scoreObjective = ((SpongeObjective) objective).getObjectiveFor(this);
    this.scoreObjectives.remove(scoreObjective.getName());
    for (int i = 0; i < 19; ++i) {
        if (this.getObjectiveInDisplaySlot(i) == scoreObjective) {
            this.setObjectiveInDisplaySlot(i, null);
        }
    }
    this.sendToPlayers(new SPacketScoreboardObjective(scoreObjective, SpongeScoreboardConstants.OBJECTIVE_PACKET_REMOVE));
    List list = this.scoreObjectiveCriterias.get(scoreObjective.getCriteria());
    if (list != null) {
        list.remove(scoreObjective);
    }
    for (Map<ScoreObjective, net.minecraft.scoreboard.Score> scoreMap : this.entitiesScoreObjectives.values()) {
        Score score = scoreMap.remove(scoreObjective);
        if (score != null) {
            ((IMixinScore) score).getSpongeScore().removeScoreFor(scoreObjective);
        }
    }
    // We deliberately don't call func_96533_c, because there's no need
    this.markSaveDataDirty();
    ((SpongeObjective) objective).removeObjectiveFor(this);
}
Also used : IMixinScore(org.spongepowered.common.interfaces.IMixinScore) Score(net.minecraft.scoreboard.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) SPacketScoreboardObjective(net.minecraft.network.play.server.SPacketScoreboardObjective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SpongeObjective

use of org.spongepowered.common.scoreboard.SpongeObjective in project SpongeCommon by SpongePowered.

the class MixinScoreboardLogic method scoreboard$addObjective.

@SuppressWarnings({ "RedundantCast" })
public void scoreboard$addObjective(Objective objective) {
    if (this.scoreObjectives.containsKey(objective.getName())) {
        throw new IllegalArgumentException("An objective with the name \'" + objective.getName() + "\' already exists!");
    }
    ScoreObjective scoreObjective = ((SpongeObjective) objective).getObjectiveFor(this);
    List<ScoreObjective> objectives = this.scoreObjectiveCriterias.get(objective.getCriterion());
    if (objectives == null) {
        objectives = new ArrayList<>();
        this.scoreObjectiveCriterias.put((IScoreCriteria) objective.getCriterion(), objectives);
    }
    objectives.add(scoreObjective);
    this.scoreObjectives.put(objective.getName(), scoreObjective);
    this.onScoreObjectiveAdded(scoreObjective);
    ((SpongeObjective) objective).updateScores(this);
}
Also used : ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective)

Example 3 with SpongeObjective

use of org.spongepowered.common.scoreboard.SpongeObjective in project SpongeCommon by SpongePowered.

the class MixinScoreboardLogic method scoreboard$removeScores.

public void scoreboard$removeScores(Text name) {
    for (ScoreObjective objective : this.scoreObjectives.values()) {
        SpongeObjective spongeObjective = ((IMixinScoreObjective) objective).getSpongeObjective();
        spongeObjective.getScore(name).ifPresent(spongeObjective::removeScore);
    }
}
Also used : ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective)

Example 4 with SpongeObjective

use of org.spongepowered.common.scoreboard.SpongeObjective in project SpongeCommon by SpongePowered.

the class MixinScoreboardLogic method removeObjectiveFromEntity.

@Override
public void removeObjectiveFromEntity(String name, ScoreObjective objective) {
    if (objective != null) {
        SpongeObjective spongeObjective = ((IMixinScoreObjective) objective).getSpongeObjective();
        Optional<org.spongepowered.api.scoreboard.Score> score = spongeObjective.getScore(SpongeTexts.fromLegacy(name));
        if (score.isPresent()) {
            spongeObjective.removeScore(score.get());
        } else {
            SpongeImpl.getLogger().warn("Objective " + objective + " did have have the score " + name);
        }
    } else {
        Text textName = SpongeTexts.fromLegacy(name);
        for (ScoreObjective scoreObjective : this.scoreObjectives.values()) {
            ((IMixinScoreObjective) scoreObjective).getSpongeObjective().removeScore(textName);
        }
    }
}
Also used : IMixinScore(org.spongepowered.common.interfaces.IMixinScore) Score(net.minecraft.scoreboard.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Text(org.spongepowered.api.text.Text)

Example 5 with SpongeObjective

use of org.spongepowered.common.scoreboard.SpongeObjective in project SpongeCommon by SpongePowered.

the class SpongeObjectiveBuilder method build.

@Override
public Objective build() throws IllegalStateException {
    checkState(this.name != null, "Name cannot be null");
    checkState(this.criterion != null, "Criterion cannot be null");
    SpongeObjective objective = new SpongeObjective(this.name, this.criterion);
    if (this.displayName != null) {
        objective.setDisplayName(this.displayName);
    }
    if (this.objectiveDisplayMode != null) {
        objective.setDisplayMode(this.objectiveDisplayMode);
    } else if (this.criterion instanceof IScoreCriteria) {
        objective.setDisplayMode((ObjectiveDisplayMode) (Object) ((IScoreCriteria) this.criterion).getRenderType());
    }
    return objective;
}
Also used : IScoreCriteria(net.minecraft.scoreboard.IScoreCriteria) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) ObjectiveDisplayMode(org.spongepowered.api.scoreboard.objective.displaymode.ObjectiveDisplayMode)

Aggregations

SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)7 ScoreObjective (net.minecraft.scoreboard.ScoreObjective)4 IMixinScoreObjective (org.spongepowered.common.interfaces.IMixinScoreObjective)4 Score (net.minecraft.scoreboard.Score)2 IMixinScore (org.spongepowered.common.interfaces.IMixinScore)2 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SPacketDisplayObjective (net.minecraft.network.play.server.SPacketDisplayObjective)1 SPacketScoreboardObjective (net.minecraft.network.play.server.SPacketScoreboardObjective)1 IScoreCriteria (net.minecraft.scoreboard.IScoreCriteria)1 ObjectiveDisplayMode (org.spongepowered.api.scoreboard.objective.displaymode.ObjectiveDisplayMode)1 Text (org.spongepowered.api.text.Text)1 SpongeDisplaySlot (org.spongepowered.common.scoreboard.SpongeDisplaySlot)1