Search in sources :

Example 16 with Argument

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

the class BurnCommand method parseArgs.

// <--[command]
// @Name Burn
// @Syntax burn [<entity>|...] (duration:<value>)
// @Required 1
// @Maximum 2
// @Short Sets a list of entities on fire.
// @Synonyms Ignite,Fire,Torch
// @Group entity
// 
// @Description
// Burn will set a list of entities on fire.
// Just specify a list of entities (or a single entity) and optionally, a duration.
// Normal mobs and players will see damage afflicted, but NPCs will block damage from a burn unless 'vulnerable'.
// Since this command sets the total time of fire, it can also be used to cancel fire on a burning entity by specifying a duration of 0.
// Specifying no duration will result in a 5 second burn.
// 
// @Tags
// <EntityTag.fire_time>
// <EntityTag.on_fire>
// 
// @Usage
// Use to set an entity on fire.
// - burn <player> duration:10s
// 
// @Usage
// Use to cancel fire on entities.
// - burn <player.location.find.living_entities.within[10]> duration:0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    scriptEntry.defaultObject("duration", new DurationTag(5));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 17 with Argument

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

the class HurtCommand method parseArgs.

// <--[command]
// @Name Hurt
// @Syntax hurt (<#.#>) ({player}/<entity>|...) (cause:<cause>) (source:<entity>)
// @Required 0
// @Maximum 4
// @Short Hurts the player or a list of entities.
// @Synonyms Damage,Injure
// @Group entity
// 
// @Description
// Does damage to a list of entities, or to any single entity.
// 
// If no entities are specified: if there is a linked player, the command targets that. If there is no linked
// player but there is a linked NPC, the command targets the NPC. If neither is available, the command will error.
// 
// Does a specified amount of damage usually, but, if no damage is specified, does precisely 1HP worth of damage (half a heart).
// 
// Optionally, specify (source:<entity>) to make the system treat that entity as the attacker.
// 
// You may also specify a damage cause to fire a proper damage event with the given cause, only doing the damage if the event wasn't cancelled.
// Calculates the 'final damage' rather than using the raw damage input number. See <@link language damage cause> for damage causes.
// 
// Using a valid 'cause' value is best when trying to replicate natural damage, excluding it is best when trying to force the raw damage through.
// Note that using invalid or impossible causes may lead to bugs
// 
// @Tags
// <EntityTag.health>
// <EntityTag.last_damage.amount>
// <EntityTag.last_damage.cause>
// <EntityTag.last_damage.duration>
// <EntityTag.last_damage.max_duration>
// 
// @Usage
// Use to hurt the player for 1 HP.
// - hurt
// 
// @Usage
// Use to hurt the NPC for 5 HP.
// - hurt 5 <npc>
// 
// @Usage
// Use to cause the player to hurt the NPC for all its health (if unarmored).
// - hurt <npc.health> <npc> cause:CUSTOM source:<player>
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("amount") && (arg.matchesFloat() || arg.matchesInteger())) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (!scriptEntry.hasObject("source") && arg.matchesPrefix("source", "s") && arg.matchesArgumentType(EntityTag.class)) {
            scriptEntry.addObject("source", arg.asType(EntityTag.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("cause") && arg.matchesEnum(EntityDamageEvent.DamageCause.class)) {
            scriptEntry.addObject("cause", arg.asElement());
        } else if (!scriptEntry.hasObject("source_once") && arg.matches("source_once")) {
            Deprecations.hurtSourceOne.warn(scriptEntry);
            scriptEntry.addObject("source_once", new ElementTag(true));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new ElementTag(1.0d));
    }
    if (!scriptEntry.hasObject("entities")) {
        List<EntityTag> entities = new ArrayList<>();
        if (Utilities.getEntryPlayer(scriptEntry) != null) {
            entities.add(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity());
        } else if (Utilities.getEntryNPC(scriptEntry) != null) {
            entities.add(Utilities.getEntryNPC(scriptEntry).getDenizenEntity());
        } else {
            throw new InvalidArgumentsException("No valid target entities found.");
        }
        scriptEntry.addObject("entities", entities);
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ArrayList(java.util.ArrayList) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 18 with Argument

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

the class CooldownCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matchesPrefix("script", "s") && arg.matchesArgumentType(ScriptTag.class)) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (arg.matchesEnum(Type.class)) {
            scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("type", Type.PLAYER);
    scriptEntry.defaultObject("script", scriptEntry.getScript());
    if (!scriptEntry.hasObject("duration")) {
        throw new InvalidArgumentsException("Requires a valid duration!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 19 with Argument

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

the class StatisticCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_players = false;
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.class)) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("players", arg.asType(ListTag.class));
            specified_players = true;
        } else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.class)) {
            scriptEntry.addObject("statistic", arg.asElement());
        } else if (!scriptEntry.hasObject("amount") && arg.matchesInteger()) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
            if (arg.matchesArgumentType(MaterialTag.class)) {
                scriptEntry.addObject("material", arg.asType(MaterialTag.class));
            } else if (arg.matchesArgumentType(EntityTag.class)) {
                scriptEntry.addObject("entity", arg.asType(EntityTag.class));
            }
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a valid action!");
    }
    if (!scriptEntry.hasObject("statistic")) {
        throw new InvalidArgumentsException("Must specify a valid Statistic!");
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new ElementTag(1));
    }
    Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
    if (type != Statistic.Type.UNTYPED) {
        if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
            throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
        } else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
            throw new InvalidArgumentsException("Must specify a valid ENTITY!");
        }
    }
    if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry) && !specified_players) {
        scriptEntry.addObject("players", new ListTag(Utilities.getEntryPlayer(scriptEntry)));
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify valid players!");
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Argument(com.denizenscript.denizencore.objects.Argument) Statistic(org.bukkit.Statistic) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 20 with Argument

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

the class WeatherCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("type") && arg.matchesEnum(Type.class)) {
            scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));
        } else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
            scriptEntry.addObject("world", arg.asType(WorldTag.class));
        } else if (!scriptEntry.hasObject("value") && arg.matchesEnum(Value.class)) {
            scriptEntry.addObject("value", arg.asElement());
        } else if (!scriptEntry.hasObject("reset_after") && arg.matchesPrefix("reset") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("reset_after", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify a value!");
    }
    scriptEntry.defaultObject("type", Type.GLOBAL);
    scriptEntry.defaultObject("world", Utilities.entryDefaultWorld(scriptEntry, false));
}
Also used : WeatherType(org.bukkit.WeatherType) Argument(com.denizenscript.denizencore.objects.Argument) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Aggregations

Argument (com.denizenscript.denizencore.objects.Argument)35 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)30 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)23 EntityTag (com.denizenscript.denizen.objects.EntityTag)12 ListTag (com.denizenscript.denizencore.objects.core.ListTag)12 ItemTag (com.denizenscript.denizen.objects.ItemTag)8 LocationTag (com.denizenscript.denizen.objects.LocationTag)6 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)5 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)3 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 ArrayList (java.util.ArrayList)3 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)1 Map (java.util.Map)1 Effect (org.bukkit.Effect)1 Statistic (org.bukkit.Statistic)1 WeatherType (org.bukkit.WeatherType)1