Search in sources :

Example 1 with BarFlag

use of org.bukkit.boss.BarFlag 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)

Example 2 with BarFlag

use of org.bukkit.boss.BarFlag in project Citizens2 by CitizensDev.

the class BossBarTrait method run.

@Override
public void run() {
    if (!npc.isSpawned() || !isBoss(npc.getEntity()))
        return;
    BossBar bar = NMSImpl.getBossBar(npc.getEntity());
    bar.setVisible(visible);
    if (color != null) {
        bar.setColor(color);
    }
    if (title != null) {
        bar.setTitle(title);
    }
    for (BarFlag flag : BarFlag.values()) {
        bar.removeFlag(flag);
    }
    for (BarFlag flag : flags) {
        bar.addFlag(flag);
    }
}
Also used : BarFlag(org.bukkit.boss.BarFlag) BossBar(org.bukkit.boss.BossBar)

Example 3 with BarFlag

use of org.bukkit.boss.BarFlag in project Citizens2 by CitizensDev.

the class Commands method bossbar.

@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    BossBarTrait trait = npc.getTrait(BossBarTrait.class);
    if (args.hasValueFlag("color")) {
        BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
        trait.setColor(color);
    }
    if (args.hasValueFlag("title")) {
        trait.setTitle(args.getFlag("title"));
    }
    if (args.hasValueFlag("visible")) {
        trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
    }
    if (args.hasValueFlag("flags")) {
        List<BarFlag> flags = Lists.newArrayList();
        for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
            BarFlag flag = Util.matchEnum(BarFlag.values(), s);
            if (flag != null) {
                flags.add(flag);
            }
        }
        trait.setFlags(flags);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 4 with BarFlag

use of org.bukkit.boss.BarFlag in project Citizens2 by CitizensDev.

the class Commands method bossbar.

@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    BossBarTrait trait = npc.getTrait(BossBarTrait.class);
    if (args.hasValueFlag("color")) {
        BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
        trait.setColor(color);
    }
    if (args.hasValueFlag("title")) {
        trait.setTitle(args.getFlag("title"));
    }
    if (args.hasValueFlag("visible")) {
        trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
    }
    if (args.hasValueFlag("flags")) {
        List<BarFlag> flags = Lists.newArrayList();
        for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
            BarFlag flag = Util.matchEnum(BarFlag.values(), s);
            if (flag != null) {
                flags.add(flag);
            }
        }
        trait.setFlags(flags);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 5 with BarFlag

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

the class BossBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("id");
    ElementTag action = scriptEntry.getElement("action");
    ListTag players = scriptEntry.getObjectTag("players");
    ElementTag title = scriptEntry.getElement("title");
    ElementTag progress = scriptEntry.getElement("progress");
    ElementTag color = scriptEntry.getElement("color");
    ElementTag style = scriptEntry.getElement("style");
    ListTag options = scriptEntry.getObjectTag("options");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, action, players, title, progress, color, style, options);
    }
    String idString = CoreUtilities.toLowerCase(id.asString());
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case CREATE:
            {
                if (bossBarMap.containsKey(idString)) {
                    Debug.echoError("BossBar '" + idString + "' already exists!");
                    return;
                }
                String barTitle = title != null ? title.asString() : "";
                List<PlayerTag> barPlayers = players.filter(PlayerTag.class, scriptEntry);
                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[options != null ? options.size() : 0];
                if (options != null) {
                    for (int i = 0; i < options.size(); i++) {
                        barFlags[i] = (BarFlag.valueOf(options.get(i).toUpperCase()));
                    }
                }
                BossBar bossBar = Bukkit.createBossBar(barTitle, barColor, barStyle, barFlags);
                NMSHandler.getPlayerHelper().setBossBarTitle(bossBar, barTitle);
                bossBar.setProgress(barProgress);
                for (PlayerTag player : barPlayers) {
                    if (!player.isOnline()) {
                        Debug.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)) {
                    Debug.echoError("BossBar '" + idString + "' does not exist!");
                    return;
                }
                BossBar bossBar1 = bossBarMap.get(idString);
                if (title != null) {
                    NMSHandler.getPlayerHelper().setBossBarTitle(bossBar1, 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 (options != null) {
                    HashSet<BarFlag> oldFlags = new HashSet<>(Arrays.asList(BarFlag.values()));
                    HashSet<BarFlag> newFlags = new HashSet<>(options.size());
                    for (String flagName : options) {
                        BarFlag flag = BarFlag.valueOf(flagName.toUpperCase());
                        newFlags.add(flag);
                        oldFlags.remove(flag);
                    }
                    for (BarFlag flag : oldFlags) {
                        bossBar1.removeFlag(flag);
                    }
                    for (BarFlag flag : newFlags) {
                        bossBar1.addFlag(flag);
                    }
                }
                if (players != null) {
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        bossBar1.addPlayer(player.getPlayerEntity());
                    }
                }
                break;
            }
        case REMOVE:
            {
                if (!bossBarMap.containsKey(idString)) {
                    Debug.echoError("BossBar '" + idString + "' does not exist!");
                    return;
                }
                if (players != null) {
                    BossBar bar = bossBarMap.get(idString);
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        bar.removePlayer(player.getPlayerEntity());
                    }
                    break;
                }
                bossBarMap.get(idString).setVisible(false);
                bossBarMap.remove(idString);
                break;
            }
    }
}
Also used : BarStyle(org.bukkit.boss.BarStyle) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) BossBar(org.bukkit.boss.BossBar) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

BarFlag (org.bukkit.boss.BarFlag)8 BarColor (org.bukkit.boss.BarColor)5 BossBar (org.bukkit.boss.BossBar)5 Command (net.citizensnpcs.api.command.Command)3 Requirements (net.citizensnpcs.api.command.Requirements)3 BarStyle (org.bukkit.boss.BarStyle)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 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