Search in sources :

Example 6 with DurationTag

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

the class PushCommand method parseArgs.

// <--[command]
// @Name Push
// @Syntax push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (duration:<duration>) (script:<name>) (def:<element>|...) (force_along) (precision:<#>) (no_rotate) (no_damage) (ignore_collision)
// @Required 1
// @Maximum 12
// @Short Pushes entities through the air in a straight line.
// @Group entity
// 
// @Description
// Pushes entities through the air in a straight line at a certain speed and for a certain duration,
// triggering a script when they hit an obstacle or stop flying.
// 
// You must specify an entity to be pushed.
// 
// Usually, you should specify the origin and the destination. If unspecified, they will be assumed from contextual data.
// 
// You can specify the script to be run with the (script:<name>) argument,
// and optionally specify definitions to be available in this script with the (def:<element>|...) argument.
// 
// Using the 'no_damage' argument causes the entity to receive no damage when they stop moving.
// 
// Optionally use the "ignore_collision" argument to ignore block collisions.
// 
// Optionally use "speed:#" to set how fast it should be pushed.
// 
// Optionally use "force_along" to cause the entity to teleport through any blockage.
// 
// Optionally use "no_rotate" to prevent entities being rotated at the start of the push.
// 
// Optionally use "duration:#" to set the max length of time to continue pushing.
// 
// The push command is ~waitable. Refer to <@link language ~waitable>.
// 
// @Tags
// <EntityTag.velocity>
// <entry[saveName].pushed_entities> returns the list of pushed entities.
// 
// @Usage
// Use to launch an arrow straight towards a target.
// - push arrow destination:<player.location>
// 
// @Usage
// Use to launch an entity into the air.
// - push cow
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
            if (arg.matchesArgumentType(EntityTag.class)) {
                scriptEntry.addObject("origin_entity", arg.asType(EntityTag.class));
            } else if (arg.matchesArgumentType(LocationTag.class)) {
                scriptEntry.addObject("origin_location", arg.asType(LocationTag.class));
            } else {
                Debug.echoError("Ignoring unrecognized argument: " + arg.getRawValue());
            }
        } else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("destination", "d")) {
            scriptEntry.addObject("destination", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("speed") && arg.matchesFloat() && arg.matchesPrefix("speed", "s")) {
            scriptEntry.addObject("speed", arg.asElement());
        } else if (!scriptEntry.hasObject("script") && ((arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof TaskScriptContainer) || arg.matchesPrefix("script"))) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("force_along") && arg.matches("force_along")) {
            scriptEntry.addObject("force_along", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
            scriptEntry.addObject("no_rotate", new ElementTag(true));
        } else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
            scriptEntry.addObject("precision", arg.asElement());
        } else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
            scriptEntry.addObject("no_damage", new ElementTag(true));
        } else if (!scriptEntry.hasObject("ignore_collision") && arg.matches("ignore_collision")) {
            scriptEntry.addObject("ignore_collision", new ElementTag(true));
        } else if (arg.matchesPrefix("def", "define", "context")) {
            scriptEntry.addObject("definitions", arg.asType(ListTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("origin_location")) {
        scriptEntry.defaultObject("origin_entity", Utilities.entryDefaultEntity(scriptEntry, false));
    }
    scriptEntry.defaultObject("speed", new ElementTag(1.5));
    scriptEntry.defaultObject("duration", new DurationTag(20));
    scriptEntry.defaultObject("force_along", new ElementTag(false));
    scriptEntry.defaultObject("precision", new ElementTag(2));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("origin_entity") && !scriptEntry.hasObject("origin_location")) {
        throw new InvalidArgumentsException("Must specify an origin location!");
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 7 with DurationTag

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

the class CastCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("remove") && arg.matches("remove", "cancel")) {
            scriptEntry.addObject("remove", new ElementTag(true));
        } else if (!scriptEntry.hasObject("ambient") && arg.matches("no_ambient")) {
            scriptEntry.addObject("ambient", new ElementTag(false));
        } else if (!scriptEntry.hasObject("show_particles") && arg.matches("hide_particles")) {
            scriptEntry.addObject("show_particles", new ElementTag(false));
        } else if (!scriptEntry.hasObject("show_icon") && arg.matches("no_icon")) {
            scriptEntry.addObject("show_icon", new ElementTag(false));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("amplifier") && arg.matchesPrefix("power", "p", "amplifier", "a") && arg.matchesFloat()) {
            scriptEntry.addObject("amplifier", arg.asElement());
        } else if (!scriptEntry.hasObject("effect") && PotionEffectType.getByName(arg.asElement().asString()) != null) {
            scriptEntry.addObject("effect", PotionEffectType.getByName(arg.asElement().asString()));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    }
    if (!scriptEntry.hasObject("effect")) {
        throw new InvalidArgumentsException("Must specify a valid PotionType!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(60));
    scriptEntry.defaultObject("amplifier", new ElementTag(1));
    scriptEntry.defaultObject("remove", new ElementTag(false));
    scriptEntry.defaultObject("show_particles", new ElementTag(true));
    scriptEntry.defaultObject("ambient", new ElementTag(true));
    scriptEntry.defaultObject("show_icon", new ElementTag(true));
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 8 with DurationTag

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

the class FakeEquipCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NetworkInterceptHelper.enable();
    EquipmentOverride equipment = (EquipmentOverride) scriptEntry.getObject("equipment");
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    List<PlayerTag> playersFor = (List<PlayerTag>) scriptEntry.getObject("for");
    ElementTag reset = scriptEntry.getElement("reset");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("entities", entities), db("equipment", equipment), reset, duration, db("for", playersFor));
    }
    boolean isReset = reset != null && reset.asBoolean();
    for (PlayerTag player : playersFor) {
        HashMap<UUID, EquipmentOverride> playersMap = overrides.computeIfAbsent(player.getUUID(), (k) -> new HashMap<>());
        for (EntityTag entity : entities) {
            if (entity.isGeneric()) {
                Debug.echoError(scriptEntry, "Cannot equip generic entity " + entity.identify() + "!");
                continue;
            }
            LivingEntity livingEntity = entity.getLivingEntity();
            if (livingEntity == null) {
                Debug.echoError(scriptEntry, "Cannot equip invalid/non-living entity " + entity.identify() + "!");
                continue;
            }
            EquipmentOverride entityData;
            if (isReset) {
                entityData = playersMap.remove(entity.getUUID());
                if (playersMap.isEmpty()) {
                    overrides.remove(player.getUUID());
                }
            } else {
                entityData = playersMap.computeIfAbsent(entity.getUUID(), (k) -> new EquipmentOverride());
                entityData.copyFrom(equipment);
            }
            if (entityData != null) {
                if (entityData.cancelTask != null && !entityData.cancelTask.isCancelled()) {
                    entityData.cancelTask.cancel();
                    entityData.cancelTask = null;
                }
                if (duration != null && duration.getTicks() > 0) {
                    entityData.cancelTask = new BukkitRunnable() {

                        @Override
                        public void run() {
                            entityData.cancelTask = null;
                            HashMap<UUID, EquipmentOverride> playersMap = overrides.get(player.getUUID());
                            if (playersMap != null) {
                                if (playersMap.remove(entity.getUUID()) != null) {
                                    if (playersMap.isEmpty()) {
                                        overrides.remove(player.getUUID());
                                    }
                                    NMSHandler.getPacketHelper().resetEquipment(player.getPlayerEntity(), livingEntity);
                                }
                            }
                        }
                    }.runTaskLater(Denizen.getInstance(), duration.getTicks());
                }
            }
            NMSHandler.getPacketHelper().resetEquipment(player.getPlayerEntity(), livingEntity);
        }
    }
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag) NetworkInterceptHelper(com.denizenscript.denizen.utilities.packets.NetworkInterceptHelper) Utilities(com.denizenscript.denizen.utilities.Utilities) java.util(java.util) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) NMSHandler(com.denizenscript.denizen.nms.NMSHandler) ItemTag(com.denizenscript.denizen.objects.ItemTag) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) LivingEntity(org.bukkit.entity.LivingEntity) Argument(com.denizenscript.denizencore.objects.Argument) Denizen(com.denizenscript.denizen.Denizen) BukkitTask(org.bukkit.scheduler.BukkitTask) EntityTag(com.denizenscript.denizen.objects.EntityTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) Debug(com.denizenscript.denizen.utilities.debugging.Debug) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) LivingEntity(org.bukkit.entity.LivingEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 9 with DurationTag

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

the class ResetCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    // We allow players to be a single player or multiple players
    ObjectTag player = scriptEntry.getObjectTag("players");
    ListTag players;
    if (player instanceof PlayerTag) {
        players = new ListTag(player);
    } else {
        players = scriptEntry.getObjectTag("players");
    }
    Type type = (Type) scriptEntry.getObject("type");
    ScriptTag script = scriptEntry.getObjectTag("script");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), players, db("type", type), script);
    }
    // Deal with GLOBAL_COOLDOWN reset first, since there's no player/players involved
    if (type == Type.GLOBAL_COOLDOWN) {
        CooldownCommand.setCooldown(null, new DurationTag(0), script.getName(), true);
        return;
    }
    // Now deal with the rest
    for (String object : players) {
        PlayerTag resettable = PlayerTag.valueOf(object, scriptEntry.context);
        if (resettable.isValid()) {
            switch(type) {
                case PLAYER_COOLDOWN:
                    CooldownCommand.setCooldown(resettable, new DurationTag(0), script.getName(), false);
                    return;
            }
        }
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 10 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag 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)

Aggregations

DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)54 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)39 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)16 ListTag (com.denizenscript.denizencore.objects.core.ListTag)16 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)13 List (java.util.List)11 Player (org.bukkit.entity.Player)7 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)6 ColorTag (com.denizenscript.denizen.objects.ColorTag)5 PotionEffect (org.bukkit.potion.PotionEffect)5 PotionEffectType (org.bukkit.potion.PotionEffectType)5 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 NPCTag (com.denizenscript.denizen.objects.NPCTag)4 WorldTag (com.denizenscript.denizen.objects.WorldTag)4 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)4 LivingEntity (org.bukkit.entity.LivingEntity)4 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3