Package net.aufdemrand.denizen.tags

Examples of net.aufdemrand.denizen.tags.Attribute


        // Alternatives are stripped, value is stripped, let's remember the raw tag for the attributer.
        raw_tag = tag.trim();

        // Use Attributes system to get type/subtype/etc. etc. for 'static/legacy' tags.
        core_attributes = new Attribute(raw_tag, scriptEntry);
        core_attributes.setHadAlternative(hasAlternative());
    }
View Full Code Here


        if (attribute.startsWith("filter")
                && attribute.hasContext(1)) {
            dList newlist = new dList();
            try {
                for (String str: this) {
                    if (ObjectFetcher.pickObjectFor(str).getAttribute(new Attribute(attribute.getContext(1),
                            attribute.getScriptEntry())).equalsIgnoreCase("true")) {
                        newlist.add(str);
                    }
                }
            }
            catch (Exception ex) {
                dB.echoError(ex);
            }
            return newlist.getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <li@list.parse[<tag>]>
        // @returns dList
        // @description
        // returns a copy of the list with all its contents parsed through the given tag.
        // For example, a list of 'one|two' .parse[to_uppercase] returns a list of 'ONE|TWO'.
        // -->
        if (attribute.startsWith("parse")
                && attribute.hasContext(1)) {
            dList newlist = new dList();
            try {
                for (String str: this) {
                    newlist.add(ObjectFetcher.pickObjectFor(str).getAttribute(new Attribute(attribute.getContext(1),
                            attribute.getScriptEntry())));
                }
            }
            catch (Exception ex) {
                dB.echoError(ex);
View Full Code Here

    @EventHandler
    public void yaml(ReplaceableTagEvent event) {

        if (!event.matches("yaml")) return;

        Attribute attribute = event.getAttributes();

        // <--[tag]
        // @attribute <yaml.list>
        // @returns dList
        // @description
        // Returns a list of all currently loaded YAML ID's.
        // -->
        if (attribute.getAttribute(2).equalsIgnoreCase("list")) {
            dList list = new dList();
            list.addAll(yamls.keySet());
            event.setReplaced(list.getAttribute(attribute.fulfill(2)));
            return;
        }

        // YAML tag requires name context and type context.
        if (!event.hasNameContext() || !(event.hasTypeContext() || attribute.getAttribute(2).equalsIgnoreCase("to_json"))) {
            dB.echoError("YAML tag '" + event.raw_tag + "' is missing required context. Tag replacement aborted.");
            return;
        }

        // Set id (name context) and path (type context)
        String id = event.getNameContext();
        String path = event.getTypeContext();

        // Check if there is a yaml file loaded with the specified id
        if (!yamls.containsKey(id.toUpperCase())) {
            dB.echoError("YAML tag '" + event.raw_tag + "' has specified an invalid ID, or the specified id has already" +
                    " been closed. Tag replacement aborted. ID given: '" + id + "'.");
            return;
        }

        // Catch up with what has already been processed.
        attribute.fulfill(1);

        //
        // Check attributes
        //

        // <--[tag]
        // @attribute <yaml[<id>].contains[<path>]>
        // @returns Element(Boolean)
        // @description
        // Returns true if the file has the specified path.
        // Otherwise, returns false.
        // -->
        if (attribute.startsWith("contains")) {
            event.setReplaced(new Element(getYaml(id).contains(path))
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <yaml[<id>].is_list[<path>]>
        // @returns Element(Boolean)
        // @description
        // Returns true if the specified path results in a list.
        // -->
        if (attribute.startsWith("is_list")) {
            event.setReplaced(new Element(getYaml(id).isList(path))
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <yaml[<id>].read[<path>]>
        // @returns Element
        // @description
        // Returns the value of the key at the path.
        // If the key is a list, returns a dList instead.
        // -->
        if (attribute.startsWith("read")) {
            attribute.fulfill(1);

            if (getYaml(id).isList(path)) {
                List<String> value = getYaml(id).getStringList(path);
                if (value == null) {
                    // If value is null, the key at the specified path didn't exist.
                    return;
                }
                else {
                    event.setReplaced(new dList(value).getAttribute(attribute));
                    return;
                }
            }
            else {
                String value = getYaml(id).getString(path);
                if (value == null) {
                    // If value is null, the key at the specified path didn't exist.
                    return;
                }
                else {
                    event.setReplaced(new Element(value).getAttribute(attribute));
                    return;
                }
            }
        }

        // <--[tag]
        // @attribute <yaml[<id>].list_deep_keys[<path>]>
        // @returns dList
        // @description
        // Returns a dList of all the keys at the path and all subpaths.
        // -->
        if (attribute.startsWith("list_deep_keys")) {
            Set<String> keys;
            if (path != null && path.length() > 0) {
                YamlConfiguration section = getYaml(id).getConfigurationSection(path);
                if (section == null) {
                    return;
                }
                keys = section.getKeys(true);
            }
            else {
                keys = getYaml(id).getKeys(true);
            }
            if (keys == null) {
                return;

            } else {
                ArrayList<String> list = new ArrayList<String>();
                list.addAll(keys);
                event.setReplaced(new dList(list).getAttribute(attribute.fulfill(1)));
                return;
            }
        }

        // <--[tag]
        // @attribute <yaml[<id>].list_keys[<path>]>
        // @returns dList
        // @description
        // Returns a dList of all the keys at the path.
        // -->
        if (attribute.startsWith("list_keys")) {
            Set<String> keys;
            if (path != null && path.length() > 0) {
                YamlConfiguration section = getYaml(id).getConfigurationSection(path);
                if (section == null) {
                    return;
                }
                keys = section.getKeys(false);
            }
            else {
                keys = getYaml(id).getKeys(false);
            }
            if (keys == null) {
                return;

            } else {
                ArrayList<String> list = new ArrayList<String>();
                list.addAll(keys);
                event.setReplaced(new dList(list).getAttribute(attribute.fulfill(1)));
                return;
            }
        }

        // <--[tag]
        // @attribute <yaml[<id>].to_json>
        // @returns dList
        // @description
        // Converts the YAML container to a JSON array.
        // -->
        if (attribute.startsWith("to_json")) {
            JSONObject jsobj = new JSONObject(getYaml(id).getMap());
            event.setReplaced(new Element(jsobj.toString()).getAttribute(attribute.fulfill(1)));
            return;
        }
    }
View Full Code Here

    public void entityTags(ReplaceableTagEvent event) {

        if (!event.matches("entity") || event.replaced()) return;

        // Build a new attribute out of the raw_tag supplied in the script to be fulfilled
        Attribute attribute = event.getAttributes();

        dEntity e = null;

        // Entity tag may specify a new entity in the <entity[context]...> portion of the tag.
        if (attribute.hasContext(1))
            // Check if this is a valid entity and update the dEntity object reference.
            if (attribute.getIntContext(1) >= 1)
               e = dEntity.valueOf("e@" + attribute.getContext(1));

        if (e == null || !e.isValid()) {
            if (!event.hasAlternative()) dB.echoError("Invalid or missing entity for tag <" + event.raw_tag + ">!");
            return;
        }

        event.setReplaced(e.getAttribute(attribute.fulfill(1)));
    }
View Full Code Here

        if (cuboid == null) {
            return;
        }

        // Build and fill attributes
        Attribute attribute = event.getAttributes();
        event.setReplaced(cuboid.getAttribute(attribute.fulfill(1)));

    }
View Full Code Here

            dB.echoError("No definitions available outside of a queue.");
            return;
        }
        String def = event.getScriptEntry().getResidingQueue().getDefinition(defName);

        Attribute atttribute = event.getAttributes().fulfill(1);

        // <--[tag]
        // @attribute <definition[<name>].exists>
        // @returns Element(Boolean)
        // @description
        // Returns whether a definition exists for the given definition name.
        // -->
        if (atttribute.startsWith("exists")) {
            if (def == null)
                event.setReplaced(Element.FALSE.getAttribute(atttribute.fulfill(1)));
            else
                event.setReplaced(Element.TRUE.getAttribute(atttribute.fulfill(1)));
            return;
        }

        // No invalid definitions!
        if (def == null) {
View Full Code Here


    @EventHandler
    public void serverTag(ReplaceableTagEvent event) {
        if (!event.matches("server", "svr", "global") || event.replaced()) return;
        Attribute attribute =
                new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

        // <--[tag]
        // @attribute <server.has_flag[<flag_name>]>
        // @returns Element(boolean)
        // @description
        // returns true if the server has the specified flag, otherwise returns false.
        // -->
        if (attribute.startsWith("has_flag")) {
            String flag_name;
            if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
            else {
                event.setReplaced("null");
                return;
            }
            event.setReplaced(new Element(FlagManager.serverHasFlag(flag_name)).getAttribute(attribute.fulfill(1)));
        }

        // <--[tag]
        // @attribute <server.flag[<name>]>
        // @returns Flag dList
        // @description
        // returns the specified flag from the server.
        // -->
        if (attribute.startsWith("flag")) {
            String flag_name;
            if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
            else {
                event.setReplaced("null");
                return;
            }
            attribute.fulfill(1);
            // NOTE: Meta is in dList.java
            if (attribute.startsWith("is_expired")
                    || attribute.startsWith("isexpired")) {
                event.setReplaced(new Element(!FlagManager.serverHasFlag(flag_name))
                        .getAttribute(attribute.fulfill(1)));
                return;
            }
            // NOTE: Meta is in dList.java
            if (attribute.startsWith("size") && !FlagManager.serverHasFlag(flag_name)) {
                event.setReplaced(new Element(0).getAttribute(attribute.fulfill(1)));
                return;
            }
            if (FlagManager.serverHasFlag(flag_name))
                event.setReplaced(new dList(DenizenAPI.getCurrentInstance().flagManager()
                        .getGlobalFlag(flag_name))
                        .getAttribute(attribute));
            return;
        }

        // <--[tag]
        // @attribute <server.list_materials>
        // @returns dList
        // @description
        // Returns a list of all materials known to the server (only their Bukkit enum names).
        // -->
        if (attribute.startsWith("list_materials")) {
            dList allMats = new dList();
            for (Material mat: Material.values())
                allMats.add(mat.name());
            event.setReplaced(allMats.getAttribute(attribute.fulfill(1)));
        }

        // <--[tag]
        // @attribute <server.list_flags[(regex:)<search>]>
        // @returns dList
        // @description
        // Returns a list of the server's flag names, with an optional search for
        // names containing a certain pattern.
        // -->
        if (attribute.startsWith("list_flags")) {
            dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listGlobalFlags());
            dList searchFlags = null;
            if (!allFlags.isEmpty() && attribute.hasContext(1)) {
                searchFlags = new dList();
                String search = attribute.getContext(1).toLowerCase();
                if (search.startsWith("regex:")) {
                    String regex = search.substring(6);
                    try {
                        Pattern pattern = Pattern.compile(search.substring(6));
                        for (String flag : allFlags)
                            if (pattern.matcher(flag).matches())
                                searchFlags.add(flag);
                    } catch (Exception e) {
                        dB.echoError(e);
                    }
                }
                else {
                    for (String flag : allFlags)
                        if (flag.toLowerCase().contains(search))
                            searchFlags.add(flag);
                }
            }
            event.setReplaced(searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1))
                    : searchFlags.getAttribute(attribute.fulfill(1)));
        }

        // <--[tag]
        // @attribute <server.current_time_millis>
        // @returns Element(Number)
        // @description
        // Returns the number of milliseconds since Jan 1, 1970.
        // -->
        if (attribute.startsWith("current_time_millis")) {
            event.setReplaced(new Element(System.currentTimeMillis())
                    .getAttribute(attribute.fulfill(1)));
        }

        // <--[tag]
        // @attribute <server.has_event[<event_name>]>
        // @returns Element(Number)
        // @description
        // Returns whether a world event exists on the server.
        // This tag will ignore dObject identifiers (see <@link language dobject>).
        // -->
        if (attribute.startsWith("has_event")
                && attribute.hasContext(1)) {
            event.setReplaced(new Element(EventManager.eventExists(attribute.getContext(1))
                    || EventManager.eventExists(EventManager.StripIdentifiers(attribute.getContext(1))))
                    .getAttribute(attribute.fulfill(1)));
        }

        // <--[tag]
        // @attribute <server.get_event_handlers[<event_name>]>
        // @returns dList<dScript>
        // @description
        // Returns a list of all world scripts that will handle a given event name.
        // This tag will ignore dObject identifiers (see <@link language dobject>).
        // For use with <@link tag server.has_event[<event_name>]>
        // -->
        if (attribute.startsWith("get_event_handlers")
                && attribute.hasContext(1)) {
            String eventName = attribute.getContext(1).toUpperCase();
            List<WorldScriptContainer> EventsOne = EventManager.events.get("ON " + eventName);
            List<WorldScriptContainer> EventsTwo = EventManager.events.get("ON " + EventManager.StripIdentifiers(eventName));
            if (EventsOne == null && EventsTwo == null) {
                dB.echoError("No world scripts will handle the event '" + eventName + "'");
            }
            else {
                dList list = new dList();
                if (EventsOne != null) {
                    for (WorldScriptContainer script: EventsOne) {
                        list.add("s@" + script.getName());
                    }
                }
                if (EventsTwo != null) {
                    for (WorldScriptContainer script: EventsTwo) {
                        if (!list.contains("s@" + script.getName()))
                            list.add("s@" + script.getName());
                    }
                }
                event.setReplaced(list.getAttribute(attribute.fulfill(1)));
            }
        }

        // <--[tag]
        // @attribute <server.selected_npc>
        // @returns dNPC
        // @description
        // Returns the server's currently selected NPC.
        // -->
        if (attribute.startsWith("selected_npc")) {
            NPC npc = ((Citizens) Bukkit.getPluginManager().getPlugin("Citizens"))
                    .getNPCSelector().getSelected(Bukkit.getConsoleSender());
            if (npc == null)
                return;
            else
                event.setReplaced(new dNPC(npc).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.get_npcs_named[<name>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of NPCs with a certain name.
        // -->
        if (attribute.startsWith("get_npcs_named") && Depends.citizens != null && attribute.hasContext(1)) {
            ArrayList<dNPC> npcs = new ArrayList<dNPC>();
            for (NPC npc : CitizensAPI.getNPCRegistry())
                if (npc.getName().equalsIgnoreCase(attribute.getContext(1)))
                    npcs.add(dNPC.mirrorCitizensNPC(npc));
            event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.has_file[<name>]>
        // @returns Element(Boolean)
        // @description
        // Returns true if the specified file exists. The starting path is /plugins/Denizen.
        // -->
        if (attribute.startsWith("has_file") && attribute.hasContext(1)) {
            event.setReplaced(new Element(new File(DenizenAPI.getCurrentInstance().getDataFolder(),
                    attribute.getContext(1)).exists()).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.denizen_version>
        // @returns Element
        // @description
        // Returns the version of Denizen currently being used.
        // -->
        if (attribute.startsWith("denizen_version")) {
            event.setReplaced(new Element(DenizenAPI.getCurrentInstance().getDescription().getVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.bukkit_version>
        // @returns Element
        // @description
        // Returns the version of Bukkit currently being used.
        // -->
        if (attribute.startsWith("bukkit_version")) {
            event.setReplaced(new Element(Bukkit.getBukkitVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.version>
        // @returns Element
        // @description
        // Returns the version string of the server.
        // -->
        if (attribute.startsWith("version")) {
            event.setReplaced(new Element(Bukkit.getServer().getVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.java_version>
        // @returns Element
        // @description
        // Returns the current Java version of the server.
        // -->
        if (attribute.startsWith("java_version")) {
            event.setReplaced(new Element(System.getProperty("java.version"))
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.max_players>
        // @returns Element(Number)
        // @description
        // Returns the maximum number of players allowed on the server.
        // -->
        if (attribute.startsWith("max_players")) {
            event.setReplaced(new Element(Bukkit.getServer().getMaxPlayers())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_sql_connections>
        // @returns dList
        // @description
        // Returns a list of all SQL connections opened by <@link command sql>.
        // -->
        if (attribute.startsWith("list_sql_connections")) {
            dList list = new dList();
            for (Map.Entry<String, Connection> entry: SQLCommand.connections.entrySet()) {
                try {
                    if (!entry.getValue().isClosed()) {
                        list.add(entry.getKey());
                    }
                    else {
                        SQLCommand.connections.remove(entry.getKey());
                    }
                }
                catch (SQLException e) {
                    dB.echoError(attribute.getScriptEntry().getResidingQueue(), e);
                }
            }
            event.setReplaced(list.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_permission_groups>
        // @returns dList
        // @description
        // Returns a list of all permission groups on the server.
        // -->
        if (attribute.startsWith("list_permission_groups")) {
            if (Depends.permissions == null) {
                dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                return;
            }
            event.setReplaced(new dList(Arrays.asList(Depends.permissions.getGroups())).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_plugin_names>
        // @returns dList
        // @description
        // Gets a list of currently enabled plugin names from the server.
        // -->
        if (attribute.startsWith("list_plugin_names")) {
            dList plugins = new dList();
            for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins())
                plugins.add(plugin.getName());
            event.setReplaced(plugins.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_scripts>
        // @returns dList(dScript)
        // @description
        // Gets a list of all scripts currently loaded into Denizen.
        // -->
        if (attribute.startsWith("list_scripts")) {
            dList scripts = new dList();
            for (String str : ScriptRegistry._getScriptNames())
                scripts.add("s@" + str);
            event.setReplaced(scripts.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.match_player[<name>]>
        // @returns dPlayer
        // @description
        // Returns the online player that best matches the input name.
        // EG, in a group of 'bo', 'bob', and 'bobby'... input 'bob' returns p@bob,
        // input 'bobb' returns p@bobby, and input 'b' returns p@bo.
        // -->
        if (attribute.startsWith("match_player") && attribute.hasContext(1)) {
            Player matchPlayer = null;
            String matchInput = attribute.getContext(1).toLowerCase();
            for (Player player: Bukkit.getOnlinePlayers()) {
                if (player.getName().toLowerCase().equals(matchInput)) {
                    matchPlayer = player;
                    break;
                }
                else if (player.getName().toLowerCase().contains(matchInput) && matchPlayer == null) {
                    matchPlayer = player;
                }
            }

            if (matchPlayer == null) {
                event.setReplaced("null");
            } else {
                event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
            }

            return;
        }

        // <--[tag]
        // @attribute <server.get_npcs_assigned[<assignment_script>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of all NPCs assigned to a specified script.
        // -->
        if (attribute.startsWith("get_npcs_assigned") && Depends.citizens != null
                && attribute.hasContext(1)) {
            dScript script = dScript.valueOf(attribute.getContext(1));
            if (script == null || !(script.getContainer() instanceof AssignmentScriptContainer)) {
                dB.echoError("Invalid script specified.");
            }
            else {
                ArrayList<dNPC> npcs = new ArrayList<dNPC>();
                for (NPC npc : CitizensAPI.getNPCRegistry()) {
                    if (npc.hasTrait(AssignmentTrait.class) && npc.getTrait(AssignmentTrait.class).hasAssignment()
                            && npc.getTrait(AssignmentTrait.class).getAssignment().getName().equalsIgnoreCase(script.getName()))
                        npcs.add(dNPC.mirrorCitizensNPC(npc));
                }
                event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
                return;
            }
        }

        // <--[tag]
        // @attribute <server.get_online_players_flagged[<flag_name>]>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all online players with a specified flag set.
        // -->
        if (attribute.startsWith("get_online_players_flagged")
                && attribute.hasContext(1)) {
            String flag = attribute.getContext(1);
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (Player player: Bukkit.getOnlinePlayers()) {
                if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(new dPlayer(player), flag).size() > 0)
                    players.add(new dPlayer(player));
            }
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.get_players_flagged[<flag_name>]>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all players with a specified flag set.
        // -->
        if (attribute.startsWith("get_players_flagged")
                && attribute.hasContext(1)) {
            String flag = attribute.getContext(1);
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (Map.Entry<String, UUID> entry : dPlayer.getAllPlayers().entrySet()) {
                if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(entry.getValue(), flag).size() > 0)
                    players.add(new dPlayer(entry.getValue()));
            }
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.get_spawned_npcs_flagged[<flag_name>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of all spawned NPCs with a specified flag set.
        // -->
        if (attribute.startsWith("get_spawned_npcs_flagged") && Depends.citizens != null
                && attribute.hasContext(1)) {
            String flag = attribute.getContext(1);
            ArrayList<dNPC> npcs = new ArrayList<dNPC>();
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                dNPC dNpc = dNPC.mirrorCitizensNPC(npc);
                if (dNpc.isSpawned() && FlagManager.npcHasFlag(dNpc, flag))
                    npcs.add(dNpc);
            }
            event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.get_npcs_flagged[<flag_name>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of all NPCs with a specified flag set.
        // -->
        if (attribute.startsWith("get_npcs_flagged") && Depends.citizens != null
                && attribute.hasContext(1)) {
            String flag = attribute.getContext(1);
            ArrayList<dNPC> npcs = new ArrayList<dNPC>();
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                dNPC dNpc = dNPC.mirrorCitizensNPC(npc);
                if (FlagManager.npcHasFlag(dNpc, flag))
                    npcs.add(dNpc);
            }
            event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_npcs>
        // @returns dList(dNPC)
        // @description
        // Returns a list of all NPCs.
        // -->
        if (attribute.startsWith("list_npcs") && Depends.citizens != null) {
            ArrayList<dNPC> npcs = new ArrayList<dNPC>();
            for (NPC npc : CitizensAPI.getNPCRegistry())
                npcs.add(dNPC.mirrorCitizensNPC(npc));
            event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_worlds>
        // @returns dList(dWorld)
        // @description
        // Returns a list of all worlds.
        // -->
        if (attribute.startsWith("list_worlds")) {
            ArrayList<dWorld> worlds = new ArrayList<dWorld>();
            for (World world : Bukkit.getWorlds())
                worlds.add(dWorld.mirrorBukkitWorld(world));
            event.setReplaced(new dList(worlds).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_plugins>
        // @returns dList(dPlugin)
        // @description
        // Gets a list of currently enabled dPlugins from the server.
        // -->
        if (attribute.startsWith("list_plugins")) {
            ArrayList<dPlugin> plugins = new ArrayList<dPlugin>();
            for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins())
                plugins.add(new dPlugin(plugin));
            event.setReplaced(new dList(plugins).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_players>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all players that have ever played on the server, online or not.
        // -->
        if (attribute.startsWith("list_players")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (OfflinePlayer player : Bukkit.getOfflinePlayers())
                    players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_online_players>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all online players.
        // -->
        if (attribute.startsWith("list_online_players")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (Player player : Bukkit.getOnlinePlayers())
                players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_offline_players>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all offline players.
        // -->
        if (attribute.startsWith("list_offline_players")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (OfflinePlayer player : Bukkit.getOfflinePlayers())
                if (!player.isOnline()) players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_ops>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all ops, online or not.
        // -->
        if (attribute.startsWith("list_ops")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (OfflinePlayer player : Bukkit.getOfflinePlayers())
                if (player.isOp()) players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_online_ops>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all online ops.
        // -->
        if (attribute.startsWith("list_online_ops")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (Player player : Bukkit.getOnlinePlayers())
                if (player.isOp()) players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_offline_ops>
        // @returns dList(dPlayer)
        // @description
        // Returns a list of all offline ops.
        // -->
        if (attribute.startsWith("list_offline_ops")) {
            ArrayList<dPlayer> players = new ArrayList<dPlayer>();
            for (OfflinePlayer player : Bukkit.getOfflinePlayers())
                if (player.isOp() && !player.isOnline()) players.add(dPlayer.mirrorBukkitPlayer(player));
            event.setReplaced(new dList(players).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.motd>
        // @returns Element
        // @description
        // Returns the server's current MOTD
        // -->
        if (attribute.startsWith("motd")) {
            event.setReplaced(new Element(Bukkit.getServer().getMotd()).getAttribute(attribute.fulfill(1)));
            return;
        }
        // TODO: Add everything else from Bukkit.getServer().*

    }
View Full Code Here

        String object = event.getType();

        // First, check queue object context.
        if (event.getScriptEntry().getResidingQueue().hasContext(object)) {
            Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
            event.setReplaced(event.getScriptEntry().getResidingQueue()
                    .getContext(object).getAttribute(attribute.fulfill(2)));
            return;
        }

        // Next, try to replace with task-script-defined context
        // NOTE: (DEPRECATED -- new RUN command uses definitions system instead)
View Full Code Here

        if (event.getScriptEntry().getResidingQueue() != null) {

            // Get the entry_id from name context
            String id = event.getNameContext();

            Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
            ScriptEntry held = event.getScriptEntry().getResidingQueue().getHeldScriptEntry(id);
            if (held == null) { // Check if the ID is bad
                dB.echoDebug(event.getScriptEntry(), "Bad saved entry ID '" + id + "'");

            } else {
                if (!held.hasObject(attribute.getAttribute(2)) // Check if there's no such object
                        || held.getdObject(attribute.getAttribute(2)) == null) { // ... or if there is such an object
                    dB.echoDebug(event.getScriptEntry(), "Missing saved entry object '" + attribute.getAttribute(2) + "'"); // but it's not a dObject...

                } else { // Okay, now it's safe!
                    event.setReplaced(held.getdObject(attribute.getAttribute(2)).getAttribute(attribute.fulfill(2)));
                }
            }
        }

        //else event.setReplaced("null");
View Full Code Here

    @EventHandler
    public void queueTag(ReplaceableTagEvent event) {

        if (!event.matches("queue", "q")) return;

        Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

        // Handle <queue[id]. ...> tags

        if (event.hasNameContext()) {
            if (!ScriptQueue._queueExists(event.getNameContext()))
                return;
            else
                event.setReplaced(ScriptQueue._getExistingQueue(event.getNameContext())
                        .getAttribute(attribute.fulfill(1)));
            return;
        }


        // Otherwise, try to use queue in a static manner.

        // <--[tag]
        // @attribute <queue.exists[<queue_id>]>
        // @returns Element(Boolean)
        // @description
        // Returns whether the specified queue exists.
        // -->
        if (attribute.startsWith("exists")
                && attribute.hasContext(1)) {
            event.setReplaced(new Element(ScriptQueue._queueExists(attribute.getContext(1)))
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <queue.stats>
        // @returns Element
        // @description
        // Returns stats for all queues during this server session
        // -->
        if (attribute.startsWith("stats")) {
            event.setReplaced(new Element(ScriptQueue._getStats())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <queue.list>
        // @returns dList(Queue)
        // @description
        // Returns a list of all currently running queues on the server.
        // -->
        if (attribute.startsWith("list")) {
            event.setReplaced(new dList(ScriptQueue._getQueues())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }


        // Else,
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.tags.Attribute

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.