Search in sources :

Example 61 with Element

use of net.aufdemrand.denizencore.objects.Element 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 62 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class ExecuteCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element cmd = scriptEntry.getElement("command");
    Element type = scriptEntry.getElement("type");
    Element silent = scriptEntry.getElement("silent");
    // Report to dB
    dB.report(scriptEntry, getName(), type.debug() + cmd.debug() + silent.debug());
    String command = cmd.asString();
    switch(Type.valueOf(type.asString())) {
        case AS_PLAYER:
            try {
                PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity(), "/" + command);
                Bukkit.getPluginManager().callEvent(pcpe);
                if (!pcpe.isCancelled()) {
                    boolean silentBool = silent.asBoolean();
                    Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
                    if (silentBool) {
                        silencedPlayers.add(player.getUniqueId());
                    }
                    player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
                    if (silentBool) {
                        silencedPlayers.remove(player.getUniqueId());
                    }
                }
            } catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as player.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            break;
        case AS_OP:
            if (CoreUtilities.toLowerCase(command).equals("stop")) {
                dB.echoError("Please use as_server to execute 'stop'.");
                return;
            }
            Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
            PlayerHelper playerHelper = NMSHandler.getInstance().getPlayerHelper();
            boolean isOp = player.isOp();
            if (!isOp) {
                playerHelper.setTemporaryOp(player, true);
            }
            try {
                PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(player, "/" + command);
                Bukkit.getPluginManager().callEvent(pcpe);
                if (!pcpe.isCancelled()) {
                    boolean silentBool = silent.asBoolean();
                    if (silentBool) {
                        silencedPlayers.add(player.getUniqueId());
                    }
                    player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
                    if (silentBool) {
                        silencedPlayers.remove(player.getUniqueId());
                    }
                }
            } catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as OP.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            if (!isOp) {
                playerHelper.setTemporaryOp(player, false);
            }
            break;
        case AS_NPC:
            if (!((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned()) {
                dB.echoError(scriptEntry.getResidingQueue(), "Cannot EXECUTE AS_NPC unless the NPC is Spawned.");
                return;
            }
            if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity().getType() != EntityType.PLAYER) {
                dB.echoError(scriptEntry.getResidingQueue(), "Cannot EXECUTE AS_NPC unless the NPC is Player-Type.");
                return;
            }
            ((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setOp(true);
            try {
                ((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).performCommand(command);
            } catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as NPC-OP.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            ((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setOp(false);
            break;
        case AS_SERVER:
            dcs.clearOutput();
            dcs.silent = silent.asBoolean();
            ServerCommandEvent sce = new ServerCommandEvent(dcs, command);
            Bukkit.getPluginManager().callEvent(sce);
            DenizenAPI.getCurrentInstance().getServer().dispatchCommand(dcs, sce.getCommand());
            scriptEntry.addObject("output", new dList(dcs.getOutput()));
            break;
    }
}
Also used : PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Player(org.bukkit.entity.Player) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) PlayerHelper(net.aufdemrand.denizen.nms.interfaces.PlayerHelper) ServerCommandEvent(org.bukkit.event.server.ServerCommandEvent)

Example 63 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class ScoreboardCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Initialize necessary fields
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "l")) {
            scriptEntry.addObject("lines", arg.asElement());
        } else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id")) {
            scriptEntry.addObject("id", arg.asElement());
        } else if (!scriptEntry.hasObject("objective") && arg.matchesPrefix("objective", "obj", "o")) {
            scriptEntry.addObject("objective", arg.asElement());
        } else if (!scriptEntry.hasObject("criteria") && arg.matchesPrefix("criteria", "c")) {
            scriptEntry.addObject("criteria", arg.asElement());
        } else if (!scriptEntry.hasObject("score") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("score", arg.asElement());
        } else if (!scriptEntry.hasObject("displayslot") && (arg.matchesEnum(DisplaySlot.values()) || arg.matches("none"))) {
            scriptEntry.addObject("displayslot", arg.asElement());
        } else if (!scriptEntry.hasObject("viewers") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("viewers", arg.asType(dList.class).filter(dPlayer.class));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("action", new Element("add"));
    scriptEntry.defaultObject("id", new Element("main"));
    scriptEntry.defaultObject("criteria", new Element("dummy"));
    scriptEntry.defaultObject("displayslot", new Element("sidebar"));
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element)

Example 64 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class AnimateChestCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element action = scriptEntry.getElement("action");
    Element sound = scriptEntry.getElement("sound");
    List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
    dB.report(scriptEntry, getName(), location.debug() + action.debug() + sound.debug() + aH.debugObj("players", players.toString()));
    PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
    switch(ChestAction.valueOf(action.asString().toUpperCase())) {
        case OPEN:
            for (dPlayer player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestOpen(), 1, 1);
                }
                packetHelper.showBlockAction(ent, location, 1, 1);
            }
            break;
        case CLOSE:
            for (dPlayer player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestClose(), 1, 1);
                }
                packetHelper.showBlockAction(ent, location, 1, 0);
            }
            break;
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) PacketHelper(net.aufdemrand.denizen.nms.interfaces.PacketHelper) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 65 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class ChunkLoadCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Element action = scriptEntry.getElement("action");
    dLocation chunkloc = (dLocation) scriptEntry.getObject("location");
    Duration length = (Duration) scriptEntry.getObject("duration");
    dB.report(scriptEntry, getName(), action.debug() + chunkloc.debug() + length.debug());
    Chunk chunk = chunkloc.getChunk();
    String chunkString = chunk.getX() + ", " + chunk.getZ();
    switch(Action.valueOf(action.asString())) {
        case ADD:
            if (length.getSeconds() != 0) {
                chunkDelays.put(chunkString, System.currentTimeMillis() + length.getMillis());
            } else {
                chunkDelays.put(chunkString, (long) 0);
            }
            dB.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
            if (!chunk.isLoaded()) {
                chunk.load();
            }
            break;
        case REMOVE:
            if (chunkDelays.containsKey(chunkString)) {
                chunkDelays.remove(chunkString);
                dB.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
            } else {
                dB.echoError("Chunk was not on the load list!");
            }
            break;
        case REMOVEALL:
            dB.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
            chunkDelays.clear();
            break;
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dChunk(net.aufdemrand.denizen.objects.dChunk) Chunk(org.bukkit.Chunk)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9