use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class GiveCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
/* Match arguments to expected variables */
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("qty", arg.asElement());
scriptEntry.addObject("set_quantity", new Element(true));
} else if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp", "experience")) {
scriptEntry.addObject("type", Type.EXP);
} else if (!scriptEntry.hasObject("engrave") && arg.matches("engrave")) {
scriptEntry.addObject("engrave", new Element(true));
} else if (!scriptEntry.hasObject("unlimit_stack_size") && arg.matches("unlimit_stack_size")) {
scriptEntry.addObject("unlimit_stack_size", new Element(true));
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.startsWith("item:") ? arg.raw_value.substring("item:".length()) : arg.raw_value).filter(dItem.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("t", "to") && arg.matchesArgumentType(dInventory.class)) {
scriptEntry.addObject("inventory", arg.asType(dInventory.class));
} else if (!scriptEntry.hasObject("slot") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("slot", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("engrave", new Element(false)).defaultObject("unlimit_stack_size", new Element(false)).defaultObject("qty", new Element(1)).defaultObject("slot", new Element(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to give to!");
}
if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
throw new InvalidArgumentsException("Must specify item/items!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class PushCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
if (arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("originEntity", arg.asType(dEntity.class));
} else if (arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("originLocation", arg.asType(dLocation.class));
} else {
dB.echoError("Ignoring unrecognized argument: " + arg.raw_value);
}
} else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("destination", "d")) {
scriptEntry.addObject("destination", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("duration", "d")) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("speed", "s")) {
scriptEntry.addObject("speed", arg.asElement());
} else if (!scriptEntry.hasObject("script") && (arg.matchesArgumentType(dScript.class) || arg.matchesPrefix("script"))) {
scriptEntry.addObject("script", arg.asType(dScript.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else if (!scriptEntry.hasObject("force_along") && arg.matches("force_along")) {
scriptEntry.addObject("force_along", new Element(true));
} else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
scriptEntry.addObject("no_rotate", new Element(true));
} else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
scriptEntry.addObject("precision", arg.asElement());
} else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
scriptEntry.addObject("no_damage", new Element(true));
} else if (arg.matchesPrefix("def", "define", "context")) {
scriptEntry.addObject("definitions", arg.asType(dList.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("originLocation")) {
scriptEntry.defaultObject("originEntity", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity() : null);
}
scriptEntry.defaultObject("speed", new Element(1.5));
scriptEntry.defaultObject("duration", new Duration(20));
scriptEntry.defaultObject("force_along", new Element(false));
scriptEntry.defaultObject("precision", new Element(2));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("originEntity") && !scriptEntry.hasObject("originLocation")) {
throw new InvalidArgumentsException("Must specify an origin location!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class FlagCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_target = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
// specified amount of time
if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(Duration.class)) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else // Also allow attached dObjects to be specified...
if (!scriptEntry.hasObject("flag_target") && arg.matches("npc", "denizen")) {
specified_target = true;
scriptEntry.addObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC());
} else if (!scriptEntry.hasObject("flag_target") && arg.matches("global", "server")) {
specified_target = true;
scriptEntry.addObject("flag_target", Element.SERVER);
} else if (!scriptEntry.hasObject("flag_target") && arg.matches("player")) {
specified_target = true;
scriptEntry.addObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
} else // as the name of the flag..
if (!scriptEntry.hasObject("flag_target") && arg.startsWith("n@") && !arg.hasPrefix()) {
if (// TODO: Optimize
dNPC.valueOf(arg.getValue()) == null) {
throw new InvalidArgumentsException("Invalid NPC target.");
}
specified_target = true;
scriptEntry.addObject("flag_target", arg.asType(dNPC.class));
} else if (!scriptEntry.hasObject("flag_target") && arg.startsWith("p@") && !arg.hasPrefix()) {
if (// TODO: Optimize
dPlayer.valueOf(arg.getValue()) == null) {
throw new InvalidArgumentsException("Invalid Player target.");
}
specified_target = true;
scriptEntry.addObject("flag_target", arg.asType(dPlayer.class));
} else if (!scriptEntry.hasObject("flag_target") && !arg.hasPrefix()) {
if (// TODO: Optimize
dEntity.valueOf(arg.getValue()) == null) {
throw new InvalidArgumentsException("Invalid Entity target.");
}
specified_target = true;
scriptEntry.addObject("flag_target", arg.asType(dEntity.class));
} else // Check if setting a boolean
if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 1) {
scriptEntry.addObject("action", FlagManager.Action.SET_BOOLEAN);
scriptEntry.addObject("value", Element.TRUE);
scriptEntry.addObject("flag_name", arg.asElement());
} else // Check for flag_name:value/action
if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 2) {
String[] flagArgs = arg.raw_value.split(":", 2);
scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
scriptEntry.addObject("action", FlagManager.Action.INCREASE);
scriptEntry.addObject("value", new Element(1));
} else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
scriptEntry.addObject("action", FlagManager.Action.DECREASE);
scriptEntry.addObject("value", new Element(1));
} else if (flagArgs[1].equals("!")) {
scriptEntry.addObject("action", FlagManager.Action.DELETE);
scriptEntry.addObject("value", Element.FALSE);
} else if (flagArgs[1].equals("<-")) {
scriptEntry.addObject("action", FlagManager.Action.REMOVE);
scriptEntry.addObject("value", Element.FALSE);
} else {
// No ACTION, we're just setting a value...
scriptEntry.addObject("action", FlagManager.Action.SET_VALUE);
scriptEntry.addObject("value", new Element(flagArgs[1]));
}
} else // Check for flag_name:action:value
if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 3) {
String[] flagArgs = arg.raw_value.split(":", 3);
scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
if (flagArgs[1].equals("->")) {
scriptEntry.addObject("action", FlagManager.Action.INSERT);
} else if (flagArgs[1].equals("<-")) {
scriptEntry.addObject("action", FlagManager.Action.REMOVE);
} else if (flagArgs[1].equals("||") || flagArgs[1].equals("|")) {
scriptEntry.addObject("action", FlagManager.Action.SPLIT);
} else if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
scriptEntry.addObject("action", FlagManager.Action.INCREASE);
} else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
scriptEntry.addObject("action", FlagManager.Action.DECREASE);
} else if (flagArgs[1].equals("**") || flagArgs[1].equals("*")) {
scriptEntry.addObject("action", FlagManager.Action.MULTIPLY);
} else if (flagArgs[1].equals("//") || flagArgs[1].equals("/")) {
scriptEntry.addObject("action", FlagManager.Action.DIVIDE);
} else {
scriptEntry.addObject("action", FlagManager.Action.SET_VALUE);
scriptEntry.addObject("value", new Element(arg.raw_value.split(":", 2)[1]));
continue;
}
scriptEntry.addObject("value", new Element(flagArgs[2]));
} else {
arg.reportUnhandled();
}
}
// Set defaults
if (!specified_target) {
scriptEntry.defaultObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
}
// Check required arguments
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify a flag action or value.");
}
if (!scriptEntry.hasObject("flag_target")) {
throw new InvalidArgumentsException("Must specify a flag target!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class TeamCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
String name = null;
String prefix = null;
String suffix = null;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matchesPrefix("id") && !scriptEntry.hasObject("id")) {
scriptEntry.addObject("id", arg.asElement());
} else if (arg.matchesPrefix("name") && !scriptEntry.hasObject("name")) {
Element nameElement = arg.asElement();
name = nameElement.asString();
scriptEntry.addObject("name", nameElement);
} else if (arg.matchesPrefix("add") && !scriptEntry.hasObject("add")) {
scriptEntry.addObject("add", arg.asType(dList.class));
} else if (arg.matchesPrefix("remove") && !scriptEntry.hasObject("remove")) {
scriptEntry.addObject("remove", arg.asType(dList.class));
} else if (arg.matchesPrefix("prefix") && !scriptEntry.hasObject("prefix")) {
Element prefixElement = arg.asElement();
prefix = prefixElement.asString();
scriptEntry.addObject("prefix", prefixElement);
} else if (arg.matchesPrefix("suffix") && !scriptEntry.hasObject("suffix")) {
Element suffixElement = arg.asElement();
suffix = suffixElement.asString();
scriptEntry.addObject("suffix", suffixElement);
}
}
if (name == null || name.length() == 0 || name.length() > 16) {
throw new InvalidArgumentsException("Must specify a team name between 1 and 16 characters!");
}
if (!scriptEntry.hasObject("add") && !scriptEntry.hasObject("remove") && !scriptEntry.hasObject("prefix") && !scriptEntry.hasObject("suffix")) {
throw new InvalidArgumentsException("Must specify something to do with the team!");
}
if ((prefix != null && prefix.length() > 16) || (suffix != null && suffix.length() > 16)) {
throw new InvalidArgumentsException("Prefixes and suffixes must be 16 characters or less!");
}
scriptEntry.defaultObject("id", new Element("main"));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class PlaySoundCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
} else if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dPlayer.class));
} else if (!scriptEntry.hasObject("volume") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("volume, v")) {
scriptEntry.addObject("volume", arg.asElement());
} else if (!scriptEntry.hasObject("pitch") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("pitch, p")) {
scriptEntry.addObject("pitch", arg.asElement());
} else if (!scriptEntry.hasObject("sound") && arg.matchesPrimitive(aH.PrimitiveType.String)) {
scriptEntry.addObject("sound", arg.asElement());
} else if (!scriptEntry.hasObject("custom") && arg.matches("custom")) {
scriptEntry.addObject("custom", Element.TRUE);
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("sound")) {
throw new InvalidArgumentsException("Missing sound argument!");
}
if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Missing location argument!");
}
scriptEntry.defaultObject("volume", new Element(1));
scriptEntry.defaultObject("pitch", new Element(1));
scriptEntry.defaultObject("custom", Element.FALSE);
}
Aggregations