Search in sources :

Example 1 with ScoreboardObjective

use of net.minecraft.scoreboard.ScoreboardObjective in project Skyblocker by LifeIsAParadox.

the class Utils method getSidebar.

public static List<String> getSidebar() {
    try {
        assert MinecraftClient.getInstance().player != null;
        Scoreboard scoreboard = MinecraftClient.getInstance().player.getScoreboard();
        ScoreboardObjective objective = scoreboard.getObjectiveForSlot(1);
        List<String> lines = new ArrayList<>();
        for (ScoreboardPlayerScore score : scoreboard.getAllPlayerScores(objective)) {
            Team team = scoreboard.getPlayerTeam(score.getPlayerName());
            if (team != null) {
                String line = team.getPrefix().getString() + team.getSuffix().getString();
                if (line.trim().length() > 0) {
                    String formatted = Formatting.strip(line);
                    lines.add(formatted);
                }
            }
        }
        if (objective != null) {
            lines.add(objective.getDisplayName().getString());
            Collections.reverse(lines);
        }
        return lines;
    } catch (NullPointerException e) {
        return null;
    }
}
Also used : Scoreboard(net.minecraft.scoreboard.Scoreboard) ScoreboardPlayerScore(net.minecraft.scoreboard.ScoreboardPlayerScore) ArrayList(java.util.ArrayList) ScoreboardObjective(net.minecraft.scoreboard.ScoreboardObjective) Team(net.minecraft.scoreboard.Team)

Example 2 with ScoreboardObjective

use of net.minecraft.scoreboard.ScoreboardObjective in project KahzerxMod by otakucraft.

the class ScoreboardExtension method showSideBar.

public void showSideBar(ServerCommandSource source, ItemStackArgument item, String type, boolean persistent) {
    Scoreboard scoreboard = source.getServer().getScoreboard();
    Item minecraftItem = item.getItem();
    String objectiveName = type + "." + Item.getRawId(minecraftItem);
    ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(objectiveName);
    Entity entity = source.getEntity();
    Text text;
    if (scoreboardObjective != null) {
        if (scoreboard.getObjectiveForSlot(1) == scoreboardObjective) {
            text = MarkEnum.CROSS.appendMessage("Already showing");
        } else {
            assert entity != null;
            scoreboard.setObjectiveSlot(1, scoreboardObjective);
            if (persistent) {
                tickSet = -100;
            } else {
                tickSet = source.getServer().getTicks() + (20 * 20);
            }
            text = MarkEnum.TICK.appendText(new LiteralText(Formatting.WHITE + entity.getEntityName() + " has selected " + Formatting.GOLD + "[" + scoreboardObjective.getDisplayName().asString() + "]"));
        }
    } else {
        String criteriaName = "minecraft." + type + ":minecraft." + item.getItem().toString();
        String capitalize = type.substring(0, 1).toUpperCase() + type.substring(1);
        String displayName = capitalize + " " + minecraftItem.toString().replaceAll("_", " ");
        Optional<ScoreboardCriterion> opCriteria = ScoreboardCriterion.getOrCreateStatCriterion(criteriaName);
        if (opCriteria.isEmpty()) {
            return;
        }
        ScoreboardCriterion criteria = opCriteria.get();
        scoreboard.addObjective(objectiveName, criteria, new LiteralText(displayName).formatted(Formatting.GOLD), criteria.getDefaultRenderType());
        ScoreboardObjective newScoreboardObjective = scoreboardObjective = scoreboard.getNullableObjective(objectiveName);
        try {
            initScoreboard(source, newScoreboardObjective, minecraftItem, type);
        } catch (Exception e) {
            scoreboard.removeObjective(newScoreboardObjective);
            text = MarkEnum.CROSS.appendMessage("Error.");
            assert entity != null;
            source.getServer().getPlayerManager().broadcast(text, MessageType.CHAT, Util.NIL_UUID);
            return;
        }
        scoreboard.setObjectiveSlot(1, newScoreboardObjective);
        if (persistent) {
            tickSet = -100;
        } else {
            tickSet = source.getServer().getTicks() + (20 * 20);
        }
        assert entity != null;
        assert scoreboardObjective != null;
        text = MarkEnum.TICK.appendText(new LiteralText(Formatting.WHITE + entity.getEntityName() + " has selected " + Formatting.GOLD + "[" + scoreboardObjective.getDisplayName().asString() + "]"));
    }
    assert entity != null;
    source.getServer().getPlayerManager().broadcast(text, MessageType.CHAT, Util.NIL_UUID);
}
Also used : Item(net.minecraft.item.Item) Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Scoreboard(net.minecraft.scoreboard.Scoreboard) ScoreboardObjective(net.minecraft.scoreboard.ScoreboardObjective) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) ScoreboardCriterion(net.minecraft.scoreboard.ScoreboardCriterion) LiteralText(net.minecraft.text.LiteralText)

Example 3 with ScoreboardObjective

use of net.minecraft.scoreboard.ScoreboardObjective in project KahzerxMod by otakucraft.

the class ScoreboardMixin method onUpdate.

@Inject(method = "updateScore", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAll(Lnet/minecraft/network/Packet;)V"))
private void onUpdate(ScoreboardPlayerScore score, CallbackInfo ci) {
    if (ScoreboardExtension.isExtensionEnabled) {
        ScoreboardObjective objective = score.getObjective();
        if (objective == null) {
            return;
        }
        int i = 0;
        for (ScoreboardPlayerScore sc : getAllPlayerScores(objective)) {
            i += sc.getScore();
        }
        server.getPlayerManager().sendToAll(new ScoreboardPlayerUpdateS2CPacket(ServerScoreboard.UpdateMode.CHANGE, objective.getName(), Formatting.BOLD + "TOTAL", i));
    }
}
Also used : ScoreboardPlayerScore(net.minecraft.scoreboard.ScoreboardPlayerScore) ScoreboardObjective(net.minecraft.scoreboard.ScoreboardObjective) ScoreboardPlayerUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ScoreboardPlayerUpdateS2CPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ScoreboardObjective (net.minecraft.scoreboard.ScoreboardObjective)3 Scoreboard (net.minecraft.scoreboard.Scoreboard)2 ScoreboardPlayerScore (net.minecraft.scoreboard.ScoreboardPlayerScore)2 ArrayList (java.util.ArrayList)1 Entity (net.minecraft.entity.Entity)1 Item (net.minecraft.item.Item)1 ScoreboardPlayerUpdateS2CPacket (net.minecraft.network.packet.s2c.play.ScoreboardPlayerUpdateS2CPacket)1 ScoreboardCriterion (net.minecraft.scoreboard.ScoreboardCriterion)1 Team (net.minecraft.scoreboard.Team)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 LiteralText (net.minecraft.text.LiteralText)1 Text (net.minecraft.text.Text)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1