Skip to content

Commit

Permalink
Add level to MythicSpawn command
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed May 28, 2016
1 parent 6f3dc04 commit 89cec52
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import net.elseland.xikage.MythicMobs.API.IMobsAPI;
import net.elseland.xikage.MythicMobs.Mobs.MythicMob;
import net.elseland.xikage.MythicMobs.MythicMobs;
import net.gnomeffinway.depenizen.objects.mythicmobs.MythicMobsMob;
import org.bukkit.entity.Entity;

public class MythicSpawnCommand extends AbstractCommand {

// <--[command]
// @Name MythicSpawn
// @Syntax mythicspawn [<name>] [<location>]
// @Syntax mythicspawn [<name>] [<location>] (level:<#>)
// @Group Depenizen
// @Plugin Depenizen, MythicMobs
// @Required 2
Expand All @@ -27,7 +29,7 @@ public class MythicSpawnCommand extends AbstractCommand {
// This allows you to spawn a MythicMob at a location using the mob's internal name.

// @Tags
// <entry[saveName].spawned_mythicmob>
// <entry[saveName].spawned_mythicmob> returns the spawned MythicMobsMob.

// @Usage
// Use to spawn a BarbarianMinion at a player's location.
Expand All @@ -45,6 +47,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
scriptEntry.addObject("location", arg.asType(dLocation.class));
}

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

else if (!scriptEntry.hasObject("name")) {
scriptEntry.addObject("name", arg.asElement());
}
Expand All @@ -58,19 +66,23 @@ else if (!scriptEntry.hasObject("name")) {
if (!scriptEntry.hasObject("location") || !scriptEntry.hasObject("name")) {
throw new InvalidArgumentsException("Must specify a name and location.");
}

scriptEntry.defaultObject("level", new Element(1));
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

Element name = scriptEntry.getElement("name");
dLocation location = scriptEntry.getdObject("location");
Element level = scriptEntry.getElement("level");

IMobsAPI api = MythicMobs.inst().getAPI().getMobAPI();

try {
MythicMob mob = api.getMythicMob(name.asString());
api.spawnMythicMob(mob, location);
Entity entity = api.spawnMythicMob(mob, location, level.asInt());
scriptEntry.addObject("spawned_mythicmob", new MythicMobsMob(api.getMythicMobInstance(entity)));
}
catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 89cec52

Please sign in to comment.