Skip to content

Commit

Permalink
Add MythicSpawn command
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed May 28, 2016
1 parent 974239c commit 6f3dc04
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
@@ -0,0 +1,80 @@
package net.gnomeffinway.depenizen.commands.mythicmobs;

import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.elseland.xikage.MythicMobs.API.IMobsAPI;
import net.elseland.xikage.MythicMobs.Mobs.MythicMob;
import net.elseland.xikage.MythicMobs.MythicMobs;

public class MythicSpawnCommand extends AbstractCommand {

// <--[command]
// @Name MythicSpawn
// @Syntax mythicspawn [<name>] [<location>]
// @Group Depenizen
// @Plugin Depenizen, MythicMobs
// @Required 2
// @Stable untested
// @Short Spawns a MythicMob at a location.
// @Author Morphan1

// @Description
// This allows you to spawn a MythicMob at a location using the mob's internal name.

// @Tags
// <entry[saveName].spawned_mythicmob>

// @Usage
// Use to spawn a BarbarianMinion at a player's location.
// - mythicspawn BarbarianMinion <player.location>

// -->

@Override
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));
}

else if (!scriptEntry.hasObject("name")) {
scriptEntry.addObject("name", arg.asElement());
}

else {
arg.reportUnhandled();
}

}

if (!scriptEntry.hasObject("location") || !scriptEntry.hasObject("name")) {
throw new InvalidArgumentsException("Must specify a name and location.");
}
}

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

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

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

try {
MythicMob mob = api.getMythicMob(name.asString());
api.spawnMythicMob(mob, location);
}
catch (Exception e) {
e.printStackTrace();
}

}
}
@@ -1,6 +1,7 @@
package net.gnomeffinway.depenizen.support.plugins;

import net.aufdemrand.denizen.objects.dEntity;
import net.gnomeffinway.depenizen.commands.mythicmobs.MythicSpawnCommand;
import net.gnomeffinway.depenizen.events.mythicmobs.MythicMobsDeathEvent;
import net.gnomeffinway.depenizen.extensions.mythicmobs.MythicMobsEntityExtension;
import net.gnomeffinway.depenizen.objects.mythicmobs.MythicMobsMob;
Expand All @@ -12,6 +13,7 @@ public MythicMobsSupport() {
registerObjects(MythicMobsMob.class);
registerProperty(MythicMobsEntityExtension.class, dEntity.class);
registerScriptEvents(new MythicMobsDeathEvent());
new MythicSpawnCommand().activate().withOptions("See Documentation", 2);
}

}

0 comments on commit 6f3dc04

Please sign in to comment.