Search in sources :

Example 46 with MapTag

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

the class CuboidBlockSet method pasteEntities.

public void pasteEntities(LocationTag relative) {
    if (entities == null) {
        return;
    }
    for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) {
        try {
            LocationTag offset = data.getObject("offset").asType(LocationTag.class, CoreUtilities.noDebugContext);
            int rotation = data.getObject("rotation").asElement().asInt();
            EntityTag entity = data.getObject("entity").asType(EntityTag.class, CoreUtilities.noDebugContext);
            if (entity == null || offset == null) {
                continue;
            }
            entity = entity.duplicate();
            offset = offset.clone();
            if (rotation != 0) {
                ArrayList<Mechanism> mechs = new ArrayList<>(entity.getWaitingMechanisms().size());
                for (Mechanism mech : entity.getWaitingMechanisms()) {
                    if (mech.getName().equals("rotation")) {
                        String rotationName = mech.getValue().asString();
                        BlockFace face = BlockFace.valueOf(rotationName.toUpperCase());
                        for (int i = 0; i < rotation; i += 90) {
                            face = rotateFaceOne(face);
                        }
                        // Compensate for hanging locations being very stupid
                        offset.add(face.getDirection().multiply(0.1));
                        mechs.add(new Mechanism("rotation", new ElementTag(face.name()), CoreUtilities.noDebugContext));
                    } else {
                        mechs.add(new Mechanism(mech.getName(), mech.value, CoreUtilities.noDebugContext));
                    }
                }
                entity.mechanisms = mechs;
            } else {
                for (Mechanism mechanism : entity.mechanisms) {
                    mechanism.context = CoreUtilities.noDebugContext;
                }
            }
            Location spawnLoc = relative.clone().add(offset);
            spawnLoc.setYaw(offset.getYaw() - rotation);
            spawnLoc.setPitch(offset.getPitch());
            entity.spawnAt(spawnLoc);
        } catch (Exception ex) {
            Debug.echoError(ex);
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) Location(org.bukkit.Location)

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