use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class SwitchCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("no_physics") && arg.matches("no_physics")) {
scriptEntry.addObject("no_physics", new ElementTag(true));
} else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
scriptEntry.addObject("locations", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.class)) {
scriptEntry.addObject("switchstate", new ElementTag(arg.getValue().toUpperCase()));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify a location!");
}
scriptEntry.defaultObject("duration", new DurationTag(0));
scriptEntry.defaultObject("switchstate", new ElementTag("TOGGLE"));
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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));
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
Deprecations.giveTakeMoney.warn(scriptEntry);
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp")) {
scriptEntry.addObject("type", Type.XP);
} else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
scriptEntry.addObject("type", Type.ITEMINHAND);
} else if (!scriptEntry.hasObject("type") && arg.matches("cursoritem", "cursor_item")) {
scriptEntry.addObject("type", Type.CURSORITEM);
} else if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesFloat()) {
if (arg.matchesPrefix("q", "qty")) {
Deprecations.qtyTags.warn(scriptEntry);
}
scriptEntry.addObject("quantity", arg.asElement());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.BYDISPLAY);
scriptEntry.addObject("displayname", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("nbt") && !scriptEntry.hasObject("type")) {
Deprecations.itemNbt.warn(scriptEntry);
scriptEntry.addObject("type", Type.NBT);
scriptEntry.addObject("nbt_key", arg.asElement());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("flagged") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.FLAGGED);
scriptEntry.addObject("flag_name", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
scriptEntry.addObject("type", Type.BYCOVER);
scriptEntry.addObject("cover", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("item")) {
scriptEntry.addObject("type", Type.MATCHER);
scriptEntry.addObject("matcher_text", arg.asElement());
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("material")) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("type", Type.MATERIAL);
scriptEntry.addObject("material", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("script", "scriptname")) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("type", Type.SCRIPTNAME);
scriptEntry.addObject("scriptitem", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("raw_exact")) {
scriptEntry.addObject("type", Type.RAWEXACT);
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot")) {
scriptEntry.addObject("type", Type.SLOT);
scriptEntry.addObject("slot", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(ItemTag.class)) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(InventoryTag.class)) {
scriptEntry.addObject("inventory", arg.asType(InventoryTag.class));
} else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
Deprecations.takeCommandInventory.warn(scriptEntry);
scriptEntry.addObject("type", Type.INVENTORY);
} else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
Deprecations.takeCommandInventory.warn(scriptEntry);
scriptEntry.addObject("inventory", Utilities.getEntryNPC(scriptEntry).getDenizenEntity().getInventory());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("quantity", new ElementTag(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to take from!");
}
if (requiresPlayerTypes.contains(type) && !Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Cannot take '" + type.name() + "' without a linked player.");
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class RemoveCommand method parseArgs.
// <--[command]
// @Name Remove
// @Syntax remove [<entity>|...] (world:<world>)
// @Required 1
// @Maximum 2
// @Short Despawns an entity or list of entities, permanently removing any NPCs.
// @Group entity
// @Description
// Removes the selected entity. May also take a list of entities to remove.
//
// Any NPC removed this way is completely removed, as if by '/npc remove'.
// For temporary NPC removal, see <@link command despawn>.
//
// If a generic entity name is given (like 'zombie'), this will remove all entities of that type from the given world.
// Optionally, you may specify a world to target.
// (Defaults to the world of the player running the command)
//
// @Tags
// <EntityTag.is_spawned>
//
// @Usage
// Use to remove the entity the player is looking at.
// - remove <player.target>
//
// @Usage
// Use to remove all nearby entities around the player, excluding the player itself.
// - remove <player.location.find_entities.within[10].exclude[<player>]>
//
// @Usage
// Use to remove all dropped items in the world called cookies.
// - remove dropped_item world:cookies
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
EntityTag.allowDespawnedNpcs = true;
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
EntityTag.allowDespawnedNpcs = false;
} else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
scriptEntry.addObject("world", arg.asType(WorldTag.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
scriptEntry.defaultObject("world", Utilities.entryDefaultWorld(scriptEntry, false));
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class SpawnCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
EntityTag.allowDespawnedNpcs = true;
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
EntityTag.allowDespawnedNpcs = false;
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("target") && arg.matchesArgumentType(EntityTag.class) && arg.matchesPrefix("target")) {
scriptEntry.addObject("target", arg.asType(EntityTag.class));
} else if (!scriptEntry.hasObject("spread") && arg.matchesInteger()) {
scriptEntry.addObject("spread", arg.asElement());
} else if (!scriptEntry.hasObject("persistent") && arg.matches("persistent")) {
scriptEntry.addObject("persistent", "");
} else {
arg.reportUnhandled();
}
}
// Use the NPC or player's locations as the location if one is not specified
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Must specify a location!");
}
}
Aggregations