Search in sources :

Example 36 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project EliteMobs by MagmaGuy.

the class SimpleScoreboard method temporaryScoreboard.

public static Scoreboard temporaryScoreboard(Player player, String displayName, List<String> scoreboardContents, int ticksTimeout) {
    Scoreboard scoreboard = lazyScoreboard(player, displayName, scoreboardContents);
    new BukkitRunnable() {

        @Override
        public void run() {
            if (player.getScoreboard().equals(scoreboard))
                player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
        }
    }.runTaskLater(MetadataHandler.PLUGIN, ticksTimeout);
    return scoreboard;
}
Also used : Scoreboard(org.bukkit.scoreboard.Scoreboard) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 37 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project EliteMobs by MagmaGuy.

the class SimpleScoreboard method lazyScoreboard.

public static Scoreboard lazyScoreboard(Player player, String displayName, List<String> scoreboardContents) {
    Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    int lineCount = Math.min(scoreboardContents.size(), 15);
    Objective objective = scoreboard.registerNewObjective("test", "dummy", displayName);
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    for (int i = 0; i < lineCount; i++) {
        String scoreString = scoreboardContents.get(i);
        if (scoreString.length() > 40)
            scoreString = scoreString.substring(0, 39);
        Score score = objective.getScore(scoreString);
        score.setScore(i);
    }
    player.setScoreboard(scoreboard);
    return scoreboard;
}
Also used : Objective(org.bukkit.scoreboard.Objective) Score(org.bukkit.scoreboard.Score) Scoreboard(org.bukkit.scoreboard.Scoreboard)

Example 38 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard 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)

Example 39 with Scoreboard

use of org.bukkit.scoreboard.Scoreboard in project MyMaid2 by jaoafa.

the class Event_CommandBlockVariable method onCommandBlockCall.

@EventHandler
public void onCommandBlockCall(ServerCommandEvent event) {
    if (!(event.getSender() instanceof BlockCommandSender))
        return;
    BlockCommandSender sender = (BlockCommandSender) event.getSender();
    if (sender.getBlock() == null || !(sender.getBlock().getState() instanceof CommandBlock))
        return;
    CommandBlock cmdb = (CommandBlock) sender.getBlock().getState();
    String command = cmdb.getCommand();
    // 最初に$が入ってたら変数入りコマンド
    if (!command.startsWith("$"))
        return;
    // $を消す
    command = StringUtils.stripStart(command, "$");
    // /を消す
    command = StringUtils.stripStart(command, "/");
    // 「@p」のみ置き換える動作をする
    if (sender instanceof Player) {
        Player player = (Player) sender;
        NearestPlayer npr = new NearestPlayer(player.getLocation());
        if (npr.getStatus()) {
            command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
        }
    } else if (sender instanceof BlockCommandSender) {
        NearestPlayer npr = new NearestPlayer(cmdb.getBlock().getLocation());
        if (npr.getStatus()) {
            command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
        }
    }
    // ----- 事前定義(予約済み変数) ----- //
    SimpleDateFormat sdf_Year = new SimpleDateFormat("yyyy");
    command = command.replaceAll("\\$" + "DateTime_Year" + "\\$", sdf_Year.format(new Date()));
    SimpleDateFormat sdf_Month = new SimpleDateFormat("MM");
    command = command.replaceAll("\\$" + "DateTime_Month" + "\\$", sdf_Month.format(new Date()));
    SimpleDateFormat sdf_Day = new SimpleDateFormat("dd");
    command = command.replaceAll("\\$" + "DateTime_Day" + "\\$", sdf_Day.format(new Date()));
    SimpleDateFormat sdf_Hour = new SimpleDateFormat("HH");
    command = command.replaceAll("\\$" + "DateTime_Hour" + "\\$", sdf_Hour.format(new Date()));
    SimpleDateFormat sdf_Minute = new SimpleDateFormat("mm");
    command = command.replaceAll("\\$" + "DateTime_Minute" + "\\$", sdf_Minute.format(new Date()));
    SimpleDateFormat sdf_Second = new SimpleDateFormat("ss");
    command = command.replaceAll("\\$" + "DateTime_Second" + "\\$", sdf_Second.format(new Date()));
    command = command.replaceAll("\\$" + "PlayerCount" + "\\$", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
    for (Player p : Bukkit.getOnlinePlayers()) {
        if (!command.contains("$" + "Damager_" + p.getName() + "$")) {
            continue;
        }
        EntityDamageEvent ede = p.getLastDamageCause();
        if (ede == null) {
            continue;
        }
        Entity e = ede.getEntity();
        if (e == null) {
            continue;
        }
        String name = e.getName();
        command = command.replaceAll("\\$" + "Damager_" + p.getName() + "\\$", name);
    }
    ScoreboardManager sbm = Bukkit.getScoreboardManager();
    Scoreboard sb = sbm.getMainScoreboard();
    for (Objective obj : sb.getObjectives()) {
        String regex = "\\$Score_" + obj.getName() + "_(.+?)\\$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(command);
        while (m.find()) {
            Score i = obj.getScore(m.group(1));
            if (i == null) {
                continue;
            }
            command = command.replaceAll("\\$" + "Score_" + obj.getName() + "_" + m.group(1) + "\\$", "" + i.getScore());
        }
    }
    // ----- 事前定義(予約済み変数) ----- //
    Map<String, String> map = MyMaidVariable.listALL();
    for (Map.Entry<String, String> e : map.entrySet()) {
        command = command.replaceAll("\\$" + e.getKey() + "\\$", e.getValue());
    }
    Bukkit.dispatchCommand(sender, command);
}
Also used : Entity(org.bukkit.entity.Entity) Pattern(java.util.regex.Pattern) Player(org.bukkit.entity.Player) NearestPlayer(com.jaoafa.MyMaid2.Lib.NearestPlayer) NearestPlayer(com.jaoafa.MyMaid2.Lib.NearestPlayer) Matcher(java.util.regex.Matcher) CommandBlock(org.bukkit.block.CommandBlock) Date(java.util.Date) Objective(org.bukkit.scoreboard.Objective) Score(org.bukkit.scoreboard.Score) Scoreboard(org.bukkit.scoreboard.Scoreboard) ScoreboardManager(org.bukkit.scoreboard.ScoreboardManager) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) BlockCommandSender(org.bukkit.command.BlockCommandSender) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Scoreboard (org.bukkit.scoreboard.Scoreboard)39 Team (org.bukkit.scoreboard.Team)24 GameProfile (com.mojang.authlib.GameProfile)11 UUID (java.util.UUID)11 Objective (org.bukkit.scoreboard.Objective)11 Property (com.mojang.authlib.properties.Property)7 BigInteger (java.math.BigInteger)7 MessageDigest (java.security.MessageDigest)7 Player (org.bukkit.entity.Player)7 PlayerProfile (net.aufdemrand.denizen.nms.util.PlayerProfile)4 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)3 File (java.io.File)3 Skin (net.citizensnpcs.npc.skin.Skin)3 User (net.dzikoysk.funnyguilds.basic.User)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 EntityType (org.bukkit.entity.EntityType)3 PotionEffectType (org.bukkit.potion.PotionEffectType)3 PotionType (org.bukkit.potion.PotionType)3 Score (org.bukkit.scoreboard.Score)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2