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