use of net.minecraft.scoreboard.ScoreObjective 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);
}
use of net.minecraft.scoreboard.ScoreObjective 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);
}
use of net.minecraft.scoreboard.ScoreObjective 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);
}
}
use of net.minecraft.scoreboard.ScoreObjective 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);
}
}
}
use of net.minecraft.scoreboard.ScoreObjective in project SpongeCommon by SpongePowered.
the class SpongeObjective method getObjectiveFor.
public ScoreObjective getObjectiveFor(net.minecraft.scoreboard.Scoreboard scoreboard) {
if (this.objectives.containsKey(scoreboard)) {
return this.objectives.get(scoreboard);
}
ScoreObjective objective = new ScoreObjective(scoreboard, this.name, (IScoreCriteria) this.criterion);
// We deliberately set the fields here instead of using the methods.
// Since a new objective is being created here, we want to avoid
// sending packets until everything is in the proper state.
objective.displayName = SpongeTexts.toLegacy(this.displayName);
objective.renderType = (IScoreCriteria.EnumRenderType) (Object) this.displayMode;
((IMixinScoreObjective) objective).setSpongeObjective(this);
this.objectives.put(scoreboard, objective);
return objective;
}
Aggregations