/** * Set a boss bar with a given color, style, percentage to a given * player. Also you can enable the darken sky, the boss music ambiance * and enable fog to a given player * * @param message Message on the top of the bar * @param color Color of the bar * @param style Style of the bar * @param progress Filling percentage * @param darkenSky Enable darken sky * @param playMusic Enable boss music * @param createFog Enable the fog */ public static Pair<UUID, BossBar> getBar(String message, BarColor color, BarStyle style, double progress, boolean darkenSky, boolean playMusic, boolean createFog) { BossBar bossBar = Bukkit.createBossBar(message, color, style); bossBar.setProgress(progress < 0 ? 0D : progress / 100.0D); if (darkenSky) bossBar.addFlag(BarFlag.DARKEN_SKY); if (playMusic) bossBar.addFlag(BarFlag.PLAY_BOSS_MUSIC); if (createFog) bossBar.addFlag(BarFlag.CREATE_FOG); UUID random = UUID.randomUUID(); bossBars.put(random, bossBar); return Pair.of(random, bossBar); }
@Handler(priority = Priority.LAST) public void gameOver(GameStopEvent event) { // There might be issues with this event. GameStopEvent is called AFTER // a new game actually starts and calls GameStartEvent. The Minecraft // client might have limit of displayed boss bars and boss bars rendered // in a new game (which would be called in GameStartEvent) might not be // displayed. // NOTE: We won't use ServerCycleEvent since this event is not // representing the stopping game. for (BossBar bossBar : this.bossBars.values()) { // We need need to send the "REMOVE" packet to all members // of this boss bar to remove it from their views. bossBar.removeAll(); } this.bossBars.clear(); }
/** * Remove a boss bar from a given player * * @param player Player */ public static void removeBar(Player player) { Map<UUID, BossBar> list = new HashMap<>(bossBars); list.forEach((uuid, bossBar) -> { bossBar.removePlayer(player); if (bossBar.getPlayers().isEmpty()) bossBars.remove(uuid); }); }
@EventHandler(priority = EventPriority.HIGHEST) public void join(final PlayerJoinEvent event) { Player player = event.getPlayer(); resetPlayer(player); event.getPlayer().addAttachment(lobby, Permissions.OBSERVER, true); if (player.hasPermission("lobby.overhead-news")) { final String datacenter = minecraftService.getLocalServer().datacenter(); final Component news = new Component(ChatColor.GREEN) .extra(new TranslatableComponent( "lobby.news", new Component(ChatColor.GOLD, ChatColor.BOLD).extra(generalFormatter.publicHostname()) )); final BossBar bar = bossBarFactory.createBossBar(renderer.render(news, player), BarColor.BLUE, BarStyle.SOLID); bar.setProgress(1); bar.addPlayer(player); bar.show(); } if(!player.hasPermission("lobby.disabled-permissions-exempt")) { for(PermissionAttachmentInfo attachment : player.getEffectivePermissions()) { if(config.getDisabledPermissions().contains(attachment.getPermission())) { attachment.getAttachment().setPermission(attachment.getPermission(), false); } } } int count = lobby.getServer().getOnlinePlayers().size(); if(!lobby.getServer().getOnlinePlayers().contains(event.getPlayer())) count++; minecraftService.updateLocalServer(new SignUpdate(count)); }
@Override public void addPlayer(Player player) { if(!views.containsKey(player)) { final BossBar view = bossBarFactory.createBossBar(renderer.render(title, player), color, style, flags.toArray(new BarFlag[flags.size()])); view.setVisible(visibile); view.addPlayer(player); views.put(player, view); } }
@HandleModel public void ticketUpdated(@Nullable Ticket before, @Nullable Ticket after, Ticket latest) { final Arena arena = arenas.byId(latest.arena_id()); updateArena(arena); final Player player = userStore.find(latest.user()); if(player != null) { final BossBar bar = bars.getUnchecked(arena); if(after != null && after.server_id() == null) { bar.addPlayer(player); } else { bar.removePlayer(player); } } }
public void updateBossBar() { BossBar b = Bukkit.createBossBar("error", BarColor.GREEN, BarStyle.SOLID); b.addPlayer(getPlayer()); int begin = getJobExp().getXPLVL().begin; int current = getJobExp().getEXP(); int end = getJobExp().getXPLVL().end; b.setTitle(getJob().getDisplayname() + ChatColor.DARK_GRAY + " - " + Job.getColor() + current + ChatColor.DARK_GRAY + "/" + Job.getColor() + end); b.setProgress(100 / (end - begin) * (current - begin)); }
@EventHandler(priority = EventPriority.HIGH) public void onCountdownCycleComplete(CycleCompleteEvent event) { for (Player player : Bukkit.getOnlinePlayers()) { if (getBossBar(player) == null) { BossBar bossBar = createBossBar(player); bossBar.addPlayer(player); bossBars.add(bossBar); if (time <= 0) { bossBar.setVisible(false); } } } }
@EventHandler public void onCountdownJoin(PlayerJoinEvent event) { BossBar bossBar = createBossBar(event.getPlayer()); this.bossBars.add(bossBar); bossBar.addPlayer(event.getPlayer()); if (time <= 0) { bossBar.setVisible(false); } }
@Override public void disable() { for (BossBar bossBar : this.bossBars) { bossBar.removeAll(); } HandlerList.unregisterAll(this); }
private boolean endCountdown() { if (canEnd()) { if (destroyOnEnd) { canRun = false; for (BossBar bossBar : this.bossBars) { bossBar.setVisible(false); } } onCountdownEnd(); return true; } return false; }
public BossBar getBossBar(Player player) { for (BossBar bossBar : this.bossBars) { if (bossBar.getPlayers().contains(player)) { return bossBar; } } return null; }
@Override protected @Nonnull ScheduledResultTask<Void> newTask(Collection<Player> players) { BossBar bar = supplier.get(); for (Player player : players) { bar.addPlayer(player); } return new ScheduledTask(bar, consumer.get(), translation, iterations); }
@Override protected @Nonnull ScheduledResultTask<Void> newTask(Collection<Player> players) { List<BossBar> bars = players.stream().map(player -> { BossBar bar = supplier.get(); bar.addPlayer(player); return bar; }).collect(toList()); return new ScheduledTask(bars, consumer.get(), translation, iterations); }
public BossBar renderBossBar(Point point, Color pointColor, double progress, Color progressColor) { BossBar bossBar = this.bossBars.get(point); if (bossBar == null) { this.bossBars.put(point, bossBar = this.createBossBar()); } bossBar.setColor(this.getBarColor(pointColor)); bossBar.setProgress(progress); bossBar.setTitle(this.getBarTitle(point.getName(), pointColor, progress, progressColor)); bossBar.setVisible(true); return bossBar; }
public BossBar renderBossBar(Point point, Color pointColor, double progress, Color progressColor, Player bukkit) { if (bukkit != null) { BossBar bossBar = this.renderBossBar(point, pointColor, progress, progressColor); if (bossBar != null) { bossBar.addPlayer(bukkit); } return bossBar; } return null; }
public void removeBossBar(Point point, Player bukkit) { BossBar bossBar = this.bossBars.get(point); if (bossBar != null) { try { bossBar.removePlayer(bukkit); } catch (NullPointerException ignored) { // Strange Bukkit bug in CraftBossBar.removePlayer(CraftBossBar.java:190) } } }
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, ParseResult parser) { bar = (Expression<BossBar>) e[0]; if (parser.mark == 2) {toggle = false;} return true; }
@Override @Nullable protected BossBar[] get(Event e) { BossBar bar = Bukkit.createBossBar(Skellett.cc("&a&lSkellett bossbar"), BarColor.GREEN, BarStyle.SOLID, new BarFlag[0]); if (flag != null) { bar = Bukkit.createBossBar(Skellett.cc("&a&lSkellett bossbar"), BarColor.GREEN, BarStyle.SOLID, flag.getSingle(e)); } return new BossBar[]{bar}; }
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) { flag = (Expression<BarFlag>) e[0]; bar = (Expression<BossBar>) e[1]; return true; }
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) e[0]; bar = (Expression<BossBar>) e[1]; return true; }
@SuppressWarnings("unchecked") public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, ParseResult parser) { bar = (Expression<BossBar>) e[0]; flag = (Expression<BarFlag>) e[1]; if (parser.mark == 2) {boo = false;} return true; }
private static void removeBar(final BossBar bar, final Player p){ final int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(RedProtect.get(), () -> { double d = bar.getProgress(); if (d >= 0.2){ bar.setProgress(d - 0.2); } }, 20, 20); Bukkit.getScheduler().runTaskLater(RedProtect.get(), () -> { bar.removePlayer(p); Bukkit.getScheduler().cancelTask(task); }, 120); }
@Override public void removeBar(Player player, SkillType skill) { EnumMap<SkillType, BossBar> skillBars = bossBars.get(player.getUniqueId()); if (skillBars != null) { BossBar bar = skillBars.get(skill); if (bar != null) { bar.setVisible(false); } } }
@Override public void removeAllBars(Player player) { EnumMap<SkillType, BossBar> skillBars = bossBars.remove(player.getUniqueId()); if (skillBars != null) { skillBars.values().forEach(bar -> bar.setVisible(false)); } }
@Override public void setMessage(Player player, SkillType skill, String newMessage, float percent) { UUID uniqueId = player.getUniqueId(); EnumMap<SkillType, BossBar> skillBars = bossBars .computeIfAbsent(uniqueId, k -> Maps.newEnumMap(SkillType.class)); BossBar bar = skillBars.computeIfAbsent(skill, skillType -> { BarStyle style = specificStyle.get(skillType); BarColor color = specificColor.get(skillType); if (style == null || color == null) { return null; } BossBar tempBar = Bukkit.createBossBar(newMessage, color, style); tempBar.addPlayer(player); return tempBar; }); bar.setTitle(newMessage); bar.setVisible(true); bar.setProgress(percent / 100); oldBars.remove(bar); oldBars.addLast(bar); if (oldBars.size() > concurrentBars) { oldBars.removeFirst().setVisible(false); } }
/** * Creates a boss bar if doesn't exist * * @param player the player * @return the boss bar */ private BossBar createIfNotExists(Player player) { if(bossBars.containsKey(player.getUniqueId())) { return getBossBar(player); } BossBar bossBar = Bukkit.getServer().createBossBar("", Config.BOSSBAR_RAIDBAR_COLOR.toEnum(BarColor.class), Config.BOSSBAR_RAIDBAR_STYLE.toEnum(BarStyle.class)); bossBar.addPlayer(player); bossBars.put(player.getUniqueId(), bossBar); return bossBar; }
/** * Saves a bossbar in the BossBarManager for future use. * * @param id The ID text for the bossbar, duplicate ID's will be over written. * @param bossbar The bossbar object to be stored. */ public void createBossBar(String id, BossBar bossbar) { if (barMap.containsKey(id)) { barMap.get(id).removeAll(); barMap.remove(id); } barMap.put(id, bossbar); }
/** * Add a flag to a bossbar in the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param flag The BarFlag to be added. */ public void addFlag(String id, BarFlag flag) { BossBar bar = barMap.get(id); if (bar != null) { bar.addFlag(flag); barMap.put(id, bar); } }
/** * Remove a flag from a bossbar in the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param flag The BarFlag to be added. */ public void removeFlag(String id, BarFlag flag) { BossBar bar = barMap.get(id); if (bar != null) { bar.removeFlag(flag); barMap.put(id, bar); } }
/** * Add an array of players to a bossbar in the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param players Array of players to be added to the bossbar */ public void addPlayers(String id, Player[] players) { BossBar bar = barMap.get(id); if (bar != null) { for (Player p : players) { bar.addPlayer(p); } barMap.put(id, bar); } }
/** * Remove an array of players from a bossbar in the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param players Array of players to be removed from the bossbar */ public void removePlayers(String id, Player[] players) { BossBar bar = barMap.get(id); if (bar != null) { for (Player p : players) { bar.removePlayer(p); } barMap.put(id, bar); } }
/** * Remove a bossbar from the BossBarManager and remove it from all players who were assigned it. * * @param id The ID text for the bossbar. */ public void removeBar(String id) { BossBar bar = barMap.get(id); if (bar != null) { bar.removeAll(); barMap.remove(id); } }
/** * Changed the title of a bossbar from the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param title The new title for the bossbar with color codes. */ public void changeTitle(String id, String title) { BossBar bar = barMap.get(id); if (bar != null) { bar.setTitle(title); barMap.put(id, bar); } }
/** * Changed the progress or fill of a bossbar from the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param progress The progress or fill to be set from 0 - 100. */ public void changeValue(String id, double progress) { BossBar bar = barMap.get(id); if (bar != null) { if (progress > 100) { progress = 100; } else if (progress < 0) { progress = 0; } bar.setProgress(progress / 100); barMap.put(id, bar); } }
/** * Changed the color of a bossbar from the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param color The BarColor to be used. */ public void changeColor(String id, BarColor color) { BossBar bar = barMap.get(id); if (bar != null) { bar.setColor(color); barMap.put(id, bar); } }
/** * Changed the style of a bossbar from the BossBarManager through the stored ID. * * @param id The ID text for the bossbar. * @param style The BarStyle to be used. */ public void changeStyle(String id, BarStyle style) { BossBar bar = barMap.get(id); if (bar != null) { bar.setStyle(style); barMap.put(id, bar); } }
/** * Hide a bossbar from the BossBarManager through the stored ID for all players * who were assigned it. * * @param id The ID text for the bossbar. */ public void hideBar(String id) { BossBar bar = barMap.get(id); if (bar != null) { bar.setVisible(false); barMap.put(id, bar); } }