Search in sources :

Example 21 with MapTag

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

the class ItemArmorPose method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("armor_pose")) {
        CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
        Tag entPart, posePart;
        if (mechanism.hasValue() && mechanism.requireObject(MapTag.class)) {
            if (compoundTag == null) {
                compoundTag = new CompoundTagBuilder().build();
            }
            entPart = compoundTag.getValue().get("EntityTag");
            if (!(entPart instanceof CompoundTag)) {
                entPart = new CompoundTagBuilder().build();
            }
            CompoundTagBuilder poseBuilder = new CompoundTagBuilder();
            MapTag input = mechanism.valueAsType(MapTag.class);
            procMechKey(mechanism, poseBuilder, "Head", "head", input);
            procMechKey(mechanism, poseBuilder, "Body", "body", input);
            procMechKey(mechanism, poseBuilder, "LeftArm", "left_arm", input);
            procMechKey(mechanism, poseBuilder, "RightArm", "right_arm", input);
            procMechKey(mechanism, poseBuilder, "LeftLeg", "left_leg", input);
            procMechKey(mechanism, poseBuilder, "RightLeg", "right_leg", input);
            CompoundTag pose = poseBuilder.build();
            if (pose.getValue().isEmpty()) {
                entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build();
            } else {
                entPart = ((CompoundTag) entPart).createBuilder().put("Pose", pose).build();
            }
        } else {
            if (compoundTag == null) {
                return;
            }
            entPart = compoundTag.getValue().get("EntityTag");
            if (!(entPart instanceof CompoundTag)) {
                return;
            }
            posePart = ((CompoundTag) entPart).getValue().get("Pose");
            if (!(posePart instanceof CompoundTag)) {
                return;
            }
            entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build();
        }
        if (((CompoundTag) entPart).getValue().isEmpty()) {
            compoundTag = compoundTag.createBuilder().remove("EntityTag").build();
        } else {
            compoundTag = compoundTag.createBuilder().put("EntityTag", entPart).build();
        }
        ItemStack result = NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag);
        item.setItemStack(result);
    }
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 22 with MapTag

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

the class ItemArmorPose method getPoseMap.

public MapTag getPoseMap() {
    CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
    if (compoundTag == null) {
        return null;
    }
    Tag entPart = compoundTag.getValue().get("EntityTag");
    if (!(entPart instanceof CompoundTag)) {
        return null;
    }
    Tag posePart = ((CompoundTag) entPart).getValue().get("Pose");
    if (!(posePart instanceof CompoundTag)) {
        return null;
    }
    CompoundTag pose = (CompoundTag) posePart;
    MapTag result = new MapTag();
    procPart(pose, "Head", "head", result);
    procPart(pose, "Body", "body", result);
    procPart(pose, "LeftArm", "left_arm", result);
    procPart(pose, "RightArm", "right_arm", result);
    procPart(pose, "LeftLeg", "left_leg", result);
    procPart(pose, "RightLeg", "right_leg", result);
    return result;
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 23 with MapTag

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

the class EntityPotionEffects method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("potion_effects")) {
        for (ObjectTag effectObj : CoreUtilities.objectToList(mechanism.value, mechanism.context)) {
            PotionEffect effect;
            if (effectObj.canBeType(MapTag.class)) {
                MapTag effectMap = effectObj.asType(MapTag.class, mechanism.context);
                effect = ItemPotion.parseEffect(effectMap, mechanism.context);
            } else {
                String effectStr = effectObj.toString();
                effect = ItemPotion.parseEffect(effectStr, mechanism.context);
            }
            if (effect == null) {
                mechanism.echoError("Invalid potion effect '" + effectObj + "'");
                continue;
            }
            if (entity.isLivingEntity()) {
                entity.getLivingEntity().addPotionEffect(effect);
            } else if (isArrow()) {
                getArrow().addCustomEffect(effect, true);
            }
        }
    }
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) PotionEffect(org.bukkit.potion.PotionEffect) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 24 with MapTag

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

the class Conversion method getInventory.

public static AbstractMap.SimpleEntry<Integer, InventoryTag> getInventory(Argument arg, TagContext context) {
    boolean isElement = arg.object instanceof ElementTag;
    if (arg.object instanceof InventoryTag || (isElement && InventoryTag.matches(arg.getValue()))) {
        InventoryTag inv = arg.object instanceof InventoryTag ? (InventoryTag) arg.object : InventoryTag.valueOf(arg.getValue(), context);
        if (inv != null) {
            return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
        }
    } else if (arg.object instanceof MapTag || (isElement && arg.getValue().startsWith("map@"))) {
        MapTag map = arg.object instanceof MapTag ? (MapTag) arg.object : MapTag.valueOf(arg.getValue(), context);
        int maxSlot = 0;
        for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
            if (!ArgumentHelper.matchesInteger(entry.getKey().str)) {
                return null;
            }
            int slot = new ElementTag(entry.getKey().str).asInt();
            if (slot > maxSlot) {
                maxSlot = slot;
            }
        }
        InventoryTag inventory = new InventoryTag(Math.min(InventoryTag.maxSlots, (maxSlot / 9) * 9 + 9));
        for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
            int slot = new ElementTag(entry.getKey().str).asInt();
            ItemTag item = ItemTag.getItemFor(entry.getValue(), context);
            if (item == null) {
                if (context == null || context.debug) {
                    Debug.echoError("Not a valid item: '" + entry.getValue() + "'");
                }
                continue;
            }
            inventory.getInventory().setItem(slot - 1, item.getItemStack());
        }
        return new AbstractMap.SimpleEntry<>(maxSlot, inventory);
    } else if (arg.object instanceof LocationTag || (isElement && LocationTag.matches(arg.getValue()))) {
        InventoryTag inv = (arg.object instanceof LocationTag ? (LocationTag) arg.object : LocationTag.valueOf(arg.getValue(), context)).getInventory();
        if (inv != null) {
            return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
        }
    } else if (arg.object instanceof EntityTag || arg.object instanceof PlayerTag || arg.object instanceof NPCTag || (isElement && EntityTag.matches(arg.getValue()))) {
        InventoryTag inv = EntityTag.valueOf(arg.getValue(), context).getInventory();
        if (inv != null) {
            return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
        }
    }
    ListTag asList = ListTag.getListFor(arg.object, context);
    if (asList.containsObjectsFrom(ItemTag.class)) {
        List<ItemTag> list = asList.filter(ItemTag.class, context);
        ItemStack[] items = convertItems(list).toArray(new ItemStack[list.size()]);
        InventoryTag inventory = new InventoryTag(Math.min(InventoryTag.maxSlots, (items.length / 9) * 9 + 9));
        inventory.setContents(items);
        return new AbstractMap.SimpleEntry<>(items.length, inventory);
    }
    return null;
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) AbstractMap(java.util.AbstractMap) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack)

Example 25 with MapTag

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

the class CuboidBlockSet method buildEntities.

public void buildEntities(CuboidTag cuboid, Location center) {
    entities = new ListTag();
    for (Entity ent : cuboid.getWorld().getEntities()) {
        if (cuboid.isInsideCuboid(ent.getLocation())) {
            if (copyTypes.contains(ent.getType())) {
                EntityTag entTag = new EntityTag(ent);
                if (entTag.isPlayer() || entTag.isNPC()) {
                    continue;
                }
                MapTag data = new MapTag();
                data.putObject("entity", entTag.describe(null));
                data.putObject("rotation", new ElementTag(0));
                Vector offset = ent.getLocation().toVector().subtract(center.toVector());
                data.putObject("offset", new LocationTag((String) null, offset.getX(), offset.getY(), offset.getZ(), ent.getLocation().getYaw(), ent.getLocation().getPitch()));
                entities.addObject(data);
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) Vector(org.bukkit.util.Vector) 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