Search in sources :

Example 41 with InvalidArgumentsException

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

the class NarrateCommand method parseArgs.

// <--[command]
// @Name Narrate
// @Syntax narrate [<text>] (targets:<player>|...) (format:<script>) (per_player) (from:<uuid>)
// @Required 1
// @Maximum 5
// @Short Shows some text to the player.
// @Group player
// 
// @Description
// Prints some text into the target's chat area. If no target is specified it will default to the attached player or the console.
// 
// Accepts the 'format:<script>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
// 
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- narrate 'hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
// 
// Optionally, specify 'from:<uuid>' to indicate that message came from a specific UUID (used for things like the vanilla client social interaction block option).
// 
// @Tags
// None
// 
// @Usage
// Use to narrate text to the player.
// - narrate "Hello World!"
// 
// @Usage
// Use to narrate text to a list of players.
// - narrate "Hello there." targets:<[player]>|<[someplayer]>|<[thatplayer]>
// 
// @Usage
// Use to narrate text to a unique message to every player on the server.
// - narrate "Hello <player.name>, your secret code is <util.random.duuid>." targets:<server.online_players> per_player
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + "'");
            }
            scriptEntry.addObject("format", new ScriptTag(format));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
            scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("from") && arg.matchesPrefix("from")) {
            scriptEntry.addObject("from", TagManager.tagObject(arg.getValue(), scriptEntry.getContext()));
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new ElementTag(true));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("targets")) {
        scriptEntry.addObject("targets", (Utilities.entryHasPlayer(scriptEntry) ? Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)) : null));
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing any text!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) 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