Skip to content

Commit

Permalink
Working on 'break' command.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jul 5, 2013
1 parent d6fe9fd commit 2fcd10e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -149,7 +149,7 @@ public <T extends dObject> T asType(Class<? extends dObject> clazz) {
arg = (dObject) clazz.getMethod("valueOf", String.class)
.invoke(null, value);

dB.log("Created: " + clazz.cast(arg).debug());
// dB.log("Created: " + clazz.cast(arg).debug());

return (T) clazz.cast(arg).setPrefix(prefix);

Expand Down
Expand Up @@ -72,6 +72,9 @@ public void registerCoreMembers() {

registerCoreMember(AttackCommand.class,
"ATTACK", "attack (stop)", 0);

registerCoreMember(BreakCommand.class,
"BREAK", "break [l@location] as:[e@entity]", 1);

registerCoreMember(BurnCommand.class,
"BURN", "burn [entities:<entity>|...] (duration:<value>)", 1);
Expand Down
@@ -0,0 +1,85 @@
package net.aufdemrand.denizen.scripts.commands.world;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.npc.ai.BlockBreaker;

/**
* Breaks a block using Citizens' BlockBreaker
*
* @author Jeremy Schroeder
*/

public class BreakCommand extends AbstractCommand {

@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("entity")
&& arg.matchesArgumentType(dEntity.class))
scriptEntry.addObject("entity", arg.asType(dEntity.class));

else if (!scriptEntry.hasObject("radius")
&& arg.matchesPrimitive(aH.PrimitiveType.Double))
scriptEntry.addObject("radius", arg.asElement());

}

// Make sure location and entity were fulfilled
if (!scriptEntry.hasObject("location"))
throw new InvalidArgumentsException("Must specify a location!");

if (!scriptEntry.hasObject("entity")) {
if (scriptEntry.getPlayer() != null && scriptEntry.getPlayer().isOnline())
scriptEntry.addObject("entity", new dEntity(scriptEntry.getPlayer().getPlayerEntity()));

else if (scriptEntry.getNPC() != null && scriptEntry.getNPC().isSpawned())
scriptEntry.addObject("entity", new dEntity(scriptEntry.getNPC().getEntity()));

else throw new InvalidArgumentsException("Must specify an entity!");

}
}

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

final dLocation location = (dLocation) scriptEntry.getObject("location");
final dEntity entity = (dEntity) scriptEntry.getObject("entity");
Element radius = (scriptEntry.hasObject("radius")
? (Element) scriptEntry.getObject("radius")
: null);

dB.report(getName(), location.debug() + entity.debug()
+ (radius != null ? radius.debug() : ""));

BlockBreaker.Configuration config = new BlockBreaker.Configuration()
.item(entity.getLivingEntity().getEquipment().getItemInHand())
.radius(radius != null ? radius.asDouble() : 1)
.callback(new Runnable() {
@Override
public void run() {
dB.echoDebug(entity.debug() + " dug " + location.debug());
}
});

BlockBreaker breaker = BlockBreaker.createWithConfiguration(entity.getLivingEntity(), location.getBlock(), config);
breaker.run();
}

}

3 comments on commit 2fcd10e

@spaceemotion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could change the copyblock to a "block" command and change the syntax to "block copy" and "block break" ...
just a thought :D

@aufdemrand
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is geared towards NPCs. It will make the NPC physically break the block.

@spaceemotion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay ;D

Please sign in to comment.