use of net.citizensnpcs.api.npc.BlockBreaker in project Denizen-For-Bukkit by DenizenScript.
the class BreakCommand method execute.
// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
final dLocation location = (dLocation) scriptEntry.getObject("location");
final dNPC npc = (dNPC) scriptEntry.getObject("entity");
Element radius = scriptEntry.getElement("radius");
final HashMap<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
context.put("location", location);
context.put("material", material);
dB.report(scriptEntry, getName(), location.debug() + npc.debug() + radius.debug());
final ScriptEntry se = scriptEntry;
BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
config.item(npc.getLivingEntity().getEquipment().getItemInHand());
config.radius(radius.asDouble());
config.callback(new Runnable() {
@Override
public void run() {
npc.action("dig", null, context);
se.setFinished(true);
}
});
BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
if (breaker.shouldExecute()) {
TaskRunnable run = new TaskRunnable(breaker);
run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), run, 0, 1);
}
}
Aggregations