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;
}
}
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));
}
}
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);
}
}
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));
}
}
Aggregations