use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class SQLCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("sqlid") && arg.matchesPrefix("id")) {
scriptEntry.addObject("sqlid", arg.asElement());
} else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("connect")) {
scriptEntry.addObject("action", new Element("CONNECT"));
scriptEntry.addObject("server", arg.asElement());
} else if (!scriptEntry.hasObject("action") && arg.matches("disconnect")) {
scriptEntry.addObject("action", new Element("DISCONNECT"));
} else if (!scriptEntry.hasObject("query") && arg.matchesPrefix("query")) {
scriptEntry.addObject("action", new Element("QUERY"));
scriptEntry.addObject("query", arg.asElement());
} else if (!scriptEntry.hasObject("query") && arg.matchesPrefix("update")) {
scriptEntry.addObject("action", new Element("UPDATE"));
scriptEntry.addObject("query", arg.asElement());
} else if (!scriptEntry.hasObject("username") && arg.matchesPrefix("username")) {
scriptEntry.addObject("username", arg.asElement());
} else if (!scriptEntry.hasObject("password") && arg.matchesPrefix("password")) {
scriptEntry.addObject("password", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("sqlid")) {
throw new InvalidArgumentsException("Must specify an ID!");
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify an action!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class NBTCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("key") && arg.raw_value.split(":", 2).length == 2) {
String[] flagArgs = arg.raw_value.split(":", 2);
scriptEntry.addObject("key", new Element(flagArgs[0]));
scriptEntry.addObject("value", new Element(flagArgs[1]));
} else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(dItem.class)) {
scriptEntry.addObject("item", arg.asType(dItem.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("item")) {
throw new InvalidArgumentsException("Must specify item!");
}
if (!scriptEntry.hasObject("key") || !scriptEntry.hasObject("value")) {
throw new InvalidArgumentsException("Must specify key and value!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ScribeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matchesEnum(BookAction.values()) && !scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", BookAction.valueOf(arg.getValue().toUpperCase()));
} else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(dScript.class)) {
scriptEntry.addObject("script", arg.asType(dScript.class));
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
scriptEntry.addObject("action", BookAction.DROP);
} else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(dItem.class)) {
scriptEntry.addObject("item", arg.asType(dItem.class));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("action", BookAction.GIVE);
scriptEntry.defaultObject("item", new dItem(Material.WRITTEN_BOOK));
// Must contain a book script
if (!scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("Missing SCRIPT argument!");
}
}
use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
ParticleHelper particleHelper = NMSHandler.getInstance().getParticleHelper();
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("location", arg.asType(dList.class).filter(dLocation.class));
} else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
if (particleHelper.hasParticle(arg.getValue())) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
} else if (arg.matches("random")) {
// Get another effect if "RANDOM" is used
if (CoreUtilities.getRandom().nextDouble() < 0.5) {
// Make sure the new effect is not an invisible effect
List<Particle> visible = particleHelper.getVisibleParticles();
scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
} else {
List<Effect> visual = particleHelper.getVisualEffects();
scriptEntry.addObject("effect", visual.get(CoreUtilities.getRandom().nextInt(visual.size())));
}
} else if (arg.startsWith("iconcrack_")) {
// Allow iconcrack_[id],[data] for item break effects (ex: iconcrack_1)
String shrunk = arg.getValue().substring("iconcrack_".length());
String[] split = shrunk.split(",");
Element typeId = new Element(split[0]);
if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
scriptEntry.addObject("iconcrack", typeId);
} else {
dB.echoError("Invalid iconcrack_[id]. Must be a valid Material ID, besides 0.");
}
Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
scriptEntry.addObject("iconcrack_data", dataId);
scriptEntry.addObject("iconcrack_type", new Element("iconcrack"));
} else if (arg.startsWith("blockcrack_")) {
String shrunk = arg.getValue().substring("blockcrack_".length());
String[] split = shrunk.split(",");
Element typeId = new Element(split[0]);
if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
scriptEntry.addObject("iconcrack", typeId);
} else {
dB.echoError("Invalid blockcrack_[id]. Must be a valid Material ID, besides 0.");
}
Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
scriptEntry.addObject("iconcrack_data", dataId);
scriptEntry.addObject("iconcrack_type", new Element("blockcrack"));
} else if (arg.startsWith("blockdust_")) {
String shrunk = arg.getValue().substring("blockdust_".length());
String[] split = shrunk.split(",");
Element typeId = new Element(split[0]);
if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
scriptEntry.addObject("iconcrack", typeId);
} else {
dB.echoError("Invalid blockdust_[id]. Must be a valid Material ID, besides 0.");
}
Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
scriptEntry.addObject("iconcrack_data", dataId);
scriptEntry.addObject("iconcrack_type", new Element("blockdust"));
} else if (particleHelper.hasEffect(arg.getValue())) {
scriptEntry.addObject("effect", particleHelper.getEffect(arg.getValue()));
}
} else if (!scriptEntry.hasObject("radius") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("visibility", "v", "radius", "r")) {
scriptEntry.addObject("radius", arg.asElement());
} else if (!scriptEntry.hasObject("data") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("data", "d")) {
scriptEntry.addObject("data", arg.asElement());
} else if (!scriptEntry.hasObject("qty") && arg.matchesPrimitive(aH.PrimitiveType.Integer) && arg.matchesPrefix("qty", "q", "quantity")) {
scriptEntry.addObject("qty", arg.asElement());
} else if (!scriptEntry.hasObject("offset") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("offset", "o")) {
double offset = arg.asElement().asDouble();
scriptEntry.addObject("offset", new dLocation(null, offset, offset, offset));
} else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("offset", "o")) {
scriptEntry.addObject("offset", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(dPlayer.class) && arg.matchesPrefix("targets", "target", "t")) {
scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
} else {
arg.reportUnhandled();
}
}
// Use default values if necessary
scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation()) : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation()) : null);
scriptEntry.defaultObject("data", new Element(0));
scriptEntry.defaultObject("radius", new Element(15));
scriptEntry.defaultObject("qty", new Element(1));
scriptEntry.defaultObject("offset", new dLocation(null, 0.5, 0.5, 0.5));
if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
throw new InvalidArgumentsException("Missing effect argument!");
}
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 ActionBarCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (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);
}
if (arg.matchesPrefix("targets", "target") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
}
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Must specify a message!");
}
if (!scriptEntry.hasObject("targets") && !((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
throw new InvalidArgumentsException("Must specify target(s).");
}
if (!scriptEntry.hasObject("targets")) {
BukkitScriptEntryData data = (BukkitScriptEntryData) scriptEntry.entryData;
if (!data.hasPlayer()) {
throw new InvalidArgumentsException("Must specify valid player Targets!");
} else {
scriptEntry.addObject("targets", Arrays.asList(data.getPlayer()));
}
}
}
Aggregations