use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class SwitchCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("locations", arg.asType(dList.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) {
scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase()));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify a location!");
}
scriptEntry.defaultObject("duration", new Duration(0));
scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class StatisticCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_players = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
} else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("players", arg.asType(dList.class));
specified_players = true;
} else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.values())) {
scriptEntry.addObject("statistic", arg.asElement());
} else if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("amount", arg.asElement());
} else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
if (arg.matchesArgumentType(dMaterial.class)) {
scriptEntry.addObject("material", arg.asType(dMaterial.class));
} else if (arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("entity", arg.asType(dEntity.class));
}
}
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify a valid action!");
}
if (!scriptEntry.hasObject("statistic")) {
throw new InvalidArgumentsException("Must specify a valid Statistic!");
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(1));
}
Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
if (type != Statistic.Type.UNTYPED) {
if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
} else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
throw new InvalidArgumentsException("Must specify a valid ENTITY!");
}
}
if (!scriptEntry.hasObject("players") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_players) {
scriptEntry.addObject("players", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
}
if (!scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must specify valid players!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class YamlCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean isSet = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesPrefix("LOAD")) {
scriptEntry.addObject("action", new Element("LOAD"));
scriptEntry.addObject("filename", arg.asElement());
} else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("SAVEFILE", "FILESAVE")) {
scriptEntry.addObject("action", new Element("SAVE"));
scriptEntry.addObject("filename", arg.asElement());
} else if (!scriptEntry.hasObject("action") && arg.matches("CREATE")) {
scriptEntry.addObject("action", new Element("CREATE"));
} else if (!scriptEntry.hasObject("action") && arg.matches("SET")) {
scriptEntry.addObject("action", new Element("SET"));
isSet = true;
} else if (!scriptEntry.hasObject("action") && arg.matches("UNLOAD")) {
scriptEntry.addObject("action", new Element("UNLOAD"));
} else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("WRITE")) {
dB.echoError(scriptEntry.getResidingQueue(), "YAML write is deprecated, use YAML set!");
scriptEntry.addObject("action", new Element("WRITE"));
scriptEntry.addObject("key", arg.asElement());
} else if (!scriptEntry.hasObject("value") && arg.matchesPrefix("VALUE")) {
if (arg.matchesArgumentType(dList.class)) {
scriptEntry.addObject("value", arg.asType(dList.class));
} else {
scriptEntry.addObject("value", arg.asElement());
}
} else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("ID")) {
scriptEntry.addObject("id", arg.asElement());
} else if (!scriptEntry.hasObject("split") && arg.matches("split_list")) {
scriptEntry.addObject("split", new Element("true"));
} else if (!scriptEntry.hasObject("fix_formatting") && arg.matches("fix_formatting")) {
scriptEntry.addObject("fix_formatting", new Element("true"));
} else // Check for key:value/action
if (isSet && !scriptEntry.hasObject("value") && arg.raw_value.split(":", 3).length == 2) {
String[] flagArgs = arg.raw_value.split(":", 2);
scriptEntry.addObject("key", new Element(flagArgs[0]));
if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
scriptEntry.addObject("yaml_action", YAML_Action.INCREASE);
scriptEntry.addObject("value", new Element(1));
} else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
scriptEntry.addObject("yaml_action", YAML_Action.DECREASE);
scriptEntry.addObject("value", new Element(1));
} else if (flagArgs[1].equals("!")) {
scriptEntry.addObject("yaml_action", YAML_Action.DELETE);
scriptEntry.addObject("value", Element.FALSE);
} else if (flagArgs[1].equals("<-")) {
scriptEntry.addObject("yaml_action", YAML_Action.REMOVE);
scriptEntry.addObject("value", Element.FALSE);
} else {
// No ACTION, we're just setting a value...
scriptEntry.addObject("yaml_action", YAML_Action.SET_VALUE);
scriptEntry.addObject("value", new Element(flagArgs[1]));
}
} else // Check for key:action:value
if (isSet && !scriptEntry.hasObject("value") && arg.raw_value.split(":", 3).length == 3) {
String[] flagArgs = arg.raw_value.split(":", 3);
scriptEntry.addObject("key", new Element(flagArgs[0]));
if (flagArgs[1].equals("->")) {
scriptEntry.addObject("yaml_action", YAML_Action.INSERT);
} else if (flagArgs[1].equals("<-")) {
scriptEntry.addObject("yaml_action", YAML_Action.REMOVE);
} else if (flagArgs[1].equals("||") || flagArgs[1].equals("|")) {
scriptEntry.addObject("yaml_action", YAML_Action.SPLIT);
} else if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
scriptEntry.addObject("yaml_action", YAML_Action.INCREASE);
} else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
scriptEntry.addObject("yaml_action", YAML_Action.DECREASE);
} else if (flagArgs[1].equals("**") || flagArgs[1].equals("*")) {
scriptEntry.addObject("yaml_action", YAML_Action.MULTIPLY);
} else if (flagArgs[1].equals("//") || flagArgs[1].equals("/")) {
scriptEntry.addObject("yaml_action", YAML_Action.DIVIDE);
} else {
scriptEntry.addObject("yaml_action", YAML_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();
}
}
if (!scriptEntry.hasObject("id")) {
throw new InvalidArgumentsException("Must specify an id!");
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify an action!");
}
if (!scriptEntry.hasObject("key") && scriptEntry.getElement("action").asString().equalsIgnoreCase("write")) {
throw new InvalidArgumentsException("Must specify a key!");
}
scriptEntry.defaultObject("value", new Element(""));
scriptEntry.defaultObject("fix_formatting", new Element("false"));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class CastCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("remove") && arg.matches("remove", "cancel")) {
scriptEntry.addObject("remove", new Element(true));
} else if (!scriptEntry.hasObject("ambient") && arg.matches("no_ambient")) {
scriptEntry.addObject("ambient", new Element(false));
} else if (!scriptEntry.hasObject("show_particles") && arg.matches("hide_particles")) {
scriptEntry.addObject("show_particles", new Element(false));
} else if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(Duration.class)) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("amplifier") && arg.matchesPrefix("power", "p", "amplifier", "a") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("amplifier", arg.asElement());
} else if (!scriptEntry.hasObject("effect") && PotionEffectType.getByName(arg.asElement().asString()) != null) {
scriptEntry.addObject("effect", PotionEffectType.getByName(arg.asElement().asString()));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else {
arg.reportUnhandled();
}
}
// No targets specified, let's use defaults if available
scriptEntry.defaultObject("entities", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity()) : null), (((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity()) : null));
// No potion specified? Problem!
if (!scriptEntry.hasObject("effect")) {
throw new InvalidArgumentsException("Must specify a valid PotionType!");
}
scriptEntry.defaultObject("duration", new Duration(60));
scriptEntry.defaultObject("amplifier", new Element(1));
scriptEntry.defaultObject("remove", new Element(false));
scriptEntry.defaultObject("show_particles", new Element(true));
scriptEntry.defaultObject("ambient", new Element(true));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) {
scriptEntry.addObject("cancel", new Element("true"));
} else if (!scriptEntry.hasObject("infinite") && arg.matches("infinite")) {
scriptEntry.addObject("infinite", new Element("true"));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("duration", "d")) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("frequency") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("frequency", "f")) {
scriptEntry.addObject("frequency", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("yaw") && arg.matchesPrefix("yaw", "y", "rotation", "r") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
scriptEntry.addObject("yaw", arg.asElement());
} else if (!scriptEntry.hasObject("pitch") && arg.matchesPrefix("pitch", "p", "tilt", "t") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
scriptEntry.addObject("pitch", arg.asElement());
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else {
arg.reportUnhandled();
}
}
// Use the NPC or the Player as the default entity
scriptEntry.defaultObject("entities", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity()) : null), (((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity()) : null));
scriptEntry.defaultObject("yaw", new Element(10));
scriptEntry.defaultObject("pitch", new Element(0));
scriptEntry.defaultObject("duration", new Duration(20));
scriptEntry.defaultObject("frequency", Duration.valueOf("1t"));
// Check to make sure required arguments have been filled
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
}
Aggregations