Search in sources :

Example 11 with Attribute

use of net.aufdemrand.denizencore.tags.Attribute in project Denizen-For-Bukkit by DenizenScript.

the class ConstantTags method constantTags.

@TagManager.TagEvents
public void constantTags(ReplaceableTagEvent event) {
    if (!event.matches("cons")) {
        return;
    }
    if (!event.hasValue()) {
        dB.echoError("Constant tag '" + event.raw_tag + " does not contain a valid constant! " + "Replacement has been aborted...");
        return;
    }
    dB.echoError(event.getAttributes().getScriptEntry().getResidingQueue(), "constant: tags are deprecated! Use <npc.constant[]>!");
    NPC npc = null;
    if (event.getType() != null && event.getType().matches("\\d+")) {
        npc = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(event.getType()));
    } else if (((BukkitTagContext) event.getContext()).npc != null) {
        npc = ((BukkitTagContext) event.getContext()).npc.getCitizen();
    }
    if (npc == null) {
        dB.echoError("Constant tag '" + event.raw_tag + " does not contain a valid NPC! " + "Has the NPC been removed, or is there no NPC list available? " + "Replacement has been aborted...");
        return;
    }
    Attribute attribute = event.getAttributes();
    if (npc.hasTrait(ConstantsTrait.class) && npc.getTrait(ConstantsTrait.class).getConstant(event.getValue()) != null) {
        event.setReplaced(new Element(npc.getTrait(ConstantsTrait.class).getConstant(event.getValue())).getAttribute(attribute.fulfill(1)));
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) Attribute(net.aufdemrand.denizencore.tags.Attribute) ConstantsTrait(net.aufdemrand.denizen.npc.traits.ConstantsTrait) Element(net.aufdemrand.denizencore.objects.Element)

Example 12 with Attribute

use of net.aufdemrand.denizencore.tags.Attribute in project Denizen-For-Bukkit by DenizenScript.

the class SchematicCommand method schematicTags.

@TagManager.TagEvents
public void schematicTags(ReplaceableTagEvent event) {
    if (!event.matches("schematic, schem")) {
        return;
    }
    String id = event.hasNameContext() ? event.getNameContext().toUpperCase() : null;
    Attribute attribute = event.getAttributes().fulfill(1);
    // -->
    if (attribute.startsWith("list")) {
        event.setReplaced(new dList(schematics.keySet()).getAttribute(attribute.fulfill(1)));
    }
    if (id == null) {
        return;
    }
    if (!schematics.containsKey(id)) {
        // Meta below
        if (attribute.startsWith("exists")) {
            event.setReplaced(new Element(false).getAttribute(attribute.fulfill(1)));
            return;
        }
        dB.echoError(attribute.getScriptEntry() != null ? attribute.getScriptEntry().getResidingQueue() : null, "Schematic file " + id + " is not loaded.");
        return;
    }
    CuboidBlockSet set = schematics.get(id);
    // -->
    if (attribute.startsWith("exists")) {
        event.setReplaced(new Element(true).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("height")) {
        event.setReplaced(new Element(set.y_length).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("length")) {
        event.setReplaced(new Element(set.z_height).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("width")) {
        event.setReplaced(new Element(set.x_width).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("block")) {
        if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
            dLocation location = dLocation.valueOf(attribute.getContext(1));
            BlockData block = set.blockAt(location.getX(), location.getY(), location.getZ());
            event.setReplaced(dMaterial.getMaterialFrom(block.getMaterial(), block.getData()).getAttribute(attribute.fulfill(1)));
            return;
        }
    }
    // -->
    if (attribute.startsWith("origin")) {
        event.setReplaced(new dLocation(null, set.center_x, set.center_y, set.center_z).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("blocks")) {
        event.setReplaced(new Element(set.blocks.size()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("cuboid") && attribute.hasContext(1)) {
        dLocation origin = dLocation.valueOf(attribute.getContext(1));
        event.setReplaced(set.getCuboid(origin).getAttribute(attribute.fulfill(1)));
        return;
    }
}
Also used : Attribute(net.aufdemrand.denizencore.tags.Attribute) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) BlockData(net.aufdemrand.denizen.nms.interfaces.BlockData) CuboidBlockSet(net.aufdemrand.denizen.utilities.blocks.CuboidBlockSet)

Example 13 with Attribute

use of net.aufdemrand.denizencore.tags.Attribute in project Denizen-For-Bukkit by DenizenScript.

the class YamlCommand method yaml.

@TagManager.TagEvents
public void yaml(ReplaceableTagEvent event) {
    if (!event.matches("yaml")) {
        return;
    }
    Attribute attribute = event.getAttributes();
    // -->
    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"))) && !attribute.hasAlternative()) {
        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().toUpperCase();
    String path = event.getTypeContext();
    // Check if there is a yaml file loaded with the specified id
    if (!yamls.containsKey(id)) {
        if (!attribute.hasAlternative()) {
            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);
    // -->
    if (attribute.startsWith("contains")) {
        event.setReplaced(new Element(getYaml(id).contains(path)).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("is_list")) {
        event.setReplaced(new Element(getYaml(id).isList(path)).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    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;
            }
        }
    }
    // -->
    if (attribute.startsWith("list_deep_keys")) {
        Set<StringHolder> 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 {
            event.setReplaced(new dList(keys).getAttribute(attribute.fulfill(1)));
            return;
        }
    }
    // -->
    if (attribute.startsWith("list_keys")) {
        Set<StringHolder> 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 {
            event.setReplaced(new dList(keys).getAttribute(attribute.fulfill(1)));
            return;
        }
    }
    // -->
    if (attribute.startsWith("to_json")) {
        JSONObject jsobj = new JSONObject(getYaml(id).getMap());
        event.setReplaced(new Element(jsobj.toString()).getAttribute(attribute.fulfill(1)));
        return;
    }
}
Also used : StringHolder(net.aufdemrand.denizencore.utilities.text.StringHolder) JSONObject(org.json.JSONObject) Attribute(net.aufdemrand.denizencore.tags.Attribute) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) YamlConfiguration(net.aufdemrand.denizencore.utilities.YamlConfiguration)

Example 14 with Attribute

use of net.aufdemrand.denizencore.tags.Attribute in project Denizen-For-Bukkit by DenizenScript.

the class dMaterial method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <m@material.has_gravity>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is affected by gravity.
    // -->
    registerTag("has_gravity", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.hasGravity()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.id>
    // @returns Element(Number)
    // @description
    // Returns the material's ID.
    // -->
    registerTag("id", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.getId()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_block>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a placeable block.
    // -->
    registerTag("is_block", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isBlock()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_burnable>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a block that can burn away.
    // -->
    registerTag("is_burnable", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isBurnable()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_edible>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is edible.
    // -->
    registerTag("is_edible", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isEdible()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_flammable>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a block that can catch fire.
    // -->
    registerTag("is_flammable", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isFlammable()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_occluding>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a block that completely blocks vision.
    // -->
    registerTag("is_occluding", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isOccluding()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_record>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a playable music disc.
    // -->
    registerTag("is_record", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isRecord()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_solid>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a block that is solid (cannot be walked through).
    // -->
    registerTag("is_solid", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(!NMSHandler.getInstance().getBlockHelper().isSafeBlock(((dMaterial) object).material)).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_transparent>
    // @returns Element(Boolean)
    // @description
    // Returns whether the material is a block that does not block any light.
    // -->
    registerTag("is_transparent", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.isTransparent()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.max_durability>
    // @returns Element(Number)
    // @description
    // Returns the maximum durability of this material.
    // -->
    registerTag("max_durability", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.getMaxDurability()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.max_stack_size>
    // @returns Element(Number)
    // @description
    // Returns the maximum amount of this material that can be held in a stack.
    // -->
    registerTag("max_stack_size", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.getMaxStackSize()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.is_made_of[<material>]>
    // @returns Element(Boolean)
    // @description
    // Returns true if the material is a variety of the specified material.
    // Example: <m@red_wool.is_made_of[m@wool]> will return true.
    // -->
    registerTag("is_made_of", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dMaterial compared = dMaterial.valueOf(attribute.getContext(1));
            if (compared == null) {
                return Element.FALSE.getAttribute(attribute.fulfill(1));
            } else {
                return new Element(((dMaterial) object).material == compared.getMaterial()).getAttribute(attribute.fulfill(1));
            }
        }
    });
    // <--[tag]
    // @attribute <m@material.bukkit_enum>
    // @returns Element
    // @description
    // Returns the bukkit Material enum value. For example: <m@birch_sapling.bukkit_enum>
    // will return 'sapling'
    // -->
    registerTag("bukkit_enum", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).material.name()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.name>
    // @returns Element
    // @description
    // Returns the name of the material.
    // -->
    registerTag("name", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).forcedIdentity != null ? ((dMaterial) object).forcedIdentityLow : CoreUtilities.toLowerCase(((dMaterial) object).material.name())).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.full>
    // @returns Element
    // @description
    // Returns the material's full identification.
    // -->
    registerTag("full", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            if (((dMaterial) object).hasData()) {
                return new Element(((dMaterial) object).identifyFull()).getAttribute(attribute.fulfill(1));
            } else {
                return new Element(((dMaterial) object).identify()).getAttribute(attribute.fulfill(1));
            }
        }
    });
    // <--[tag]
    // @attribute <m@material.data>
    // @returns Element(Number)
    // @description
    // Returns the bukkit Material data value. For example: <m@red_clay.data>
    // will return '14'. Note: This kind of 'material identification' has been deprecated
    // by bukkit and should be used sparingly.
    // -->
    registerTag("data", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dMaterial) object).getData()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.item>
    // @returns dItem
    // @description
    // Returns an item of the material.
    // -->
    registerTag("item", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new dItem(((dMaterial) object), 1).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <m@material.type>
    // @returns Element
    // @description
    // Always returns 'Material' for dMaterial objects. All objects fetchable by the Object Fetcher will return the
    // type of object that is fulfilling this attribute.
    // -->
    registerTag("type", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element("Material").getAttribute(attribute.fulfill(1));
        }
    });
}
Also used : Attribute(net.aufdemrand.denizencore.tags.Attribute) TagRunnable(net.aufdemrand.denizencore.objects.TagRunnable) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) Element(net.aufdemrand.denizencore.objects.Element)

Aggregations

Attribute (net.aufdemrand.denizencore.tags.Attribute)14 Element (net.aufdemrand.denizencore.objects.Element)6 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)4 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)3 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)2 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 NPC (net.citizensnpcs.api.npc.NPC)2 File (java.io.File)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Pattern (java.util.regex.Pattern)1 FlagManager (net.aufdemrand.denizen.flags.FlagManager)1 BlockData (net.aufdemrand.denizen.nms.interfaces.BlockData)1 AssignmentTrait (net.aufdemrand.denizen.npc.traits.AssignmentTrait)1 ConstantsTrait (net.aufdemrand.denizen.npc.traits.ConstantsTrait)1 net.aufdemrand.denizen.objects.dCuboid (net.aufdemrand.denizen.objects.dCuboid)1