use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class SidebarCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Action action = Action.SET;
for (aH.Argument arg : aH.interpret(scriptEntry.getOriginalArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
action = Action.valueOf(arg.getValue().toUpperCase());
} else if (!scriptEntry.hasObject("title") && arg.matchesPrefix("title", "t", "objective", "obj", "o")) {
scriptEntry.addObject("title", arg.asElement());
} else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "line", "l")) {
scriptEntry.addObject("lines", arg.asElement());
} else if (!scriptEntry.hasObject("value") && arg.matchesPrefix("value", "values", "val", "v")) {
scriptEntry.addObject("value", arg.asElement());
} else if (!scriptEntry.hasObject("increment") && arg.matchesPrefix("increment", "inc", "i")) {
scriptEntry.addObject("increment", arg.asElement());
} else if (!scriptEntry.hasObject("start") && arg.matchesPrefix("start", "s")) {
scriptEntry.addObject("start", arg.asElement());
} else if (!scriptEntry.hasObject("players") && arg.matchesPrefix("players", "player", "p")) {
scriptEntry.addObject("players", arg.asElement());
} else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
scriptEntry.addObject("per_player", new Element(true));
}
}
if (action == Action.ADD && !scriptEntry.hasObject("value")) {
throw new InvalidArgumentsException("Must specify value(s) for that action!");
}
if (action == Action.SET && !scriptEntry.hasObject("value") && !scriptEntry.hasObject("title") && !scriptEntry.hasObject("increment") && !scriptEntry.hasObject("start")) {
throw new InvalidArgumentsException("Must specify at least one of: value(s), title, increment, or start for that action!");
}
if (action == Action.SET && scriptEntry.hasObject("lines") && !scriptEntry.hasObject("value")) {
throw new InvalidArgumentsException("Must specify value(s) when setting lines!");
}
scriptEntry.addObject("action", new Element(action.name()));
BukkitScriptEntryData entryData = (BukkitScriptEntryData) scriptEntry.entryData;
scriptEntry.defaultObject("per_player", new Element(false)).defaultObject("players", new Element(entryData.hasPlayer() ? entryData.getPlayer().identify() : "li@"));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class PoseCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Parse Arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matches("add", "assume", "remove")) {
scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
} else if (arg.matchesPrefix("id")) {
scriptEntry.addObject("pose_id", arg.getValue());
} else if (arg.matches("player")) {
scriptEntry.addObject("target", TargetType.PLAYER);
} else if (arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("pose_loc", arg.asType(dLocation.class));
}
}
// Even if the target is a player, this command requires an NPC to get the pose from.
if (!((BukkitScriptEntryData) scriptEntry.entryData).hasNPC()) {
throw new InvalidArgumentsException("This command requires an NPC!");
}
// It also requires a pose ID
if (!scriptEntry.hasObject("pose_id")) {
throw new InvalidArgumentsException("No ID specified!");
}
// Set default objects
scriptEntry.defaultObject("target", TargetType.NPC);
scriptEntry.defaultObject("action", Action.ASSUME);
// from players, so only allow ASSUME.
if (scriptEntry.getObject("target") == TargetType.PLAYER) {
if (scriptEntry.getObject("action") != Action.ASSUME) {
throw new InvalidArgumentsException("You cannot add or remove poses from a player.");
} else if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
throw new InvalidArgumentsException("This command requires a linked player!");
}
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class AnnounceCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// let's check if there are more argument than usual.
if (scriptEntry.getArguments().size() > 3) {
throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
}
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
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("format") && arg.matchesPrefix("format")) {
FormatScriptContainer format = null;
String formatStr = arg.getValue();
format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
dB.echoError("Could not find format script matching '" + formatStr + '\'');
}
scriptEntry.addObject("format", format);
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new Element(arg.raw_value));
}
}
// If text is missing, alert the console.
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing text argument!");
}
scriptEntry.defaultObject("type", AnnounceType.ALL);
}
Aggregations