Search in sources :

Example 1 with BlockBreaker

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);
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) HashMap(java.util.HashMap) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) BlockBreaker(net.citizensnpcs.api.npc.BlockBreaker) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

HashMap (java.util.HashMap)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizen.objects.dMaterial (net.aufdemrand.denizen.objects.dMaterial)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)1 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)1 BlockBreaker (net.citizensnpcs.api.npc.BlockBreaker)1