Search in sources :

Example 1 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemArmorStand method getDataMap.

public MapTag getDataMap() {
    ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
    if (meta == null) {
        return null;
    }
    MapTag result = new MapTag();
    result.putObject("base_plate", new ElementTag(!meta.hasNoBasePlate()));
    result.putObject("visible", new ElementTag(!meta.isInvisible()));
    result.putObject("marker", new ElementTag(meta.isMarker()));
    result.putObject("is_small", new ElementTag(meta.isSmall()));
    result.putObject("arms", new ElementTag(meta.shouldShowArms()));
    return result;
}
Also used : ArmorStandMeta(com.destroystokyo.paper.inventory.meta.ArmorStandMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 2 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemArmorStand method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("armor_stand_data") && mechanism.requireObject(MapTag.class)) {
        MapTag map = mechanism.valueAsType(MapTag.class);
        ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
        ObjectTag base_plate = map.getObject("base_plate");
        ObjectTag visible = map.getObject("visible");
        ObjectTag marker = map.getObject("marker");
        ObjectTag is_small = map.getObject("is_small");
        ObjectTag arms = map.getObject("arms");
        if (base_plate != null) {
            meta.setNoBasePlate(!((ElementTag) base_plate).asBoolean());
        }
        if (visible != null) {
            meta.setInvisible(!((ElementTag) visible).asBoolean());
        }
        if (marker != null) {
            meta.setMarker(((ElementTag) marker).asBoolean());
        }
        if (is_small != null) {
            meta.setSmall(((ElementTag) is_small).asBoolean());
        }
        if (arms != null) {
            meta.setShowArms(((ElementTag) arms).asBoolean());
        }
        item.setItemMeta(meta);
    }
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ArmorStandMeta(com.destroystokyo.paper.inventory.meta.ArmorStandMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 3 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerPreparesEnchantScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String determineLow = CoreUtilities.toLowerCase(determinationObj.toString());
        if (determineLow.startsWith("offers:")) {
            ListTag offers = ListTag.valueOf(determineLow.substring("offers:".length()), getTagContext(path));
            if (offers.size() != event.getOffers().length) {
                Debug.echoError("Offer list size incorrect.");
                return false;
            }
            for (int i = 0; i < offers.size(); i++) {
                MapTag map = MapTag.getMapFor(offers.getObject(i), getTagContext(path));
                event.getOffers()[i].setCost(map.getObject("cost").asElement().asInt());
                ObjectTag enchantment = map.getObject("enchantment_type");
                if (enchantment == null) {
                    enchantment = map.getObject("enchantment");
                }
                event.getOffers()[i].setEnchantment(enchantment.asType(EnchantmentTag.class, getTagContext(path)).enchantment);
                event.getOffers()[i].setEnchantmentLevel(map.getObject("level").asElement().asInt());
            }
            return true;
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 4 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerPreparesEnchantScriptEvent method getContext.

@Override
public ObjectTag getContext(String name) {
    switch(name) {
        case "item":
            return new ItemTag(event.getItem());
        case "location":
            return new LocationTag(event.getEnchantBlock().getLocation());
        case "bonus":
            return new ElementTag(event.getEnchantmentBonus());
        case "offers":
            ListTag output = new ListTag();
            for (EnchantmentOffer offer : event.getOffers()) {
                MapTag map = new MapTag();
                map.putObject("cost", new ElementTag(offer.getCost()));
                map.putObject("enchantment", new ElementTag(offer.getEnchantment().getKey().getKey()));
                map.putObject("enchantment_type", new EnchantmentTag(offer.getEnchantment()));
                map.putObject("level", new ElementTag(offer.getEnchantmentLevel()));
                output.addObject(map);
            }
            return output;
    }
    return super.getContext(name);
}
Also used : EnchantmentOffer(org.bukkit.enchantments.EnchantmentOffer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 5 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class LocationTag method parsePointsAroundArgs.

public static double[] parsePointsAroundArgs(Attribute attribute) {
    if (!attribute.hasParam()) {
        return null;
    }
    MapTag inputMap = attribute.paramAsType(MapTag.class);
    if (inputMap == null) {
        return null;
    }
    ObjectTag radiusObj = inputMap.getObject("radius");
    ObjectTag pointsObj = inputMap.getObject("points");
    if (radiusObj == null || pointsObj == null) {
        return null;
    }
    ElementTag radiusElement = radiusObj.asElement();
    ElementTag amountElement = pointsObj.asElement();
    if (radiusElement == null || amountElement == null) {
        return null;
    }
    double radius = radiusElement.asDouble();
    int amount = amountElement.asInt();
    if (amount < 1) {
        attribute.echoError("Invalid amount of points! There must be at least 1 point.");
        return null;
    }
    return new double[] { radius, amount };
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Aggregations

MapTag (com.denizenscript.denizencore.objects.core.MapTag)46 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)30 ListTag (com.denizenscript.denizencore.objects.core.ListTag)23 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)9 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)8 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ItemStack (org.bukkit.inventory.ItemStack)5 ColorTag (com.denizenscript.denizen.objects.ColorTag)4 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 Attributable (org.bukkit.attribute.Attributable)3 Attribute (org.bukkit.attribute.Attribute)3 AttributeInstance (org.bukkit.attribute.AttributeInstance)3 AttributeModifier (org.bukkit.attribute.AttributeModifier)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 FlaggableObject (com.denizenscript.denizencore.flags.FlaggableObject)2 Attribute (com.denizenscript.denizencore.tags.Attribute)2 ArmorStandMeta (com.destroystokyo.paper.inventory.meta.ArmorStandMeta)2 UUID (java.util.UUID)2