Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6fe9fd
commit 2fcd10e
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/net/aufdemrand/denizen/scripts/commands/world/BreakCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
2fcd10e
There was a problem hiding this comment.
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
2fcd10e
There was a problem hiding this comment.
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.
2fcd10e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay ;D