use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
scriptEntry.addObject("type", Type.ITEMINHAND);
} else if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("qty", arg.asElement());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.BYDISPLAY);
scriptEntry.addObject("displayname", arg.asElement());
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
scriptEntry.addObject("type", Type.BYCOVER);
scriptEntry.addObject("cover", arg.asType(dList.class));
} else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("type", Type.SLOT);
scriptEntry.addObject("slot", arg.asElement());
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(dItem.class)) {
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(dInventory.class)) {
scriptEntry.addObject("inventory", arg.asType(dInventory.class));
} else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
scriptEntry.addObject("type", Type.INVENTORY);
} else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity().getInventory());
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("qty", 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 take from!");
}
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 CreateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("entity_type") && arg.matchesArgumentType(dEntity.class)) {
// Avoid duplication of objects
dEntity ent = arg.asType(dEntity.class);
if (!ent.isGeneric() && !ent.isCitizensNPC()) {
throw new InvalidArgumentsException("Entity supplied must be generic or a Citizens NPC!");
}
scriptEntry.addObject("entity_type", ent);
} else if (!scriptEntry.hasObject("spawn_location") && arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("spawn_location", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("name")) {
scriptEntry.addObject("name", arg.asElement());
} else if (!scriptEntry.hasObject("traits") && arg.matchesPrefix("t", "trait", "traits")) {
scriptEntry.addObject("traits", arg.asType(dList.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("name")) {
throw new InvalidArgumentsException("Must specify a name!");
}
if (!scriptEntry.hasObject("entity_type")) {
throw new InvalidArgumentsException("Must specify an entity type!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class FlyCommand 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")) {
scriptEntry.addObject("cancel", "");
} else if (!scriptEntry.hasObject("destinations") && arg.matchesPrefix("destination", "destinations", "d")) {
scriptEntry.addObject("destinations", arg.asType(dList.class).filter(dLocation.class));
} else if (!scriptEntry.hasObject("controller") && arg.matchesArgumentType(dPlayer.class) && arg.matchesPrefix("controller", "c")) {
// Check if it matches a dPlayer, but save it as a dEntity
scriptEntry.addObject("controller", (arg.asType(dEntity.class)));
} else if (!scriptEntry.hasObject("origin") && arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("origin", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else if (!scriptEntry.hasObject("rotationThreshold") && arg.matchesPrefix("rotationthreshold", "rotation", "r") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
scriptEntry.addObject("rotationThreshold", arg.asElement());
} else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("speed", arg.asElement());
} else {
arg.reportUnhandled();
}
}
// Use the NPC or player's locations as the location if one is not specified
scriptEntry.defaultObject("origin", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null);
// Use a default speed and rotation threshold if they are not specified
scriptEntry.defaultObject("speed", new Element(1.2));
scriptEntry.defaultObject("rotationThreshold", new Element(15));
// Check to make sure required arguments have been filled
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("origin")) {
throw new InvalidArgumentsException("Must specify an origin!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class HealCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("amount", arg.asElement());
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
// Entity arg
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
specified_targets = true;
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
specified_targets = true;
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(-1));
}
if (!specified_targets) {
List<dEntity> entities = new ArrayList<dEntity>();
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
} else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
} else {
throw new InvalidArgumentsException("No valid target entities found.");
}
scriptEntry.addObject("entities", entities);
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class HurtCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("amount") && (arg.matchesPrimitive(aH.PrimitiveType.Double) || arg.matchesPrimitive(aH.PrimitiveType.Integer))) {
scriptEntry.addObject("amount", arg.asElement());
} else if (!scriptEntry.hasObject("source") && arg.matchesPrefix("source", "s") && arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("source", arg.asType(dEntity.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
// Entity arg
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
specified_targets = true;
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
specified_targets = true;
} else if (!scriptEntry.hasObject("cause") && arg.matchesEnum(EntityDamageEvent.DamageCause.values())) {
scriptEntry.addObject("cause", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(1.0d));
}
if (!specified_targets) {
List<dEntity> entities = new ArrayList<dEntity>();
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
} else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
} else {
throw new InvalidArgumentsException("No valid target entities found.");
}
scriptEntry.addObject("entities", entities);
}
}
Aggregations