org.bukkit.boss.BarStyle Java Examples

The following examples show how to use org.bukkit.boss.BarStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimedPhase.java    From VoxelGamesLibv2 with MIT License 7 votes vote down vote up
@Override
public void enable() {
    super.enable();

    originalTicks = ticks;

    log.finer("enable timed phase with name " + getName());
    bossBar = Bukkit.createBossBar(getName(), BarColor.BLUE, BarStyle.SEGMENTED_20);

    getGame().getPlayers().forEach(u -> bossBar.addPlayer(u.getPlayer()));
    getGame().getSpectators().forEach(u -> bossBar.addPlayer(u.getPlayer()));

    started = true;
}
 
Example #2
Source File: TicketDisplay.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void updateArena(Arena arena) {
    final Game game = games.byId(arena.game_id());
    int minPlayers = 0;
    if(arena.next_server_id() != null) {
        minPlayers = servers.byId(arena.next_server_id()).min_players();
    }
    final BaseComponent text;
    final double progress;
    if(minPlayers > 0 && arena.num_queued() < minPlayers) {
        text = gameFormatter.queued(game, minPlayers - arena.num_queued());
        progress = (double) arena.num_queued() / (double) minPlayers;
    } else {
        text = gameFormatter.joining(game);
        progress = 1;
    }
    bars.getUnchecked(arena).update(text, progress, BarColor.YELLOW, BarStyle.SOLID, Collections.emptySet());
}
 
Example #3
Source File: BukkitBossBarFactory.java    From helper with MIT License 6 votes vote down vote up
private static BarStyle convertStyle(BossBarStyle style) {
    switch (style) {
        case SOLID:
            return BarStyle.SOLID;
        case SEGMENTED_6:
            return BarStyle.SEGMENTED_6;
        case SEGMENTED_10:
            return BarStyle.SEGMENTED_10;
        case SEGMENTED_12:
            return BarStyle.SEGMENTED_12;
        case SEGMENTED_20:
            return BarStyle.SEGMENTED_20;
        default:
            return convertStyle(BossBarStyle.defaultStyle());
    }
}
 
Example #4
Source File: BukkitBossBarFactory.java    From helper with MIT License 6 votes vote down vote up
private static BossBarStyle convertStyle(BarStyle style) {
    switch (style) {
        case SOLID:
            return BossBarStyle.SOLID;
        case SEGMENTED_6:
            return BossBarStyle.SEGMENTED_6;
        case SEGMENTED_10:
            return BossBarStyle.SEGMENTED_10;
        case SEGMENTED_12:
            return BossBarStyle.SEGMENTED_12;
        case SEGMENTED_20:
            return BossBarStyle.SEGMENTED_20;
        default:
            return BossBarStyle.defaultStyle();
    }
}
 
Example #5
Source File: CraftBossBar.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public CraftBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
    this.flags = flags.length > 0 ? EnumSet.of(flags[0], flags) : EnumSet.noneOf(BarFlag.class);
    this.color = color;
    this.style = style;

    handle = new BossInfoServer(
            CraftChatMessage.fromString(title, true)[0],
            convertColor(color),
            convertStyle(style)
    );

    updateFlags();
}
 
Example #6
Source File: RenderedBossBar.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void update(BaseComponent title, double progress, BarColor color, BarStyle style, Set<BarFlag> flags) {
    this.title = title;
    this.progress = progress;
    this.color = color;
    this.style = style;
    this.flags.clear();
    this.flags.addAll(flags);

    views.entrySet().forEach(entry -> entry.getValue().update(renderer.render(title, entry.getKey()), progress, color, style, flags));
}
 
Example #7
Source File: PlayerListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #8
Source File: BossBarUtilsBukkitImpl.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: BossBarMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
View(BossBarSource source, Player viewer) {
    this.source = source;
    this.viewer = viewer;
    this.bar = bossBarFactory.createBossBar(Components.blank(), BarColor.WHITE, BarStyle.SOLID);
    render();
    bar.addPlayer(viewer);
}
 
Example #10
Source File: Messages.java    From Harbor with MIT License 5 votes vote down vote up
public static void sendBossBarMessage(final World world, final String message, final String color, final double percentage) {
    if (!Config.getBoolean("messages.bossbar.enabled") || message.length() < 1) return;
    BossBar bar = Bukkit.createBossBar(Messages.prepareMessage(world, message), getBarColor(color), BarStyle.SOLID);
    bar.setProgress(percentage);
    world.getPlayers().forEach(bar::addPlayer);
    Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), bar::removeAll, Config.getInteger("interval") * 20);
}
 
Example #11
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void changeStyle(String id, BarStyle style) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.setStyle(style);
        barMap.put(id, bar);
    }
}
 
Example #12
Source File: EffCreateModernBossBar.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    BarStyle barStyle = BarStyle.SOLID;
    BarColor barColor = BarColor.PURPLE;
    if (style != null) {
        barStyle = style.getSingle(evt).getKey();
    }
    if (color != null) {
        barColor = color.getSingle(evt).getKey();
    }
    BossBar bar;
    if (flag != null) {
        bar = Bukkit.createBossBar(title.getSingle(evt).replace("\"", ""), barColor, barStyle,
                flag.getSingle(evt).getKey());
    } else {
        bar = Bukkit.createBossBar(title.getSingle(evt).replace("\"", ""), barColor, barStyle);
    }
    if (value != null) {
        double vol = value.getSingle(evt).doubleValue();
        if (vol > 100) {
            vol = 100;
        } else if (vol < 0) {
            vol = 0;
        }
        bar.setProgress(vol / 100);
    }
    for (Player p : players.getAll(evt)) {
        bar.addPlayer(p);
    }
    Core.bossbarManager.createBossBar(id.getSingle(evt).replace("\"", ""), bar);
}
 
Example #13
Source File: CraftBossBar.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private BossInfo.Overlay convertStyle(BarStyle style) {
    switch (style) {
        default:
        case SOLID:
            return BossInfo.Overlay.PROGRESS;
        case SEGMENTED_6:
            return BossInfo.Overlay.NOTCHED_6;
        case SEGMENTED_10:
            return BossInfo.Overlay.NOTCHED_10;
        case SEGMENTED_12:
            return BossInfo.Overlay.NOTCHED_12;
        case SEGMENTED_20:
            return BossInfo.Overlay.NOTCHED_20;
    }
}
 
Example #14
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public LocalizedBossBar(ChatMessage bossBarTitle, BarColor color, BarStyle style, BarFlag... flags) {
    this.bossBarTitle = bossBarTitle;
    this.color = color;
    this.style = style;
    this.shown = true;
    this.flags = flags.length > 0 ? EnumSet.of(flags[0], flags):EnumSet.noneOf(BarFlag.class);
}
 
Example #15
Source File: FlagBossbar.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFlagAdd(Game game) {
    baseTitle = getI18N().getVarString(Messages.Broadcast.BOSSBAR_PLAYING_ON)
            .setVariable("game", game.getName())
            .toString();
    baseColor = new SafeContainer<>(BarColor.GREEN);

    bossBar = new SafeContainer<>(Bukkit.getServer().createBossBar(baseTitle, baseColor.value, BarStyle.SOLID));
    bossBar.value.setProgress(DEFAULT_PROGRESS);
}
 
Example #16
Source File: Poll.java    From CardinalPGM with MIT License 5 votes vote down vote up
protected Poll(int id, CommandSender sender, String command, int time, boolean any) {
    this.id = id;
    this.sender = sender;
    this.command = command;
    this.any = any;
    this.time = time * 20;
    this.originalTime = this.time;
    this.bossBar = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.YELLOW, BarStyle.SOLID, true);
    taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Cardinal.getInstance(), new Runnable() {
        @Override
        public void run() {
            Poll.this.update();
        }
    }, 0L, 1L);
}
 
Example #17
Source File: BossBars.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static UUID addBroadcastedBossBar(ChatMessage bossBarTitle, BarColor color, BarStyle style, Boolean shown, BarFlag... flags) {
    UUID id = UUID.randomUUID();
    LocalizedBossBar bossBar = new LocalizedBossBar(bossBarTitle, color, style, flags);
    bossBar.setVisible(shown);
    for (Player player : Bukkit.getOnlinePlayers()) {
        bossBar.addPlayer(player);
    }
    broadcastedBossBars.put(id, bossBar);
    return id;
}
 
Example #18
Source File: BossBarOptions.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public Builder style(String barStyle) {
    for (BarStyle loopStyle : BarStyle.values()) {
        if (loopStyle.name().equalsIgnoreCase(barStyle)) {
            this.barStyle = loopStyle;
            break;
        }
    }

    return this;
}
 
Example #19
Source File: MonumentModes.java    From CardinalPGM with MIT License 5 votes vote down vote up
public MonumentModes(int after, final Pair<Material, Integer> material, final String name, int showBefore) {
    this.after = after;
    this.material = material;
    this.name = name;
    this.showBefore = showBefore;

    this.ran = false;

    this.bossBar = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.BLUE, BarStyle.SOLID, false);
}
 
Example #20
Source File: TimeNotifications.java    From CardinalPGM with MIT License 4 votes vote down vote up
protected TimeNotifications() {
    this.bossBar = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.GREEN, BarStyle.SOLID, false);
}
 
Example #21
Source File: CycleTimer.java    From CardinalPGM with MIT License 4 votes vote down vote up
public CycleTimer(Match match) {
    super(BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.BLUE, BarStyle.SOLID, false));
    this.match = match;
}
 
Example #22
Source File: StartTimer.java    From CardinalPGM with MIT License 4 votes vote down vote up
public StartTimer(Match match) {
    super(BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.GREEN, BarStyle.SOLID, false), false);
    this.match = match;
    this.neededPlayers = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.RED, BarStyle.SOLID, false);
}
 
Example #23
Source File: Stats.java    From CardinalPGM with MIT License 4 votes vote down vote up
public void updateDisplay(final Player player) {
    if (!shouldShow(player)) return;

    final int kills = getKills(player.getUniqueId());
    final int deaths = getDeaths(player.getUniqueId());
    final String kd = format.format((double)kills / Math.max(deaths, 1)).replace(",", ".");

    switch (Settings.getSettingByName("Stats").getValueByPlayer(player).getValue()) {
        case "sidebar":
            if (!sidebarView.contains(player.getUniqueId())) {
                sidebarView.add(player.getUniqueId());
                sendTeamPackets(player, true);
            }
            sendSlotPackets(player, true);
            String prefix = "K:" + ChatColor.GREEN + Math.min(kills, 999);
            String suffix = "" + Math.min(deaths, 999) + ChatColor.WHITE + " K/D:" + ChatColor.AQUA + kd;
            PacketUtils.sendPacket(player, new PacketPlayOutScoreboardTeam(2, "scoreboard-stats", "scoreboard-stats", prefix, suffix, -1, "never", "never", 0, Collections.singletonList(scoreboardEntry)));
            break;
        case "boss bar":
            if (!bossBars.containsKey(player.getUniqueId())) {
                LocalizedBossBar bossBar = new LocalizedBossBar(new UnlocalizedChatMessage(""), BarColor.PURPLE, BarStyle.SOLID);
                bossBar.addPlayer(player);
                bossBars.put(player.getUniqueId(), bossBar);
            }
            bossBars.get(player.getUniqueId()).setTitle(getLocalizedMessage(kills, deaths, kd));
            break;
        case "action bar":
            if (actionBarTasks.containsKey(player.getUniqueId())) {
                Bukkit.getScheduler().cancelTask(actionBarTasks.get(player.getUniqueId()));
            }
            actionBarTasks.put(player.getUniqueId(), Bukkit.getScheduler().scheduleSyncRepeatingTask(Cardinal.getInstance(), new Runnable() {

                private int tick;

                @Override
                public void run() {
                    if (tick > 40) {
                        if (actionBarTasks.containsKey(player.getUniqueId())) {
                            Bukkit.getScheduler().cancelTask(actionBarTasks.get(player.getUniqueId()));
                            actionBarTasks.remove(player.getUniqueId());
                        }
                    } else {
                        sendActionBarPacket(player, kills, deaths, kd);
                        tick++;
                    }
                }
            }, 1L, 1L));
            break;
    }
}
 
Example #24
Source File: DefaultBossBarProvider.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
public DefaultBossBarProvider(User user) {
    this.user = user;
    this.bossBar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID);
}
 
Example #25
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 4 votes vote down vote up
public BarStyle getStyle() {
    return this.style;
}
 
Example #26
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 4 votes vote down vote up
public void setStyle(BarStyle style) {
    this.style = style;
    for (BossBar bossbar : playerBossBars.values()) {
        bossbar.setStyle(this.style);
    }
}
 
Example #27
Source File: Compat111.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
static void sendBarMsg(String msg, String color, Player p) {
    BossBar bar = Bukkit.createBossBar(msg, BarColor.valueOf(color), BarStyle.SEGMENTED_10);
    bar.addPlayer(p);
    removeBar(bar, p);
}
 
Example #28
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 4 votes vote down vote up
public static void sendDurabilityBossBar(Player player, ItemStack item, EquipmentSlot slot) {
	BossBarConfig config = ConfigFile.getInstance().getBossBarConfig();
	if (!config.show())
		return;
	UUID uuid = player.getUniqueId();
	BossBar bar;
	HashMap<UUID, BossBar> playersBars;
	String title;
	if (slot.equals(EquipmentSlot.HAND)) {
		title = LangFileUtils.get("item_durability_main_hand");
		playersBars = playersBarsMain;
	} else if (slot.equals(EquipmentSlot.OFF_HAND)) {
		title = LangFileUtils.get("item_durability_off_hand");
		playersBars = playersBarsOff;
	} else {
		return;
	}
	if (!playersBars.containsKey(uuid)) {
		bar = Bukkit.createBossBar(title, BarColor.GREEN, BarStyle.SOLID);
		bar.addPlayer(player);
		playersBars.put(uuid, bar);
	} else {
		bar = playersBars.get(uuid);
	}
	if (item == null || item.getType() == Material.AIR) {
		bar.setVisible(false);
		bar.setProgress(1.0D);
		return;
	}
	int durability = 0;
	int durabilityMax = 0;
	if (AdditionsAPI.isCustomItem(item)) {
		if (!config.showCustomItems() || item.getType().getMaxDurability() == 0) {
			bar.setVisible(false);
			bar.setProgress(1.0D);
			return;
		}
		CustomItemStack cStack = new CustomItemStack(item);
		CustomItem cItem = cStack.getCustomItem();
		if (cItem.hasFakeDurability()) {
			durability = cStack.getFakeDurability();
			durabilityMax = cItem.getFakeDurability();
		} else if (cStack.getCustomItem().isUnbreakable()) {
			bar.setVisible(false);
			bar.setProgress(1.0D);
			return;
		} else {
			durabilityMax = item.getType().getMaxDurability();
			durability = durabilityMax - item.getDurability();
		}
	} else if (item.getType().getMaxDurability() != 0) {
		if (!config.showVanillaItems()) {
			bar.setVisible(false);
			bar.setProgress(1.0D);
			return;
		}
		durabilityMax = item.getType().getMaxDurability();
		durability = durabilityMax - item.getDurability();
	} else {
		bar.setVisible(false);
		bar.setProgress(1.0D);
		return;
	}
	double progress = (double) durability / (double) durabilityMax;
	if (progress > 1) {
		progress = 1;
	} else if (progress < 0) {
		progress = 0;
	}
	bar.setVisible(true);
	if (progress < 0)
		progress = 0;
	else if (progress > 1)
		progress = 1;
	try {
		bar.setProgress(progress);
	} catch (IllegalArgumentException event) {}
	if (progress >= 0.5) {
		bar.setColor(BarColor.GREEN);
		bar.setTitle(title + ChatColor.GREEN + durability + " / " + durabilityMax);
	} else if (progress >= 0.25) {
		bar.setColor(BarColor.YELLOW);
		bar.setTitle(title + ChatColor.YELLOW + durability + " / " + durabilityMax);
	} else {
		bar.setColor(BarColor.RED);
		bar.setTitle(title + ChatColor.RED + durability + " / " + durabilityMax);
	}
}
 
Example #29
Source File: RenderedBossBar.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public BarStyle getStyle() {
    return style;
}
 
Example #30
Source File: BossBarFeature.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
public void setStyle(BarStyle style) {
    this.style = style;
}