Java Code Examples for org.bukkit.boss.BarColor

The following examples show how to use org.bukkit.boss.BarColor. These examples are extracted from open source projects. 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 Project: BedWars   Source File: GameCreator.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private String setGameBossBarColor(String color) {
    color = color.toUpperCase();
    BarColor c = null;
    if (!color.equalsIgnoreCase("default")) {
        try {
            c = BarColor.valueOf(color);
        } catch (Exception e) {
            return i18n("admin_command_invalid_bar_color");
        }
    }

    game.setGameBossBarColor(c);

    return i18n("admin_command_bar_color_set").replace("%color%", c == null ? "default" : c.name())
            .replace("%type%", "GAME");
}
 
Example 2
Source Project: BedWars   Source File: GameCreator.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private String setLobbyBossBarColor(String color) {
    color = color.toUpperCase();
    BarColor c = null;
    if (!color.equalsIgnoreCase("default")) {
        try {
            c = BarColor.valueOf(color);
        } catch (Exception e) {
            return i18n("admin_command_invalid_bar_color");
        }
    }

    game.setLobbyBossBarColor(c);

    return i18n("admin_command_bar_color_set").replace("%color%", c == null ? "default" : c.name())
            .replace("%type%", "LOBBY");
}
 
Example 3
Source Project: BedWars   Source File: GameCreator.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private String setGameBossBarColor(String color) {
    color = color.toUpperCase();
    BarColor c = null;
    if (!color.equalsIgnoreCase("default")) {
        try {
            c = BarColor.valueOf(color);
        } catch (Exception e) {
            return i18n("admin_command_invalid_bar_color");
        }
    }

    game.setGameBossBarColor(c);

    return i18n("admin_command_bar_color_set").replace("%color%", c == null ? "default" : c.name())
            .replace("%type%", "GAME");
}
 
Example 4
Source Project: BedWars   Source File: GameCreator.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private String setLobbyBossBarColor(String color) {
    color = color.toUpperCase();
    BarColor c = null;
    if (!color.equalsIgnoreCase("default")) {
        try {
            c = BarColor.valueOf(color);
        } catch (Exception e) {
            return i18n("admin_command_invalid_bar_color");
        }
    }

    game.setLobbyBossBarColor(c);

    return i18n("admin_command_bar_color_set").replace("%color%", c == null ? "default" : c.name())
            .replace("%type%", "LOBBY");
}
 
Example 5
Source Project: helper   Source File: BukkitBossBarFactory.java    License: MIT License 6 votes vote down vote up
private static BarColor convertColor(BossBarColor color) {
    switch (color) {
        case PINK:
            return BarColor.PINK;
        case BLUE:
            return BarColor.BLUE;
        case RED:
            return BarColor.RED;
        case GREEN:
            return BarColor.GREEN;
        case YELLOW:
            return BarColor.YELLOW;
        case PURPLE:
            return BarColor.PURPLE;
        case WHITE:
            return BarColor.WHITE;
        default:
            return convertColor(BossBarColor.defaultColor());
    }
}
 
Example 6
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 7
Source Project: AdditionsAPI   Source File: DurabilityBar.java    License: 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 8
Source Project: CardinalPGM   Source File: TimeNotifications.java    License: MIT License 6 votes vote down vote up
@Override
public void run() {
    if (GameHandler.getGameHandler().getMatch().isRunning()) {
        int timeLimit = TimeLimit.getMatchTimeLimit();
        double time = MatchTimer.getTimeInSeconds();
        if (timeLimit > 0) {
            double timeRemaining = timeLimit - time;
            BossBars.setProgress(bossBar, timeRemaining / timeLimit);
            if (lastSecond != (int) time) {
                lastSecond = (int) time;
                BossBars.setTitle(bossBar, new UnlocalizedChatMessage(ChatColor.AQUA + "{0} " + ChatUtil.getTimerColor(timeRemaining) + "{1}", new LocalizedChatMessage(ChatConstant.UI_TIMER), new UnlocalizedChatMessage(Strings.formatTime(timeRemaining + 1))));
                if (timeRemaining < 30) {
                    BossBars.broadcastedBossBars.get(bossBar).setColor(BarColor.RED);
                } else if (timeRemaining < 60) {
                    BossBars.broadcastedBossBars.get(bossBar).setColor(BarColor.YELLOW);
                } else {
                    BossBars.broadcastedBossBars.get(bossBar).setColor(BarColor.GREEN);
                }
            }
        } else if (lastSecond != (int) time) {
            lastSecond = (int) time;
            if ((int)time % 300 == 0) sendTimeElapsedMessage(time);
        }
    }
}
 
Example 9
Source Project: BedWars   Source File: Game.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static BarColor loadBossBarColor(String color) {
    try {
        return BarColor.valueOf(color);
    } catch (Exception e) {
        return null;
    }
}
 
Example 10
Source Project: BedWars   Source File: Game.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static BarColor loadBossBarColor(String color) {
    try {
        return BarColor.valueOf(color);
    } catch (Exception e) {
        return null;
    }
}
 
Example 11
Source Project: Kettle   Source File: CraftBossBar.java    License: 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 12
Source Project: Harbor   Source File: Messages.java    License: MIT License 5 votes vote down vote up
private static BarColor getBarColor(final String enumString) {
    BarColor barColor;
    try {
        barColor = BarColor.valueOf(enumString.toUpperCase().trim());
    } catch (IllegalArgumentException e) {
        barColor = BarColor.BLUE;
    }
    return barColor;
}
 
Example 13
@Override
public BarColor barColor(Player viewer) {
    long seconds = remaining.getSeconds();
    if(seconds > 60) {
        return BarColor.GREEN;
    } else if(seconds > 30) {
        return BarColor.YELLOW;
    } else {
        return BarColor.RED;
    }
}
 
Example 14
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 15
Source Project: HeavySpleef   Source File: FlagBossbar.java    License: 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
@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 17
@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 18
Source Project: VoxelGamesLibv2   Source File: TimedPhase.java    License: MIT License 5 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 19
/**
 * 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 20
Source Project: skRayFall   Source File: BossBarManager.java    License: 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 21
@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 22
Source Project: FunnyGuilds   Source File: BossBarOptions.java    License: Apache License 2.0 5 votes vote down vote up
public Builder color(String barColor) {
    for (BarColor loopColor : BarColor.values()) {
        if (loopColor.name().equalsIgnoreCase(barColor)) {
            this.barColor = loopColor;
            break;
        }
    }

    return this;
}
 
Example 23
Source Project: CardinalPGM   Source File: MonumentModes.java    License: 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 24
Source Project: CardinalPGM   Source File: LocalizedBossBar.java    License: 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 25
Source Project: CardinalPGM   Source File: LocalizedBossBar.java    License: 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 Project: CardinalPGM   Source File: BossBars.java    License: 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 27
Source Project: CardinalPGM   Source File: Poll.java    License: 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 28
Source Project: CraftserveRadiation   Source File: BarConfig.java    License: Apache License 2.0 4 votes vote down vote up
public BarConfig(String title, BarColor color, BarStyle style, BarFlag[] flags) {
    this.title = Objects.requireNonNull(title, "title");
    this.color = Objects.requireNonNull(color, "color");
    this.style = Objects.requireNonNull(style, "style");
    this.flags = Objects.requireNonNull(flags, "flags");
}
 
Example 29
Source Project: CraftserveRadiation   Source File: BarConfig.java    License: Apache License 2.0 4 votes vote down vote up
public BarColor color() {
    return this.color;
}
 
Example 30
Source Project: CraftserveRadiation   Source File: RadiationPlugin.java    License: Apache License 2.0 4 votes vote down vote up
private boolean migrate(ConfigurationSection section, int protocol) {
    Objects.requireNonNull(section, "section");
    Logger logger = this.getLogger();

    if (protocol > CURRENT_PROTOCOL_VERSION) {
        logger.severe("Your configuration file's protocol version \"" + protocol +
                "\" is invalid. Are you trying to load it using a newer version of the plugin?");
        return false;
    }

    if (protocol < 0) {
        section.set("lugols-iodine-bar.title", "Działanie Płynu Lugola");
        section.set("lugols-iodine-bar.color", BarColor.GREEN.name());
        section.set("lugols-iodine-bar.style", BarStyle.SEGMENTED_20.name());
        section.set("lugols-iodine-bar.flags", Collections.emptyList());

        section.set("lugols-iodine-potion.name", "Płyn Lugola");
        section.set("lugols-iodine-potion.description", "Odporność na promieniowanie ({0})");
        section.set("lugols-iodine-potion.duration", TimeUnit.MINUTES.toSeconds(section.getInt("potion-duration", 10)));
        section.set("lugols-iodine-potion.drink-message", "{0}" + ChatColor.RED + " wypił/a {1}.");

        section.set("radiation.bar.title", "Strefa radiacji");
        section.set("radiation.bar.color", BarColor.RED.name());
        section.set("radiation.bar.style", BarStyle.SOLID.name());
        section.set("radiation.bar.flags", Collections.singletonList(BarFlag.DARKEN_SKY.name()));

        section.set("radiation.effects.wither.level", 5);
        section.set("radiation.effects.wither.ambient", false);
        section.set("radiation.effects.wither.has-particles", false);
        section.set("radiation.effects.wither.has-icon", false);

        section.set("radiation.effects.hunger.level", 1);
        section.set("radiation.effects.hunger.ambient", false);
        section.set("radiation.effects.hunger.has-particles", false);
        section.set("radiation.effects.hunger.has-icon", false);

        section.set("radiation.escape-message", "{0}" + ChatColor.RED + " uciekł/a do strefy radiacji.");

        // Migrate from the old region-ID based system.
        String legacyRegionId = section.getString("region-name", "km_safe_from_radiation");
        AtomicBoolean logged = new AtomicBoolean();
        section.getStringList("world-names").forEach(worldName -> {
            if (logged.compareAndSet(false, true)) {
                logger.warning(
                        "Enabling in legacy region-name mode! The plugin will try to automatically migrate to the new flag-based system.\n" +
                        "If everything went fine please completely remove your config.yml file.");
            }

            this.migrateFromRegionId(worldName, legacyRegionId);
        });
    }

    if (protocol < 1) {
        section.set("lugols-iodine-potion.recipe.enabled", true);
        section.set("lugols-iodine-potion.recipe.base-potion", LugolsIodinePotion.Config.Recipe.DEFAULT_BASE_POTION.name());
        section.set("lugols-iodine-potion.recipe.ingredient", LugolsIodinePotion.Config.Recipe.DEFAULT_INGREDIENT.getKey().getKey());

        section.set("lugols-iodine-potion.color", null);
    }

    return true;
}