use of org.bukkit.scoreboard.Objective in project Glowstone by GlowstoneMC.
the class GlowScoreboard method registerNewObjective.
@Override
public Objective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
Objective objective = registerNewObjective(name, criteria);
objective.setDisplayName(displayName);
return objective;
}
use of org.bukkit.scoreboard.Objective in project InfernalMobs by NyaaCat.
the class GUI method updateMobScoreboard.
private static void updateMobScoreboard(Mob mob, LivingEntity mobEntity) {
Scoreboard sb = mobScoreboard.get(mob.entityId);
if (sb == null) {
// init scoreboard
sb = Bukkit.getScoreboardManager().getNewScoreboard();
mobScoreboard.put(mob.entityId, sb);
Objective obj = sb.registerNewObjective(OBJECTIVE_NAME_INFO, "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(mobEntity.getType().name());
// this is the actual "score"
int index = 1;
for (EnumAbilities ab : mob.abilityList) {
obj.getScore(ab.name().toLowerCase()).setScore(index++);
}
obj.getScore(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Abilities:").setScore(index++);
double maxHealth = mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = mobEntity.getHealth();
obj.getScore(String.format("Health: %.0f/%.0f", health, maxHealth)).setScore(index);
} else {
// update scoreboard
Objective obj = sb.getObjective(OBJECTIVE_NAME_INFO);
int index = -1;
for (String str : sb.getEntries()) {
if (str.startsWith("Health:")) {
index = obj.getScore(str).getScore();
sb.resetScores(str);
}
}
double maxHealth = mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = mobEntity.getHealth();
obj.getScore(String.format("Health: %.0f/%.0f", health, maxHealth)).setScore(index);
}
}
Aggregations