use of net.minecraft.scoreboard.ScoreboardCriterion 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);
}
Aggregations