Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.Element


        // @description
        // If the entity is infectable, returns whether the entity is infected.
        // Currently only Zombie or Villager entities can be infected.
        // -->
        if (attribute.startsWith("is_infected"))
            return new Element(isInfected())
                    .getAttribute(attribute.fulfill(1));

        return null;
    }
View Full Code Here


        // @description
        // Returns the display name of the item, as set by plugin or an anvil.
        // -->
        if (attribute.startsWith("display")) {
            if (hasDisplayName()) {
                return new Element(item.getItemStack().getItemMeta().getDisplayName())
                    .getAttribute(attribute.fulfill(1));
            }
        }

        // <--[tag]
        // @attribute <i@item.has_display>
        // @returns Element(Boolean)
        // @mechanism dItem.display_name
        // @group properties
        // @description
        // Returns whether the item has a custom set display name.
        // -->
        if (attribute.startsWith("has_display")) {
            return new Element(hasDisplayName())
                    .getAttribute(attribute.fulfill(1));
        }

        return null;
    }
View Full Code Here

            if (arg.matches("ASPLAYER", "AS_PLAYER", "PLAYER")
                    && !scriptEntry.hasObject("type")) {
                if (!((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer())
                    throw new InvalidArgumentsException("Must have a Player link when using AS_PLAYER.");
                scriptEntry.addObject("type", new Element("AS_PLAYER"));
            }

            else if (arg.matches("ASOPPLAYER", "ASOP", "AS_OP", "AS_OP_PLAYER", "OP")
                    && !scriptEntry.hasObject("type")) {
                if (!((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer())
                    throw new InvalidArgumentsException("Must have a Player link when using AS_OP.");
                scriptEntry.addObject("type", new Element("AS_OP"));
            }

            else if (arg.matches("ASNPC", "AS_NPC", "NPC")
                    && !scriptEntry.hasObject("type")) {
                if (!((BukkitScriptEntryData)scriptEntry.entryData).hasNPC())
                    throw new InvalidArgumentsException("Must have a NPC link when using AS_NPC.");
                scriptEntry.addObject("type", new Element("AS_NPC"));
            }

            else if (arg.matches("ASSERVER", "AS_SERVER", "SERVER")
                    && !scriptEntry.hasObject("type"))
                scriptEntry.addObject("type", new Element("AS_SERVER"));

            else if (!scriptEntry.hasObject("silent")
                    && arg.matches("silent"))
                scriptEntry.addObject("silent", new Element("true"));

            else if (!scriptEntry.hasObject("command"))
                scriptEntry.addObject("command", new Element(arg.raw_value));

            else
                arg.reportUnhandled();
        }

        if (!scriptEntry.hasObject("type"))
            throw new InvalidArgumentsException("Missing execution type!");

        if (!scriptEntry.hasObject("command"))
            throw new InvalidArgumentsException("Missing command text!");

        scriptEntry.defaultObject("silent", new Element("false"));

    }
View Full Code Here

    }

    @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())
                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().performCommand(
                            pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1): pcpe.getMessage());
            }
            catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as player.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            return;

        case AS_OP:
            boolean isOp = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().isOp();
            if (!isOp) ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().setOp(true);
            try {
                PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity(), "/" + command);
                Bukkit.getPluginManager().callEvent(pcpe);
                if (!pcpe.isCancelled())
                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().performCommand(
                            pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1): pcpe.getMessage());
            }
            catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as OP.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            if (!isOp) ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().setOp(false);
            return;

        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);
            return;

        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()));
        }
View Full Code Here

                if (format == null) dB.echoError("Could not find format script matching '" + formatStr + '\'');
                scriptEntry.addObject("format", format);
            }

            else if (!scriptEntry.hasObject("text"))
                scriptEntry.addObject("text", new Element(arg.raw_value));

        }

        // If text is missing, alert the console.
        if (!scriptEntry.hasObject("text"))
View Full Code Here

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        // Fetch objects
        Element text = scriptEntry.getElement("text");
        AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
        FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
        Element flag = scriptEntry.getElement("flag");

        // Report to dB
        dB.report(scriptEntry, getName(),
                aH.debugObj("Message", text)
                        + (format != null ? aH.debugObj("Format", format.getName()) : "")
                        + aH.debugObj("Type", type.name())
                        + (flag != null? aH.debugObj("Flag_Name", flag) : ""));

        String message = format != null ? format.getFormattedText(scriptEntry) : text.asString();

        // Use Bukkit to broadcast the message to everybody in the server.
        if (type == AnnounceType.ALL) {
            DenizenAPI.getCurrentInstance().getServer().broadcastMessage(message);
        }

        else if (type == AnnounceType.TO_OPS) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (player.isOp()) player.sendMessage(message);
            }
        }

        else if (type == AnnounceType.TO_FLAGGED) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (FlagManager.playerHasFlag(dPlayer.mirrorBukkitPlayer(player), flag.asString()))
                    player.sendMessage(message);
            }
        }

        else if (type == AnnounceType.TO_CONSOLE) {
View Full Code Here

            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"));
    }
View Full Code Here

        List<dPlayer> viewers = (List<dPlayer>) scriptEntry.getObject("viewers");
        dList lines = scriptEntry.hasObject("lines") ?
                        dList.valueOf(scriptEntry.getElement("lines").asString()) :
                        new dList();

        Element action = scriptEntry.getElement("action");
        Element id = scriptEntry.getElement("id");
        Element objective = scriptEntry.getElement("objective");
        Element criteria = scriptEntry.getElement("criteria");
        Element score = scriptEntry.getElement("score");
        Element displaySlot = scriptEntry.getElement("displayslot");
        Action act = Action.valueOf(action.asString().toUpperCase());

        // Report to dB
        dB.report(scriptEntry, getName(), action.debug() +
                             id.debug() +
                             (viewers != null ? aH.debugObj("viewers", viewers.toString()) : "") +
                             (objective != null ? objective.debug() : "") +
                             (act.equals(Action.ADD) && objective!= null
                                 ? criteria.debug()
                                 : "") +
                             (!lines.isEmpty() ? lines.debug() : "") +
                             (act.equals(Action.ADD) && score != null
                                 ? score.debug()
                                 : "") +
                             (act.equals(Action.ADD) && objective != null
                                 ? displaySlot.debug()
                                 : ""));

        Scoreboard board = null;

        // Get the main scoreboard by default
        if (id.asString().equalsIgnoreCase("main")) {
            board = ScoreboardHelper.getMain();
        }
        else {
            // If this scoreboard already exists, get it
            if (ScoreboardHelper.hasScoreboard(id.asString())) {
                board = ScoreboardHelper.getScoreboard(id.asString());
            }
            // Else, create a new one if Action is ADD
            else if (act.equals(Action.ADD)) {
                board = ScoreboardHelper.createScoreboard(id.asString());
            }
        }

        // Don't progress if we ended up with a null board
        if (board == null) {
            dB.echoError(scriptEntry.getResidingQueue(), "Scoreboard " + id.asString() + " does not exist!");
            return;
        }

        Objective obj = null;

        if (act.equals(Action.ADD)) {

            if (objective != null) {
                // Try getting the objective from the board
                obj = board.getObjective(objective.asString());

                // Create the objective if it does not already exist
                if (obj == null) {
                    obj = board.registerNewObjective(objective.asString(), criteria.asString());
                }
                // If a different criteria has been set for this objective,
                // recreate the objective
                else if (criteria != null && !obj.getCriteria().equals(criteria.asString())) {
                    obj.unregister();
                    obj = board.registerNewObjective(objective.asString(), criteria.asString());
                }

                // Change the objective's display slot
                if (!displaySlot.asString().equalsIgnoreCase("none")) {
                    obj.setDisplaySlot(DisplaySlot.valueOf(displaySlot.asString().toUpperCase()));
                }

                obj.setDisplayName(objective.asString());

                if (!lines.isEmpty()) {
                    // If we've gotten this far, but the score is null,
                    // use a score of 0
                    if (score == null) score = new Element(0);

                    // Set all the score lines in the scoreboard, creating fake players
                    // for those lines that are not meant to track players
                    //
                    // Read https://forums.bukkit.org/threads/help-with-multi-line-scoreboards.181149/
View Full Code Here

        // @group properties
        // @description
        // Returns the number of items in the dItem's itemstack.
        // -->
        if (attribute.startsWith("qty"))
            return new Element(item.getItemStack().getAmount())
                    .getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <i@item.max_stack>
        // @returns Element(Number)
        // @group properties
        // @description
        // Returns the max number of this item possible in a single stack of this type.
        // For use with <@link tag i@item.quantity> and <@link mechanism dItem.quantity>.
        // -->
        if (attribute.startsWith("max_stack"))
            return new Element(item.getItemStack().getMaxStackSize())
                    .getAttribute(attribute.fulfill(1));

        return null;
    }
View Full Code Here

        // Note: Item must be a 'skull_item' with a skin.
        // -->
        if (attribute.startsWith("skin")) {
            if (item.getItemStack().getDurability() == 3
                    && ((SkullMeta)item.getItemStack().getItemMeta()).hasOwner())
                return new Element(((SkullMeta)item.getItemStack().getItemMeta()).getOwner())
                    .getAttribute(attribute.fulfill(1));
            else
                dB.echoError("This skull_item does not have a skin set!");
        }

        // <--[tag]
        // @attribute <i@item.has_skin>
        // @returns Element(Boolean)
        // @mechanism dItem.skull_skin
        // @group properties
        // @description
        // Returns whether the item has a custom skin set.
        // (Only for human 'skull_item's)
        // -->
        if (attribute.startsWith("has_skin"))
            return new Element(item.getItemStack().getDurability() == 3
                                && ((SkullMeta)item.getItemStack().getItemMeta()).hasOwner())
                    .getAttribute(attribute.fulfill(1));


        return null;
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.objects.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.