use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("type") && arg.matches("random")) {
scriptEntry.addObject("type", new ElementTag(FireworkEffect.Type.values()[CoreUtilities.getRandom().nextInt(FireworkEffect.Type.values().length)].name()));
} else if (!scriptEntry.hasObject("type") && arg.matchesEnum(FireworkEffect.Type.class)) {
scriptEntry.addObject("type", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location!");
}
scriptEntry.defaultObject("type", new ElementTag("ball"));
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class AnnounceCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("type") && arg.matches("to_ops")) {
scriptEntry.addObject("type", AnnounceType.TO_OPS);
} else if (!scriptEntry.hasObject("type") && arg.matches("to_console")) {
scriptEntry.addObject("type", AnnounceType.TO_CONSOLE);
} else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_flagged")) {
scriptEntry.addObject("type", AnnounceType.TO_FLAGGED);
scriptEntry.addObject("flag", arg.asElement());
} else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_permission")) {
scriptEntry.addObject("type", AnnounceType.TO_PERMISSION);
scriptEntry.addObject("flag", arg.asElement());
} else if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format")) {
FormatScriptContainer format;
String formatStr = arg.getValue();
format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
Debug.echoError("Could not find format script matching '" + formatStr + '\'');
}
scriptEntry.addObject("format", format);
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", arg.getRawElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing text argument!");
}
scriptEntry.defaultObject("type", AnnounceType.ALL);
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ScoreboardCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.class)) {
scriptEntry.addObject("action", arg.asElement());
} else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "l")) {
scriptEntry.addObject("lines", arg.asElement());
} else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id")) {
scriptEntry.addObject("id", arg.asElement());
} else if (!scriptEntry.hasObject("objective") && arg.matchesPrefix("objective", "obj", "o")) {
scriptEntry.addObject("objective", arg.asElement());
} else if (!scriptEntry.hasObject("criteria") && arg.matchesPrefix("criteria", "c")) {
scriptEntry.addObject("criteria", arg.asElement());
} else if (!scriptEntry.hasObject("score") && arg.matchesInteger()) {
scriptEntry.addObject("score", arg.asElement());
} else if (!scriptEntry.hasObject("displayslot") && (arg.matchesEnum(DisplaySlot.class) || arg.matches("none"))) {
scriptEntry.addObject("displayslot", arg.asElement());
} else if (!scriptEntry.hasObject("displayslot") && arg.matchesPrefix("displayname")) {
scriptEntry.addObject("displayname", arg.asElement());
} else if (!scriptEntry.hasObject("rendertype") && arg.matchesPrefix("rendertype") && arg.matchesEnum(RenderType.class)) {
scriptEntry.addObject("rendertype", arg.asElement());
} else if (!scriptEntry.hasObject("viewers") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("viewers", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("action", new ElementTag("add"));
scriptEntry.defaultObject("id", new ElementTag("main"));
}
use of com.denizenscript.denizencore.objects.Argument 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"));
}
use of com.denizenscript.denizencore.objects.Argument 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!");
}
}
Aggregations