Search in sources :

Example 1 with Score

use of net.minecraft.scoreboard.Score 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 Score

use of net.minecraft.scoreboard.Score 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 3 with Score

use of net.minecraft.scoreboard.Score in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method onDeath.

/**
 * @author blood - May 12th, 2016
 * @author gabizou - June 3rd, 2016
 *
 * @reason SpongeForge requires an overwrite so we do it here instead. This handles player death events.
 */
@Override
@Overwrite
public void onDeath(DamageSource cause) {
    // Sponge start
    DestructEntityEvent.Death event = SpongeCommonEventFactory.callDestructEntityEventDeath((EntityPlayerMP) (Object) this, cause);
    // Double check that the PhaseTracker is already capturing the Death phase
    final PhaseTracker phaseTracker;
    final boolean tracksEntityDeaths;
    if (!this.world.isRemote) {
        phaseTracker = PhaseTracker.getInstance();
        final PhaseData peek = phaseTracker.getCurrentPhaseData();
        final IPhaseState state = peek.state;
        tracksEntityDeaths = state.tracksEntityDeaths();
    } else {
        phaseTracker = null;
        tracksEntityDeaths = false;
    }
    try (PhaseContext<?> context = !tracksEntityDeaths ? EntityPhase.State.DEATH.createPhaseContext().source(this).setDamageSource((org.spongepowered.api.event.cause.entity.damage.source.DamageSource) cause).buildAndSwitch() : null) {
        // Sponge end
        boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
        this.connection.sendPacket(new SPacketCombatEvent(this.getCombatTracker(), SPacketCombatEvent.Event.ENTITY_DIED, flag));
        if (flag) {
            Team team = this.getTeam();
            if (team != null && team.getDeathMessageVisibility() != Team.EnumVisible.ALWAYS) {
                if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OTHER_TEAMS) {
                    this.mcServer.getPlayerList().sendMessageToAllTeamMembers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
                } else if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OWN_TEAM) {
                    this.mcServer.getPlayerList().sendMessageToTeamOrAllPlayers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
                }
            } else {
                this.mcServer.getPlayerList().sendMessage(this.getCombatTracker().getDeathMessage());
            }
        }
        this.spawnShoulderEntities();
        // Ignore keepInventory GameRule instead use keepInventory from Event
        if (!event.getKeepInventory() && !this.isSpectator()) {
            this.destroyVanishingCursedItems();
            this.inventory.dropAllItems();
        }
        for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.DEATH_COUNT)) {
            Score score = this.getWorldScoreboard().getOrCreateScore(this.getName(), scoreobjective);
            score.incrementScore();
        }
        EntityLivingBase entitylivingbase = this.getAttackingEntity();
        if (entitylivingbase != null) {
            EntityList.EntityEggInfo entitylist$entityegginfo = EntityList.ENTITY_EGGS.get(EntityList.getKey(entitylivingbase));
            if (entitylist$entityegginfo != null) {
                this.addStat(entitylist$entityegginfo.entityKilledByStat);
            }
            entitylivingbase.awardKillScore((EntityPlayerMP) (Object) this, this.scoreValue, cause);
        }
        this.addStat(StatList.DEATHS);
        this.takeStat(StatList.TIME_SINCE_DEATH);
        this.extinguish();
        this.setFlag(0, false);
        this.getCombatTracker().reset();
        this.keepInventory = event.getKeepInventory();
    }
// Sponge - brackets
}
Also used : PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) EntityList(net.minecraft.entity.EntityList) SPacketCombatEvent(net.minecraft.network.play.server.SPacketCombatEvent) Score(net.minecraft.scoreboard.Score) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IInteractionObject(net.minecraft.world.IInteractionObject) IMixinTeam(org.spongepowered.common.interfaces.IMixinTeam) Team(net.minecraft.scoreboard.Team) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with Score

use of net.minecraft.scoreboard.Score in project takumicraft by TNTModders.

the class RenderPlayerSP method renderEntityName.

/**
 * Allows the render to do state modifications necessary before the model is rendered.
 */
/*    @Override
    protected void preRenderCallback(AbstractClientPlayer entitylivingbaseIn, float partialTickTime) {
        float f = 0.9375F;
        GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
    }*/
@Override
protected void renderEntityName(AbstractClientPlayer entityIn, double x, double y, double z, String name, double distanceSq) {
    if (distanceSq < 100.0D) {
        Scoreboard scoreboard = entityIn.getWorldScoreboard();
        ScoreObjective scoreobjective = scoreboard.getObjectiveInDisplaySlot(2);
        if (scoreobjective != null) {
            Score score = scoreboard.getOrCreateScore(entityIn.getName(), scoreobjective);
            this.renderLivingLabel(entityIn, score.getScorePoints() + " " + scoreobjective.getDisplayName(), x, y, z, 64);
            y += (double) ((float) this.getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * 0.025F);
        }
    }
    super.renderEntityName(entityIn, x, y, z, name, distanceSq);
}
Also used : Score(net.minecraft.scoreboard.Score) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) Scoreboard(net.minecraft.scoreboard.Scoreboard)

Example 5 with Score

use of net.minecraft.scoreboard.Score in project ct.js by ChatTriggers.

the class TabList method getNamesByObjectives.

/**
 * Gets names set in scoreboard objectives (useful for newer games)
 *
 * @return The formatted names
 */
public static List<String> getNamesByObjectives() {
    List<String> tabNames = new ArrayList<>();
    try {
        Scoreboard scoreboard = World.getWorld().getScoreboard();
        ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(0);
        Collection<Score> scores = scoreboard.getSortedScores(sidebarObjective);
        for (Score score : scores) {
            ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName());
            String name = ScorePlayerTeam.formatPlayerName(team, score.getPlayerName());
            tabNames.add(name);
        }
    } catch (Exception e) {
        return new ArrayList<>();
    }
    return tabNames;
}
Also used : Score(net.minecraft.scoreboard.Score) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) Scoreboard(net.minecraft.scoreboard.Scoreboard) ArrayList(java.util.ArrayList) ScorePlayerTeam(net.minecraft.scoreboard.ScorePlayerTeam)

Aggregations

Score (net.minecraft.scoreboard.Score)5 ScoreObjective (net.minecraft.scoreboard.ScoreObjective)5 ArrayList (java.util.ArrayList)2 Scoreboard (net.minecraft.scoreboard.Scoreboard)2 IMixinScore (org.spongepowered.common.interfaces.IMixinScore)2 IMixinScoreObjective (org.spongepowered.common.interfaces.IMixinScoreObjective)2 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)2 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)2 List (java.util.List)1 EntityList (net.minecraft.entity.EntityList)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 SPacketCombatEvent (net.minecraft.network.play.server.SPacketCombatEvent)1 SPacketScoreboardObjective (net.minecraft.network.play.server.SPacketScoreboardObjective)1 ScorePlayerTeam (net.minecraft.scoreboard.ScorePlayerTeam)1 Team (net.minecraft.scoreboard.Team)1 IInteractionObject (net.minecraft.world.IInteractionObject)1 DestructEntityEvent (org.spongepowered.api.event.entity.DestructEntityEvent)1 Text (org.spongepowered.api.text.Text)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1