Search in sources :

Example 1 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag 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 2 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag 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 3 with ListTag

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

the class PlayerReceivesCommandsScriptEvent method getContext.

@Override
public ObjectTag getContext(String name) {
    if (name.equals("commands")) {
        ListTag list = new ListTag();
        list.addAll(event.getCommands());
        return list;
    }
    return super.getContext(name);
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 4 with ListTag

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

the class LootGenerateScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String determination = determinationObj.toString();
        String determinationLower = CoreUtilities.toLowerCase(determination);
        if (determinationLower.startsWith("loot:")) {
            ListTag list = ListTag.valueOf(determination.substring("loot:".length()), getTagContext(path));
            ArrayList<ItemStack> newLoot = new ArrayList<>(list.size());
            for (ItemTag item : list.filter(ItemTag.class, getTagContext(path))) {
                newLoot.add(item.getItemStack());
            }
            event.setLoot(newLoot);
            return true;
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : ArrayList(java.util.ArrayList) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 5 with ListTag

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

the class AreaContainmentObject method getBlocksFlagged.

default ListTag getBlocksFlagged(String flagName, Attribute attribute) {
    CuboidTag cuboid = getCuboidBoundary();
    ListTag blocks = new ListTag();
    for (CuboidTag.LocationPair pair : cuboid.pairs) {
        ChunkTag minChunk = new ChunkTag(pair.low);
        ChunkTag maxChunk = new ChunkTag(pair.high);
        ChunkTag subChunk = new ChunkTag(pair.low);
        for (int x = minChunk.getX(); x <= maxChunk.getX(); x++) {
            subChunk.chunkX = x;
            for (int z = minChunk.getZ(); z <= maxChunk.getZ(); z++) {
                subChunk.chunkZ = z;
                subChunk.cachedChunk = null;
                if (subChunk.isLoadedSafe()) {
                    LocationFlagSearchHelper.getFlaggedLocations(subChunk.getChunkForTag(attribute), flagName, (loc) -> {
                        if (doesContainLocation(loc)) {
                            blocks.addObject(new LocationTag(loc));
                        }
                    });
                }
            }
        }
    }
    return blocks;
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

ListTag (com.denizenscript.denizencore.objects.core.ListTag)122 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)71 MapTag (com.denizenscript.denizencore.objects.core.MapTag)21 ItemStack (org.bukkit.inventory.ItemStack)18 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)14 List (java.util.List)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)13 Player (org.bukkit.entity.Player)13 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)12 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)9 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 ArrayList (java.util.ArrayList)9 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)7 NPC (net.citizensnpcs.api.npc.NPC)7 Entity (org.bukkit.entity.Entity)7