Java Code Examples for org.bukkit.boss.BossBar#setProgress()

The following examples show how to use org.bukkit.boss.BossBar#setProgress() . 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: LugolsIodineDisplay.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
private void add(Player player, LugolsIodineEffect.Effect effect) {
    Objects.requireNonNull(player, "player");
    Objects.requireNonNull(effect, "effect");

    BossBar bossBar = this.displayMap.computeIfAbsent(player.getUniqueId(), playerId -> this.createBossBar());
    bossBar.setProgress(effect.getSecondsLeft() / (double) effect.getInitialSeconds());
    bossBar.addPlayer(player);
}
 
Example 2
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 6 votes vote down vote up
public static void hideDurabilityBossBar(Player player, EquipmentSlot slot) {
	UUID uuid = player.getUniqueId();
	BossBar bar;
	HashMap<UUID, BossBar> playersBars;
	if (slot.equals(EquipmentSlot.HAND)) {
		playersBars = playersBarsMain;
	} else if (slot.equals(EquipmentSlot.OFF_HAND)) {
		playersBars = playersBarsOff;
	} else {
		return;
	}
	if (!playersBars.containsKey(uuid)) {
		return;
	} else {
		bar = playersBars.get(uuid);
	}

	bar.setVisible(false);
	bar.setProgress(1.0D);
	bar.setColor(BarColor.GREEN);
}
 
Example 3
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 4
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 5
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
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);
    }
}
 
Example 6
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 7
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void setProgress(double progress) {
    if (progress == 0D || progress == 1D || Math.abs(this.progress - progress) > 0.0049D) {
        this.progress = progress;
        for (BossBar bossbar : playerBossBars.values()) {
            bossbar.setProgress(this.progress);
        }
    }
}
 
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: BossBarUtilsBukkitImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setMessage(Player player, String message, float percent) {
	BossBar bar = createIfNotExists(player);
	bar.setTitle(message);
	bar.setProgress(percent / 100.0F);
}
 
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);
}