Search in sources :

Example 1 with ScoreboardPlayerScore

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

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

the class ScoreboardMixin method onCreate.

@Inject(method = "createChangePackets", at = @At(value = "RETURN"))
private void onCreate(ScoreboardObjective objective, CallbackInfoReturnable<List<Packet<?>>> cir) {
    if (ScoreboardExtension.isExtensionEnabled) {
        int i = 0;
        for (ScoreboardPlayerScore score : getAllPlayerScores(objective)) {
            i += score.getScore();
        }
        cir.getReturnValue().add(new ScoreboardPlayerUpdateS2CPacket(ServerScoreboard.UpdateMode.CHANGE, objective.getName(), Formatting.BOLD + "TOTAL", i));
    }
}
Also used : ScoreboardPlayerScore(net.minecraft.scoreboard.ScoreboardPlayerScore) ScoreboardPlayerUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ScoreboardPlayerUpdateS2CPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ScoreboardPlayerScore

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

the class ScoreboardExtension method initScoreboard.

public void initScoreboard(ServerCommandSource source, ScoreboardObjective scoreboardObjective, Item item, String type) {
    Scoreboard scoreboard = source.getServer().getScoreboard();
    MinecraftServer server = source.getServer();
    File file = new File(((ServerWorldProperties) server.getOverworld().getLevelProperties()).getLevelName(), "stats");
    File[] stats = file.listFiles();
    assert stats != null;
    for (File stat : stats) {
        String fileName = stat.getName();
        String uuidString = fileName.substring(0, fileName.lastIndexOf(".json"));
        UUID uuid = UUID.fromString(uuidString);
        ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
        Stat<?> finalStat = null;
        if (type.equalsIgnoreCase("broken")) {
            finalStat = Stats.BROKEN.getOrCreateStat(item);
        } else if (type.equalsIgnoreCase("crafted")) {
            finalStat = Stats.CRAFTED.getOrCreateStat(item);
        } else if (type.equalsIgnoreCase("mined")) {
            finalStat = Stats.MINED.getOrCreateStat(Block.getBlockFromItem(item));
        } else if (type.equalsIgnoreCase("used")) {
            finalStat = Stats.USED.getOrCreateStat(item);
        } else if (type.equalsIgnoreCase("picked_up")) {
            finalStat = Stats.PICKED_UP.getOrCreateStat(item);
        } else if (type.equalsIgnoreCase("dropped")) {
            finalStat = Stats.DROPPED.getOrCreateStat(item);
        }
        int value;
        String playerName;
        if (player != null) {
            value = player.getStatHandler().getStat(finalStat);
            playerName = player.getEntityName();
        } else {
            ServerStatHandler serverStatHandler = new ServerStatHandler(server, stat);
            value = serverStatHandler.getStat(finalStat);
            Optional<GameProfile> gameProfile = server.getUserCache().getByUuid(uuid);
            if (gameProfile.isEmpty()) {
                continue;
            }
            playerName = gameProfile.get().getName();
        }
        if (value == 0) {
            continue;
        }
        ScoreboardPlayerScore scoreboardPlayerScore = scoreboard.getPlayerScore(playerName, scoreboardObjective);
        scoreboardPlayerScore.setScore(value);
    }
}
Also used : ScoreboardPlayerScore(net.minecraft.scoreboard.ScoreboardPlayerScore) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) Scoreboard(net.minecraft.scoreboard.Scoreboard) GameProfile(com.mojang.authlib.GameProfile) ServerStatHandler(net.minecraft.stat.ServerStatHandler) UUID(java.util.UUID) File(java.io.File)

Example 4 with ScoreboardPlayerScore

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

ScoreboardPlayerScore (net.minecraft.scoreboard.ScoreboardPlayerScore)4 ScoreboardPlayerUpdateS2CPacket (net.minecraft.network.packet.s2c.play.ScoreboardPlayerUpdateS2CPacket)2 Scoreboard (net.minecraft.scoreboard.Scoreboard)2 ScoreboardObjective (net.minecraft.scoreboard.ScoreboardObjective)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 GameProfile (com.mojang.authlib.GameProfile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Team (net.minecraft.scoreboard.Team)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ServerStatHandler (net.minecraft.stat.ServerStatHandler)1