Java Code Examples for org.bukkit.Bukkit#createBossBar()

The following examples show how to use org.bukkit.Bukkit#createBossBar() . 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: 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 3
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 4
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void addPlayer(Player player) {
    if (!playerBossBars.containsKey(player)) {
        BossBar bossBar = Bukkit.createBossBar(getTitle(player.getLocale()), this.color, this.style, this.flags.toArray(new BarFlag[flags.size()]));
        bossBar.setVisible(this.shown);
        bossBar.addPlayer(player);
        playerBossBars.put(player, bossBar);
    }
}
 
Example 5
Source File: BossBar19.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BossBar19() {
    this.boss = Bukkit.createBossBar("", BarColor.PURPLE, BarStyle.SOLID);
}
 
Example 6
Source File: BossBar19.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BossBar19() {
    this.boss = Bukkit.createBossBar("", BarColor.PURPLE, BarStyle.SOLID);
}
 
Example 7
Source File: BossBarFeature.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@Override
public void enable() {
    bossBar = Bukkit.createBossBar(message, color, style);

    getPhase().getGame().getPlayers().forEach(user -> bossBar.addPlayer(user.getPlayer()));
}
 
Example 8
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 9
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 10
Source File: BossBarNotifyIO.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendNotify(String message, Collection<? extends Player> players) {
    BossBar bossBar = Bukkit.createBossBar(Utils.format(message), barColor, style);
    if (barFlags != null) {
        for (BarFlag flag : barFlags) {
            bossBar.addFlag(flag);
        }
    }
    bossBar.setProgress(progress);

    // Show bar
    for (Player player : players) {
        bossBar.addPlayer(player);
    }

    bossBar.setVisible(true);

    // Remove after stay ticks
    new BukkitRunnable() {

        @Override
        public void run() {
            bossBar.removeAll();
        }
    }.runTaskLater(BetonQuest.getInstance(), stay);

    // If Countdown, then divide stay by countdown and reduce progress to 0 by those intevals
    if (countdown > 0) {
        int interval = stay / countdown;
        double amount = progress / ((double) countdown);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (countdown == 0) {
                    cancel();
                    return;
                }
                countdown -= 1;
                progress -= amount;
                bossBar.setProgress(Math.max(0.0, progress));
            }
        }.runTaskTimer(BetonQuest.getInstance(), interval, interval);
    }

    super.sendNotify(message, players);
}
 
Example 11
Source File: BossBarMessage.java    From HubBasics with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BossBar toBossBar(Player player) {
    return Bukkit.createBossBar(PlaceHolderUtil.replace(player, message), color, style);
}
 
Example 12
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);
}