Skip to content

Commit

Permalink
Add InvalidArgumentsException to some commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Sep 25, 2013
1 parent 05caaff commit f2dec7f
Show file tree
Hide file tree
Showing 38 changed files with 144 additions and 112 deletions.
Expand Up @@ -81,8 +81,8 @@ else if (!scriptEntry.hasObject("id") &&
arg.matchesPrefix("ID")) {
scriptEntry.addObject("id", arg.asElement());
}
else
dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Check for required arguments
Expand Down
Expand Up @@ -78,6 +78,8 @@ else if (!scriptEntry.hasObject("step"))
else if (!scriptEntry.hasObject("duration")
&& arg.matchesArgumentType(Duration.class))
scriptEntry.addObject("duration", arg.asType(Duration.class));

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Add default script if none was specified.
Expand Down
Expand Up @@ -54,6 +54,8 @@ else if (!scriptEntry.hasObject("lock")

scriptEntry.addObject("lock", "");
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Check to make sure required arguments have been filled
Expand Down
Expand Up @@ -48,20 +48,19 @@ else if (!scriptEntry.hasObject("entities")
// Entity dList arg
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the player as the target if one is not specified

scriptEntry.defaultObject("target",
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getDenizenEntity() : null);

// Use the NPC as the attacking entity if one is not specified

scriptEntry.defaultObject("entities",
scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null);

// Check to make sure required arguments have been filled

if (!scriptEntry.hasObject("entities"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");

Expand Down
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.scripts.commands.entity;

import java.util.Arrays;
import java.util.List;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
Expand Down Expand Up @@ -37,15 +38,16 @@ else if (!scriptEntry.hasObject("duration")

scriptEntry.addObject("duration", arg.asType(Duration.class));
}
}

// Check to make sure required arguments have been filled
else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

if (!scriptEntry.hasObject("entities"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");
// Use the NPC or the Player as the default entity
scriptEntry.defaultObject("entities",
(scriptEntry.hasPlayer() ? Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()) : null),
(scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null));

// Use default duration if one is not specified

scriptEntry.defaultObject("duration", Duration.valueOf("5s"));
}

Expand Down
Expand Up @@ -98,6 +98,8 @@ else if (!scriptEntry.hasObject("entities")

}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);

}

// No targets specified, let's use defaults if available
Expand Down
Expand Up @@ -84,6 +84,8 @@ else if (!scriptEntry.hasObject("speed")

scriptEntry.addObject("speed", arg.asElement());
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player's locations as the location if one is not specified
Expand Down
Expand Up @@ -45,19 +45,13 @@ else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(dEntity.class))
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));

else
dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or the Player as the default entity
if (!scriptEntry.hasObject("entities")) {
if (scriptEntry.hasNPC())
scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getNPC().getDenizenEntity()));
else if (scriptEntry.hasPlayer())
scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()));
else
throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "ENTITIES");
}
scriptEntry.defaultObject("entities",
(scriptEntry.hasPlayer() ? Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()) : null),
(scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null));

if (!scriptEntry.hasObject("skin"))
throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "SKIN");
Expand All @@ -73,7 +67,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Report to dB
dB.report(getName(),
aH.debugObj("entities", entities.toString()) +
skin.debug());
skin.debug());

// Create head item with chosen skin
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
Expand All @@ -92,7 +86,7 @@ else if (entity.isPlayer()) {
entity.getPlayer().getInventory().setHelmet(item);
}
else {
dB.echoError("No players or NPCs have been specified!");
dB.report(getName(), entity.debug() + " is not a player or an NPC!");
}
}
}
Expand Down
Expand Up @@ -42,6 +42,8 @@ else if (!scriptEntry.hasObject("entities")
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

if (!scriptEntry.hasObject("amount"))
Expand Down
Expand Up @@ -25,12 +25,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
throw new InvalidArgumentsException(dB.Messages.ERROR_NO_PLAYER);
scriptEntry.addObject("target", arg.asElement());
}
if (!scriptEntry.hasObject("qty")

else if (!scriptEntry.hasObject("qty")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer))
scriptEntry.addObject("qty", arg.asElement());
if (!scriptEntry.hasObject("action")

else if (!scriptEntry.hasObject("action")
&& arg.matchesPrefix("state"))
scriptEntry.addObject("action", arg.asElement());

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}


Expand Down
Expand Up @@ -43,6 +43,8 @@ else if (!scriptEntry.hasObject("entities")
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

if (!scriptEntry.hasObject("amount"))
Expand Down
Expand Up @@ -31,30 +31,28 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("cancel")
&& arg.matches("cancel, stop")) {
&& arg.matches("cancel, stop")) {
scriptEntry.addObject("cancel", "");
}

else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(dEntity.class)) {
&& arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else if (!scriptEntry.hasObject("holder")
&& arg.matchesArgumentType(dEntity.class)
&& arg.matchesPrefix("holder, h")) {
scriptEntry.addObject("holder", arg.asType(dEntity.class));
}
&& arg.matchesPrefix("holder, h")) {

else if (!scriptEntry.hasObject("holder")
&& arg.matchesArgumentType(dLocation.class)
&& arg.matchesPrefix("holder, h")) {
if (arg.matchesArgumentType(dEntity.class))
scriptEntry.addObject("holder", arg.asType(dEntity.class));
else if (arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("holder", arg.asType(dLocation.class));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Check to make sure required arguments have been filled

if (!scriptEntry.hasObject("entities"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");

Expand Down
Expand Up @@ -43,6 +43,8 @@ else if (!scriptEntry.hasObject("entities")
// Entity arg
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player as the entity if no entities are specified
Expand Down
Expand Up @@ -48,6 +48,8 @@ else if (!scriptEntry.hasObject("entities")
// Entity arg
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player's locations as the location if one is not specified
Expand Down
Expand Up @@ -86,8 +86,7 @@ else if (!scriptEntry.hasObject("entities")
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else
dB.echoError("Ignoring unrecognized argument: " + arg.raw_value);
else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player's locations as the origin if one is not specified
Expand Down
Expand Up @@ -48,6 +48,8 @@ else if (!scriptEntry.hasObject("world")

scriptEntry.addObject("world", arg.asType(dWorld.class));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Check to make sure required arguments have been filled
Expand Down
Expand Up @@ -82,8 +82,7 @@ else if (!scriptEntry.hasObject("entities")
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else
dB.echoError("Ignoring unrecognized argument: " + arg.raw_value);
else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player's locations as the origin if one is not specified
Expand Down
Expand Up @@ -35,37 +35,37 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(dEntity.class)) {
// Entity arg

scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class)) {
// Location arg

scriptEntry.addObject("location", arg.asType(dLocation.class));
}

else if (!scriptEntry.hasObject("target")
&& arg.matchesArgumentType(dEntity.class)
&& arg.matchesPrefix("target")) {
// Entity arg

scriptEntry.addObject("target", arg.asType(dEntity.class));
}

else if (!scriptEntry.hasObject("spread")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("spread", arg.asElement());
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use the NPC or player's locations as the location if one is not specified

scriptEntry.defaultObject("location",
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null,
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null);

// Check to make sure required arguments have been filled

if (!scriptEntry.hasObject("entities"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");

Expand Down
Expand Up @@ -46,6 +46,8 @@ else if (arg.matches("npc") && scriptEntry.hasNPC()) {
// NPC arg for compatibility with old scripts
scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getNPC().getDenizenEntity()));
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Use player or NPC as default entity
Expand Down
Expand Up @@ -60,6 +60,8 @@ else if (arg.matchesArgumentType(dLocation.class))
else if (arg.matchesArgumentType(dInventory.class))
scriptEntry.addObject("destinationInventory", arg.asType(dInventory.class));
}

else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

// Check to make sure required arguments have been filled
Expand Down
Expand Up @@ -68,8 +68,7 @@ else if (!scriptEntry.hasObject("location")
// add location (for ADD)
scriptEntry.addObject("location", arg.asType(dLocation.class));


else dB.echoError("Unhandled argument: '" + arg.raw_value + '\'');
else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}


Expand Down
Expand Up @@ -40,6 +40,7 @@ else if (!scriptEntry.hasObject("auto_range")
&& arg.matches("auto_range"))
scriptEntry.addObject("auto_range", Element.TRUE);

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}


Expand Down
Expand Up @@ -20,17 +20,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("location", arg.asType(dLocation.class));
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("location", arg.asType(dLocation.class));

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}


// Check for required information

if (!scriptEntry.hasObject("location"))
throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "LOCATION");

}


Expand Down
Expand Up @@ -48,7 +48,7 @@ else if ((arg.matchesPrefix("target") || arg.matchesPrefix(TARGET_ARG))) {
scriptEntry.addObject("targets", ((dList)arg.asType(dList.class)).filter(dPlayer.class));
}

// Use raw_value as to not accidentely strip a value before any :'s.
// Use raw_value as to not accidentally strip a value before any :'s.
else {
if (!scriptEntry.hasObject("text"))
scriptEntry.addObject("text", new Element(arg.raw_value));
Expand Down
Expand Up @@ -37,6 +37,8 @@ else if (arg.matchesPrefix("d, duration")

else if (arg.matchesArgumentType(dMaterial.class))
scriptEntry.addObject("material", arg.asType(dMaterial.class));

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

if (locations.isEmpty())
Expand Down

0 comments on commit f2dec7f

Please sign in to comment.