Search in sources :

Example 1 with Score

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

use of net.minecraft.world.scores.Score in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method bridge$addPlayer.

@Override
public void bridge$addPlayer(final ServerPlayer player, final boolean sendPackets) {
    this.impl$players.add(player);
    if (sendPackets) {
        for (final PlayerTeam team : this.getPlayerTeams()) {
            player.connection.send(new ClientboundSetPlayerTeamPacket(team, 0));
        }
        for (final net.minecraft.world.scores.Objective objective : this.getObjectives()) {
            player.connection.send(new ClientboundSetObjectivePacket(objective, 0));
            for (int i = 0; i < 19; ++i) {
                if (this.getDisplayObjective(i) == objective) {
                    player.connection.send(new ClientboundSetDisplayObjectivePacket(i, objective));
                }
            }
            for (final Score score : this.getPlayerScores(objective)) {
                final ClientboundSetScorePacket packetIn = new ClientboundSetScorePacket(Method.CHANGE, score.getObjective().getName(), score.getOwner(), score.getScore());
                player.connection.send(packetIn);
            }
        }
    }
}
Also used : ClientboundSetScorePacket(net.minecraft.network.protocol.game.ClientboundSetScorePacket) Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetPlayerTeamPacket(net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket) ClientboundSetDisplayObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Example 3 with Score

use of net.minecraft.world.scores.Score in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method die.

/**
 * @author blood - May 12th, 2016
 * @author gabizou - June 3rd, 2016
 * @author gabizou - February 22nd, 2020 - Minecraft 1.14.3
 * @reason SpongeForge requires an overwrite so we do it here instead. This handles player death events.
 */
@Overwrite
public void die(final DamageSource cause) {
    // Sponge start - Call Destruct Death Event
    final DestructEntityEvent.Death event = SpongeCommonEventFactory.callDestructEntityEventDeath((net.minecraft.server.level.ServerPlayer) (Object) this, cause, Audiences.server());
    if (event.isCancelled()) {
        return;
    }
    // Sponge end
    final boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES) && !event.isMessageCancelled();
    if (flag) {
        final net.minecraft.network.chat.Component itextcomponent = this.shadow$getCombatTracker().getDeathMessage();
        this.connection.send(new ClientboundPlayerCombatPacket(this.shadow$getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent), (p_212356_2_) -> {
            if (!p_212356_2_.isSuccess()) {
                final int i = 256;
                final String s = itextcomponent.getString(256);
                final net.minecraft.network.chat.Component itextcomponent1 = new TranslatableComponent("death.attack.message_too_long", (new TextComponent(s)).withStyle(ChatFormatting.YELLOW));
                final net.minecraft.network.chat.Component itextcomponent2 = new TranslatableComponent("death.attack.even_more_magic", this.shadow$getDisplayName()).withStyle((p_212357_1_) -> p_212357_1_.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent1)));
                this.connection.send(new ClientboundPlayerCombatPacket(this.shadow$getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent2));
            }
        });
        final Team team = this.shadow$getTeam();
        if (team != null && team.getDeathMessageVisibility() != Team.Visibility.ALWAYS) {
            if (team.getDeathMessageVisibility() == Team.Visibility.HIDE_FOR_OTHER_TEAMS) {
                this.server.getPlayerList().broadcastToTeam((net.minecraft.server.level.ServerPlayer) (Object) this, itextcomponent);
            } else if (team.getDeathMessageVisibility() == Team.Visibility.HIDE_FOR_OWN_TEAM) {
                this.server.getPlayerList().broadcastToAllExceptTeam((net.minecraft.server.level.ServerPlayer) (Object) this, itextcomponent);
            }
        } else {
            final Component message = event.message();
            // Sponge start - use the event audience
            if (message != Component.empty()) {
                event.audience().ifPresent(eventChannel -> eventChannel.sendMessage(Identity.nil(), message));
            }
        // Sponge end
        // this.server.getPlayerList().sendMessage(itextcomponent);
        }
    } else {
        this.connection.send(new ClientboundPlayerCombatPacket(this.shadow$getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED));
    }
    this.shadow$removeEntitiesOnShoulder();
    if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
        this.shadow$tellNeutralMobsThatIDied();
    }
    // Sponge Start - update the keep inventory flag for dropping inventory
    // during the death update ticks
    this.impl$keepInventory = event.keepInventory();
    if (!this.shadow$isSpectator()) {
        this.shadow$dropAllDeathLoot(cause);
    }
    // Sponge End
    this.shadow$getScoreboard().forAllObjectives(ObjectiveCriteria.DEATH_COUNT, this.shadow$getScoreboardName(), Score::increment);
    final LivingEntity livingentity = this.shadow$getKillCredit();
    if (livingentity != null) {
        this.shadow$awardStat(Stats.ENTITY_KILLED_BY.get(livingentity.getType()));
        livingentity.awardKillScore((net.minecraft.server.level.ServerPlayer) (Object) this, this.deathScore, cause);
        this.shadow$createWitherRose(livingentity);
    }
    this.level.broadcastEntityEvent((net.minecraft.server.level.ServerPlayer) (Object) this, (byte) 3);
    this.shadow$awardStat(Stats.DEATHS);
    this.shadow$resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_DEATH));
    this.shadow$resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_REST));
    this.shadow$clearFire();
    this.shadow$setSharedFlag(0, false);
    this.shadow$getCombatTracker().recheckStatus();
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) HoverEvent(net.minecraft.network.chat.HoverEvent) LivingEntity(net.minecraft.world.entity.LivingEntity) Score(net.minecraft.world.scores.Score) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ClientboundPlayerCombatPacket(net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Team(net.minecraft.world.scores.Team) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.kyori.adventure.text.Component) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with Score

use of net.minecraft.world.scores.Score in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method bridge$removeObjective.

@Override
public void bridge$removeObjective(final Objective objective) {
    final net.minecraft.world.scores.Objective scoreObjective = ((SpongeObjective) objective).getObjectiveFor(this);
    ((ScoreboardAccessor) this).accessor$objectivesByName().remove(scoreObjective.getName());
    for (int i = 0; i < 19; ++i) {
        if (this.getDisplayObjective(i) == scoreObjective) {
            this.setDisplayObjective(i, null);
        }
    }
    ((ServerScoreboardBridge) this).bridge$sendToPlayers(new ClientboundSetObjectivePacket(scoreObjective, Constants.Scoreboards.OBJECTIVE_PACKET_REMOVE));
    final List list = ((ScoreboardAccessor) this).accessor$objectivesByCriteria().get(scoreObjective.getCriteria());
    if (list != null) {
        list.remove(scoreObjective);
    }
    for (final Map<net.minecraft.world.scores.Objective, Score> scoreMap : ((ScoreboardAccessor) this).accessor$playerScores().values()) {
        final Score score = scoreMap.remove(scoreObjective);
        if (score != null) {
            ((ScoreBridge) score).bridge$getSpongeScore().removeScoreFor(scoreObjective);
        }
    }
    this.shadow$setDirty();
    ((SpongeObjective) objective).removeObjectiveFor(this);
}
Also used : ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Objective(org.spongepowered.api.scoreboard.objective.Objective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) PlayerList(net.minecraft.server.players.PlayerList) ArrayList(java.util.ArrayList) List(java.util.List) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge)

Aggregations

Score (net.minecraft.world.scores.Score)4 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)3 Component (net.kyori.adventure.text.Component)2 ClientboundSetObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)2 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)1 HoverEvent (net.minecraft.network.chat.HoverEvent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ClientboundPlayerCombatPacket (net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket)1 ClientboundSetDisplayObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket)1 ClientboundSetPlayerTeamPacket (net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket)1 ClientboundSetScorePacket (net.minecraft.network.protocol.game.ClientboundSetScorePacket)1 PlayerList (net.minecraft.server.players.PlayerList)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 PlayerTeam (net.minecraft.world.scores.PlayerTeam)1 Team (net.minecraft.world.scores.Team)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1