Search in sources :

Example 26 with Objective

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;
}
Also used : Objective(org.bukkit.scoreboard.Objective)

Example 27 with 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);
    }
}
Also used : Objective(org.bukkit.scoreboard.Objective) Scoreboard(org.bukkit.scoreboard.Scoreboard) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)

Aggregations

Objective (org.bukkit.scoreboard.Objective)27 Scoreboard (org.bukkit.scoreboard.Scoreboard)10 Team (org.bukkit.scoreboard.Team)8 Player (org.bukkit.entity.Player)6 Score (org.bukkit.scoreboard.Score)4 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)2 List (java.util.List)2 Denizen (com.denizenscript.denizen.Denizen)1 BukkitScriptEvent (com.denizenscript.denizen.events.BukkitScriptEvent)1 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)1 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)1 com.denizenscript.denizen.objects (com.denizenscript.denizen.objects)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 BossBarCommand (com.denizenscript.denizen.scripts.commands.server.BossBarCommand)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 CommandScriptHelper (com.denizenscript.denizen.scripts.containers.core.CommandScriptHelper)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 ScoreboardHelper (com.denizenscript.denizen.utilities.ScoreboardHelper)1 Settings (com.denizenscript.denizen.utilities.Settings)1