Search in sources :

Example 16 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class DebugBlockCommand method parseArgs.

// <--[command]
// @Name DebugBlock
// @Syntax debugblock [<location>|.../clear] (color:<color>) (alpha:<#.#>) (name:<name>) (players:<player>|...) (d:<duration>{10s})
// @Required 1
// @Maximum 6
// @Short Shows or clears minecraft debug blocks.
// @Synonyms GameTestMarker
// @Group player
// 
// @Description
// Shows or clears minecraft debug blocks, AKA "Game Test Markers".
// These are block-grid-aligned markers that are a perfect cube of a single (specifiable) transparent color, and stay for a specified duration of time or until cleared.
// Markers can optionally also have simple text names.
// 
// If arguments are unspecified, the default color is white (in practice: green), the default alpha is 1.0 (most opaque, but not completely opaque),
// the default player is the linked player, the default name is none, and the default duration is 10 seconds.
// 
// The underlying color input is a full color value, however the current minecraft client can only render shades between green and gray (ie the red and blue color channels are ignored).
// 
// @Tags
// None
// 
// @Usage
// Use to show a debug block where the player is looking.
// - debugblock <player.cursor_on>
// 
// @Usage
// Use to show a transparent green debug block in front of the player for five seconds.
// - debugblock <player.eye_location.forward[2]> color:green alpha:0.5 d:5s
// 
// @Usage
// Use to remove all debug blocks,
// - debugblock clear
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
            scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (arg.matchesPrefix("color") && arg.matchesArgumentType(ColorTag.class)) {
            scriptEntry.addObject("color", arg.asType(ColorTag.class));
        } else if (arg.matchesPrefix("alpha") && arg.matchesFloat()) {
            scriptEntry.addObject("alpha", arg.asElement());
        } else if (arg.matchesPrefix("name")) {
            scriptEntry.addObject("name", arg.asElement());
        } else if (arg.matches("clear")) {
            scriptEntry.addObject("clear", new ElementTag(true));
        } else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
        scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
    }
    if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("clear")) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(10));
    scriptEntry.defaultObject("color", new ColorTag(255, 255, 255));
    scriptEntry.defaultObject("alpha", new ElementTag("1"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 17 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class NBTCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("key") && arg.getRawValue().split(":", 2).length == 2) {
            String[] flagArgs = arg.getRawValue().split(":", 2);
            scriptEntry.addObject("key", new ElementTag(flagArgs[0]));
            scriptEntry.addObject("value", new ElementTag(flagArgs[1]));
        } else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(ItemTag.class)) {
            scriptEntry.addObject("item", arg.asType(ItemTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("item")) {
        throw new InvalidArgumentsException("Must specify item!");
    }
    if (!scriptEntry.hasObject("key") || !scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify key and value!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 18 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class ZapCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("script") && !scriptEntry.hasObject("step") && arg.hasPrefix() && arg.getPrefix().matchesArgumentType(ScriptTag.class)) {
            Deprecations.zapPrefix.warn(scriptEntry);
            scriptEntry.addObject("script", arg.getPrefix().asType(ScriptTag.class));
            scriptEntry.addObject("step", arg.asElement());
        } else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof InteractScriptContainer && arg.limitToOnlyPrefix("script")) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (!scriptEntry.hasObject("step") && arg.limitToOnlyPrefix("step")) {
            scriptEntry.addObject("step", arg.asElement());
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.limitToOnlyPrefix("duration")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    if (player == null || !player.isValid()) {
        throw new InvalidArgumentsException("Must have player context!");
    }
    if (!scriptEntry.hasObject("script")) {
        ScriptTag script = scriptEntry.getScript();
        if (script != null) {
            if (script.getContainer() instanceof InteractScriptContainer) {
                scriptEntry.addObject("script", script);
            } else if (script.getContainer() instanceof AssignmentScriptContainer) {
                InteractScriptContainer interact = ((AssignmentScriptContainer) script.getContainer()).interact;
                if (interact != null) {
                    scriptEntry.addObject("script", new ScriptTag(interact));
                }
            }
        }
        if (!scriptEntry.hasObject("script")) {
            NPCTag npc = Utilities.getEntryNPC(scriptEntry);
            if (npc != null && npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                for (AssignmentScriptContainer container : trait.containerCache) {
                    if (container != null && container.getInteract() != null) {
                        scriptEntry.addObject("script", new ScriptTag(container.getInteract()));
                        break;
                    }
                }
            }
        }
        if (!scriptEntry.hasObject("script")) {
            throw new InvalidArgumentsException("No script to zap! Must be in an interact script, or have a linked NPC with an associated interact script.");
        }
    }
}
Also used : AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) InteractScriptContainer(com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 19 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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 20 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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)

Aggregations

InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)41 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)31 Argument (com.denizenscript.denizencore.objects.Argument)30 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)14 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)11 ItemTag (com.denizenscript.denizen.objects.ItemTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)3 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 ArrayList (java.util.ArrayList)2 ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)1 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 WorldTag (com.denizenscript.denizen.objects.WorldTag)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)1