Skip to content

Commit

Permalink
Ad reset arg to Compass command
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 25, 2015
1 parent ac1ba50 commit 6215d6d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -492,7 +492,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Compass
// @Syntax compass [<location>]
// @Syntax compass [<location>/reset]
// @Required 1
// @Stable stable
// @Short Redirects the player's compass to target the given location.
Expand All @@ -506,7 +506,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(CompassCommand.class,
"COMPASS", "compass [<location>]", 1);
"COMPASS", "compass [<location>/reset]", 1);


// <--[command]
Expand Down
Expand Up @@ -3,11 +3,13 @@
import net.aufdemrand.denizen.BukkitScriptEntryData;
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.denizen.objects.dLocation;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Location;
import org.bukkit.entity.Player;

public class CompassCommand extends AbstractCommand {
Expand All @@ -21,16 +23,22 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class))
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("location", arg.asType(dLocation.class));

else if (!scriptEntry.hasObject("reset")
&& arg.matches("reset"))
scriptEntry.addObject("reset", new Element(true));

else
arg.reportUnhandled();
}

// Check for required information
if (!scriptEntry.hasObject("location"))
if (!scriptEntry.hasObject("location") && !scriptEntry.hasObject("reset"))
throw new InvalidArgumentsException("Missing location argument!");

scriptEntry.defaultObject("reset", new Element(false));
}


Expand All @@ -39,16 +47,22 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

// Fetch required objects

dLocation location = (dLocation) scriptEntry.getObject("location");
dLocation location = scriptEntry.getdObject("location");
Element reset = scriptEntry.getElement("reset");
Player player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity();


// Debug the execution

dB.report(scriptEntry, getName(), location.debug());

dB.report(scriptEntry, getName(), location.debug() + reset.debug());

player.setCompassTarget(location);
if (reset.asBoolean()) {
Location bed = player.getBedSpawnLocation();
player.setCompassTarget(bed != null ? bed : player.getWorld().getSpawnLocation());
}
else {
player.setCompassTarget(location);
}


}
Expand Down

0 comments on commit 6215d6d

Please sign in to comment.