Search in sources :

Example 71 with ElementTag

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

the class MaterialHalf method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.half>
    // @returns ElementTag
    // @mechanism MaterialTag.half
    // @group properties
    // @description
    // Returns the current half for a bisected material (like a door, double-plant, chest, or a bed).
    // Output for "Bisected" blocks (doors/double plants/...) is "BOTTOM" or "TOP".
    // Output for beds is "HEAD" or "FOOT".
    // Output for chests is "LEFT" or "RIGHT".
    // -->
    PropertyParser.<MaterialHalf, ElementTag>registerStaticTag(ElementTag.class, "half", (attribute, material) -> {
        String halfName = material.getHalfName();
        if (halfName == null) {
            return null;
        }
        return new ElementTag(halfName);
    });
    // <--[tag]
    // @attribute <MaterialTag.relative_vector>
    // @returns LocationTag
    // @mechanism MaterialTag.half
    // @group properties
    // @description
    // Returns a vector location of the other block for a bisected material.
    // -->
    PropertyParser.<MaterialHalf, LocationTag>registerStaticTag(LocationTag.class, "relative_vector", (attribute, material) -> {
        Vector vector = material.getRelativeBlockVector();
        if (vector == null) {
            return null;
        }
        return new LocationTag(vector);
    });
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Vector(org.bukkit.util.Vector)

Example 72 with ElementTag

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

the class ItemSpawnerDelay method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("spawner_spawn_delay")) {
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        return new ElementTag(state.getDelay()).getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("spawner_minimum_spawn_delay")) {
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        return new ElementTag(state.getMinSpawnDelay()).getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("spawner_maximum_spawn_delay")) {
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        return new ElementTag(state.getMaxSpawnDelay()).getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 73 with ElementTag

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

the class MaterialAge method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.maximum_age>
    // @returns ElementTag(Number)
    // @group properties
    // @description
    // Returns the maximum age for an ageable material. This includes plant growth.
    // -->
    PropertyParser.PropertyTagWithReturn<MaterialAge, ElementTag> runnable = (attribute, material) -> {
        return new ElementTag(material.getMax());
    };
    PropertyParser.registerStaticTag(ElementTag.class, "maximum_age", runnable);
    PropertyParser.registerStaticTag(ElementTag.class, "maximum_plant_growth", runnable);
    // <--[tag]
    // @attribute <MaterialTag.age>
    // @returns ElementTag(Number)
    // @mechanism MaterialTag.age
    // @group properties
    // @description
    // Returns the current age for an ageable material. This includes plant growth.
    // -->
    runnable = (attribute, material) -> {
        return new ElementTag(material.getCurrent());
    };
    PropertyParser.registerStaticTag(ElementTag.class, "age", runnable);
    PropertyParser.registerStaticTag(ElementTag.class, "plant_growth", runnable);
}
Also used : Ageable(org.bukkit.block.data.Ageable) Property(com.denizenscript.denizencore.objects.properties.Property) Sapling(org.bukkit.block.data.type.Sapling) TurtleEgg(org.bukkit.block.data.type.TurtleEgg) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) PropertyParser(com.denizenscript.denizencore.objects.properties.PropertyParser) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) PropertyParser(com.denizenscript.denizencore.objects.properties.PropertyParser)

Example 74 with ElementTag

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

the class RotateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) {
            scriptEntry.addObject("cancel", new ElementTag("true"));
        } else if (!scriptEntry.hasObject("infinite") && arg.matches("infinite")) {
            scriptEntry.addObject("infinite", new ElementTag("true"));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("frequency") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("frequency", "f")) {
            scriptEntry.addObject("frequency", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("yaw") && arg.matchesPrefix("yaw", "y", "rotation", "r") && arg.matchesFloat()) {
            scriptEntry.addObject("yaw", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch") && arg.matchesPrefix("pitch", "p", "tilt", "t") && arg.matchesFloat()) {
            scriptEntry.addObject("pitch", arg.asElement());
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    scriptEntry.defaultObject("yaw", new ElementTag(10));
    scriptEntry.defaultObject("pitch", new ElementTag(0));
    scriptEntry.defaultObject("duration", new DurationTag(20));
    scriptEntry.defaultObject("frequency", new DurationTag(1L));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 75 with ElementTag

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

the class RotateCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    final List<EntityTag> entities = new ArrayList<>((List<EntityTag>) scriptEntry.getObject("entities"));
    final DurationTag duration = scriptEntry.getObjectTag("duration");
    final DurationTag frequency = scriptEntry.getObjectTag("frequency");
    final ElementTag yaw = scriptEntry.getElement("yaw");
    final ElementTag pitch = scriptEntry.getElement("pitch");
    boolean cancel = scriptEntry.hasObject("cancel");
    final boolean infinite = scriptEntry.hasObject("infinite");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities), (infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
    }
    for (EntityTag entity : entities) {
        if (cancel) {
            rotatingEntities.remove(entity.getUUID());
        } else {
            rotatingEntities.add(entity.getUUID());
        }
    }
    if (cancel) {
        return;
    }
    BukkitRunnable task = new BukkitRunnable() {

        int ticks = 0;

        int maxTicks = duration.getTicksAsInt();

        ArrayList<EntityTag> unusedEntities = new ArrayList<>();

        @Override
        public void run() {
            if (entities.isEmpty()) {
                scriptEntry.setFinished(true);
                this.cancel();
            } else if (infinite || ticks < maxTicks) {
                for (EntityTag entity : entities) {
                    if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
                        NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), EntityHelper.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
                    } else {
                        rotatingEntities.remove(entity.getUUID());
                        unusedEntities.add(entity);
                    }
                }
                if (!unusedEntities.isEmpty()) {
                    for (EntityTag unusedEntity : unusedEntities) {
                        entities.remove(unusedEntity);
                    }
                    unusedEntities.clear();
                }
                ticks = (int) (ticks + frequency.getTicks());
            } else {
                scriptEntry.setFinished(true);
                this.cancel();
            }
        }
    };
    task.runTaskTimer(Denizen.getInstance(), 0, frequency.getTicks());
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12