org.bukkit.boss.BossBar Java Examples

The following examples show how to use org.bukkit.boss.BossBar. 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: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void changeColor(String id, BarColor color) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.setColor(color);
        barMap.put(id, bar);
    }
}
 
Example #4
Source File: LugolsIodineDisplay.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
private void remove(Player player) {
    Objects.requireNonNull(player, "player");

    UUID playerId = player.getUniqueId();
    BossBar bossBar = this.displayMap.get(playerId);

    if (bossBar != null) {
        bossBar.removePlayer(player);
        this.displayMap.remove(playerId);
    }
}
 
Example #5
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 #6
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 #7
Source File: Compat111.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
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: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void createBossBar(String id, BossBar bossbar) {
    if (barMap.containsKey(id)) {
        barMap.get(id).removeAll();
        barMap.remove(id);
    }
    barMap.put(id, bossbar);
}
 
Example #10
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void addFlag(String id, BarFlag flag) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.addFlag(flag);
        barMap.put(id, bar);
    }
}
 
Example #11
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void removeFlag(String id, BarFlag flag) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.removeFlag(flag);
        barMap.put(id, bar);
    }
}
 
Example #12
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
 */
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);
    }
}
 
Example #13
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
 */
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);
    }
}
 
Example #14
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove a bossbar from the BossBarManager and remove it from all players who were assigned it.
 *
 * @param id The ID text for the bossbar.
 */
void removeBar(String id) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.removeAll();
        barMap.remove(id);
    }
}
 
Example #15
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void changeTitle(String id, String title) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.setTitle(title);
        barMap.put(id, bar);
    }
}
 
Example #16
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 #17
Source File: LugolsIodineDisplay.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
public void disable() {
    HandlerList.unregisterAll(this);

    if (this.task != null) {
        this.task.cancel();
    }

    this.displayMap.values().forEach(BossBar::removeAll);
    this.displayMap.clear();
}
 
Example #18
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 #19
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
void hideBar(String id) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.setVisible(false);
        barMap.put(id, bar);
    }
}
 
Example #20
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show a bossbar from the BossBarManager through the stored ID for all players
 * who were assigned it.
 *
 * @param id The ID text for the bossbar.
 */
void showBar(String id) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        bar.setVisible(true);
        barMap.put(id, bar);
    }
}
 
Example #21
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the title of a stored bossbar from the BossBarManager through the ID.
 *
 * @param id The ID text for the bossbar.
 * @return Title of the bossbar
 */
String getBarTitle(String id) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        return bar.getTitle();
    }
    return null;
}
 
Example #22
Source File: BossBarManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the progress or fill of a stored bossbar from the BossBarManager through the ID.
 *
 * @param id The ID text for the bossbar.
 * @return The progress or fill of the bossbar from 0 - 100.
 */
Number getBarProgress(String id) {
    BossBar bar = barMap.get(id);
    if (bar != null) {
        return bar.getProgress();
    }
    return null;
}
 
Example #23
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 #24
Source File: BossAnnouncer.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void remBossBar(Player player) {
    BossBar bossBar = playerBars.getOrDefault(player.getUniqueId(), null);
    if (bossBar != null) {
        bossBar.removePlayer(player);
        playerBars.remove(player.getUniqueId());
    }
}
 
Example #25
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void setColor(BarColor color) {
    if (color != this.color) {
        this.color = color;
        for (BossBar bossbar : playerBossBars.values()) {
            bossbar.setColor(color);
        }
    }
}
 
Example #26
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void removeFlag(BarFlag flag) {
    if (this.flags.contains(flag)) {
        this.flags.remove(flag);
        for (BossBar bossbar : playerBossBars.values()) {
            bossbar.setFlags(this.flags);
        }
    }
}
 
Example #27
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void addFlag(BarFlag flag) {
    if (!this.flags.contains(flag)) {
        this.flags.remove(flag);
        for (BossBar bossbar : playerBossBars.values()) {
            bossbar.setFlags(this.flags);
        }
    }
}
 
Example #28
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 #29
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 #30
Source File: LocalizedBossBar.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void setVisible(Boolean visible) {
    if (visible != this.shown) {
        this.shown = visible;
        for (BossBar bossbar : playerBossBars.values()) {
            bossbar.setVisible(visible);
        }
    }
}