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