use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ChatCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
boolean specified_talker = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
// Default target is the attached Player, if none specified otherwise.
if (arg.matchesPrefix("target", "targets", "t")) {
if (arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("targets", arg.asType(dList.class));
}
specified_targets = true;
} else if (arg.matches("no_target")) {
scriptEntry.addObject("targets", new dList());
} else // Default talker is the attached NPC, if none specified otherwise.
if (arg.matchesPrefix("talker", "talkers")) {
if (arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("talkers", arg.asType(dList.class));
}
specified_talker = true;
} else if (arg.matchesPrefix("range", "r")) {
if (arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("range", arg.asElement());
}
} else if (!scriptEntry.hasObject("message")) {
scriptEntry.addObject("message", new Element(arg.raw_value));
} else {
arg.reportUnhandled();
}
}
// Add default recipient as the attached Player if no recipients set otherwise
if (!scriptEntry.hasObject("targets") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_targets) {
scriptEntry.defaultObject("targets", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
}
// Add default talker as the attached NPC if no recipients set otherwise
if (!scriptEntry.hasObject("talkers") && ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() && !specified_talker) {
scriptEntry.defaultObject("talkers", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().identify()));
}
// Verify essential fields are set
if (!scriptEntry.hasObject("targets")) {
throw new InvalidArgumentsException("Must specify valid targets!");
}
if (!scriptEntry.hasObject("talkers")) {
throw new InvalidArgumentsException("Must specify valid talkers!");
}
if (!scriptEntry.hasObject("message")) {
throw new InvalidArgumentsException("Must specify a message!");
}
scriptEntry.defaultObject("range", new Element(Settings.chatBystandersRange()));
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ListenCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
List<aH.Argument> arguments = new ArrayList<aH.Argument>();
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
// <action>
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
} else // <id:name>
if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id", "i")) {
scriptEntry.addObject("id", arg.asElement());
} else // <script>
if (!scriptEntry.hasObject("finish_script") && arg.matchesPrefix("script") && arg.matchesArgumentType(dScript.class)) {
scriptEntry.addObject("finish_script", arg.asType(dScript.class));
} else // <type>
if (!scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", arg.asElement());
}
arguments.add(arg);
}
// Set defaults
scriptEntry.defaultObject("action", new Element("new"));
scriptEntry.defaultObject("id", new Element(UUID.randomUUID().toString()));
// Check for type (if using NEW) -- it's required
if (!scriptEntry.hasObject("type") && scriptEntry.getElement("action").asString().equalsIgnoreCase("new")) {
throw new InvalidArgumentsException("Must specify a listener type!");
}
// Player listeners require a player!
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() == null) {
throw new InvalidArgumentsException("Must specify a player!");
}
// Add arguments
scriptEntry.addObject("args", arguments);
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ExplodeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("power") && arg.matchesPrimitive(aH.PrimitiveType.Float) && arg.matchesPrefix("power", "p")) {
scriptEntry.addObject("power", arg.asElement());
} else if (!scriptEntry.hasObject("breakblocks") && arg.matches("breakblocks")) {
scriptEntry.addObject("breakblocks", "");
} else if (!scriptEntry.hasObject("fire") && arg.matches("fire")) {
scriptEntry.addObject("fire", "");
} else {
arg.reportUnhandled();
}
}
// Use default values if necessary
scriptEntry.defaultObject("power", new Element(1.0));
scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null);
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
if (scriptEntry.getArguments().size() > 4) {
// TODO: Use this more often!
throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
}
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
String formatStr = arg.getValue();
FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
dB.echoError("Could not find format script matching '" + formatStr + '\'');
}
scriptEntry.addObject("format", format);
} else // Add players to target list
if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
} else // Use raw_value as to not accidentally strip a value before any :'s.
if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
} else {
arg.reportUnhandled();
}
}
// to the targets
if (!scriptEntry.hasObject("targets")) {
scriptEntry.addObject("targets", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) : null));
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing any text!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ShowFakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
dList locations = new dList();
dList entities = new dList();
boolean added_entities = false;
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matchesPrefix("to", "players")) {
for (String entity : dList.valueOf(arg.getValue())) {
if (dPlayer.matches(entity)) {
entities.add(entity);
}
}
// TODO: handle lists properly
added_entities = true;
} else if (arg.matchesArgumentList(dMaterial.class)) {
scriptEntry.addObject("materials", arg.asType(dList.class));
} else if (locations.isEmpty() && arg.matchesArgumentType(dList.class)) {
for (String item : dList.valueOf(arg.getValue())) {
if (dLocation.matches(item)) {
locations.add(item);
}
}
} else if (locations.isEmpty() && arg.matchesArgumentType(dLocation.class)) {
locations.add(arg.getValue());
} else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(Duration.class)) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (arg.matches("cancel")) {
scriptEntry.addObject("cancel", new Element(true));
} else {
arg.reportUnhandled();
}
}
if (entities.isEmpty() && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify());
}
if (locations.isEmpty()) {
throw new InvalidArgumentsException("Must specify at least one valid location!");
}
if (!added_entities && (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() || !((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline())) {
throw new InvalidArgumentsException("Must have a valid, online player attached!");
}
if (entities.isEmpty() && added_entities) {
throw new InvalidArgumentsException("Must specify valid targets!");
}
if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
throw new InvalidArgumentsException("Must specify valid material(s)!");
}
scriptEntry.addObject("entities", entities);
scriptEntry.addObject("locations", locations);
scriptEntry.defaultObject("duration", new Duration(10)).defaultObject("cancel", new Element(false));
}
Aggregations