Search in sources :

Example 1 with BarColor

use of org.bukkit.boss.BarColor in project Denizen-For-Bukkit by DenizenScript.

the class BossBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element id = scriptEntry.getElement("id");
    Element action = scriptEntry.getElement("action");
    dList players = scriptEntry.getdObject("players");
    Element title = scriptEntry.getElement("title");
    Element progress = scriptEntry.getElement("progress");
    Element color = scriptEntry.getElement("color");
    Element style = scriptEntry.getElement("style");
    dList flags = scriptEntry.getdObject("flags");
    dB.report(scriptEntry, getName(), id.debug() + action.debug() + (players != null ? players.debug() : "") + (title != null ? title.debug() : "") + (progress != null ? progress.debug() : "") + (color != null ? color.debug() : "") + (style != null ? style.debug() : "") + (flags != null ? flags.debug() : ""));
    String idString = CoreUtilities.toLowerCase(id.asString());
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case CREATE:
            if (bossBarMap.containsKey(idString)) {
                dB.echoError("BossBar '" + idString + "' already exists!");
                return;
            }
            String barTitle = title != null ? title.asString() : "";
            List<dPlayer> barPlayers = players.filter(dPlayer.class);
            double barProgress = progress != null ? progress.asDouble() : 1D;
            BarColor barColor = color != null ? BarColor.valueOf(color.asString().toUpperCase()) : BarColor.WHITE;
            BarStyle barStyle = style != null ? BarStyle.valueOf(style.asString().toUpperCase()) : BarStyle.SOLID;
            BarFlag[] barFlags = new BarFlag[flags != null ? flags.size() : 0];
            if (flags != null) {
                for (int i = 0; i < flags.size(); i++) {
                    barFlags[i] = (BarFlag.valueOf(flags.get(i).toUpperCase()));
                }
            }
            BossBar bossBar = Bukkit.createBossBar(barTitle, barColor, barStyle, barFlags);
            bossBar.setProgress(barProgress);
            for (dPlayer player : barPlayers) {
                if (!player.isOnline()) {
                    dB.echoError("Player must be online to show a BossBar to them!");
                    continue;
                }
                bossBar.addPlayer(player.getPlayerEntity());
            }
            bossBar.setVisible(true);
            bossBarMap.put(idString, bossBar);
            break;
        case UPDATE:
            if (!bossBarMap.containsKey(idString)) {
                dB.echoError("BossBar '" + idString + "' does not exist!");
                return;
            }
            BossBar bossBar1 = bossBarMap.get(idString);
            if (title != null) {
                bossBar1.setTitle(title.asString());
            }
            if (progress != null) {
                bossBar1.setProgress(progress.asDouble());
            }
            if (color != null) {
                bossBar1.setColor(BarColor.valueOf(color.asString().toUpperCase()));
            }
            if (style != null) {
                bossBar1.setStyle(BarStyle.valueOf(style.asString().toUpperCase()));
            }
            if (players != null) {
                for (dPlayer player : players.filter(dPlayer.class)) {
                    bossBar1.addPlayer(player.getPlayerEntity());
                }
            }
            break;
        case REMOVE:
            if (!bossBarMap.containsKey(idString)) {
                dB.echoError("BossBar '" + idString + "' does not exist!");
                return;
            }
            if (players != null) {
                BossBar bar = bossBarMap.get(idString);
                for (dPlayer player : players.filter(dPlayer.class)) {
                    bar.removePlayer(player.getPlayerEntity());
                }
                break;
            }
            bossBarMap.get(idString).setVisible(false);
            bossBarMap.remove(idString);
            break;
    }
}
Also used : BarStyle(org.bukkit.boss.BarStyle) BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) BossBar(org.bukkit.boss.BossBar)

Aggregations

net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 BarColor (org.bukkit.boss.BarColor)1 BarFlag (org.bukkit.boss.BarFlag)1 BarStyle (org.bukkit.boss.BarStyle)1 BossBar (org.bukkit.boss.BossBar)1