Skip to content

Commit

Permalink
Update health command, fixes #329
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 11, 2013
1 parent b431fd1 commit dc56ce5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 80 deletions.
Expand Up @@ -173,7 +173,7 @@ public void registerCoreMembers() {
"HEAL", "heal (<#.#>) (<entity>|...)", 0);

registerCoreMember(HealthCommand.class,
"HEALTH", "health (state:true/false/toggle) (set_max:<#>)", 1);
"HEALTH", "health [<#>]", 1);

registerCoreMember(HurtCommand.class,
"HURT", "hurt (<#.#>) (<entity>|...)", 0);
Expand Down
Expand Up @@ -36,7 +36,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

// if (!scriptEntry.hasObject("required_integer")
// && arg.matchesPrimitive(aH.PrimitiveType.Integer))
// scriptEntry.addObject("required_integer", arg.asElement);
// scriptEntry.addObject("required_integer", arg.asElement());

// if (!scriptEntry.hasObject("required_location")
// && arg.matchesArgumentType(dLocation.class))
Expand Down
@@ -0,0 +1,74 @@
package net.aufdemrand.denizen.scripts.commands.entity;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.npc.traits.HealthTrait;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;

public class HealthCommand extends AbstractCommand {


@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

// Interpret arguments

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("target")
&& arg.matches("player")){
if (!scriptEntry.hasPlayer())
throw new InvalidArgumentsException(dB.Messages.ERROR_NO_PLAYER);
scriptEntry.addObject("target", arg.asElement());
}
if (!scriptEntry.hasObject("qty")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer))
scriptEntry.addObject("qty", arg.asElement());

}


// Check for required information

if (!scriptEntry.hasObject("qty"))
throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "QUANTITY");
if (!scriptEntry.hasObject("target")) {
if (!scriptEntry.hasNPC())
throw new InvalidArgumentsException(dB.Messages.ERROR_NO_NPCID);
scriptEntry.addObject("target", Element.valueOf("npc"));
}

}


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

// Fetch required objects

Element qty = scriptEntry.getElement("qty");
boolean isplayer = scriptEntry.getElement("target").asString().equalsIgnoreCase("player");


dB.report(getName(), qty.debug());

if (qty == null)
dB.echoError("Null quantity!");

if (isplayer) {
scriptEntry.getPlayer().getPlayerEntity().setMaxHealth(qty.asDouble());
}
else {
if (scriptEntry.getNPC().getCitizen().hasTrait(HealthTrait.class))
scriptEntry.getNPC().getHealthTrait().setMaxhealth(qty.asInt());
else
dB.echoError("NPC doesn't have health trait!");
}
}


}

This file was deleted.

0 comments on commit dc56ce5

Please sign in to comment.