Search in sources :

Example 1 with ExperienceOrb

use of org.bukkit.entity.ExperienceOrb in project Denizen-For-Bukkit by DenizenScript.

the class DropCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element qty = scriptEntry.getElement("qty");
    Element action = scriptEntry.getElement("action");
    Element speed = scriptEntry.getElement("speed");
    List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
    dEntity entity = (dEntity) scriptEntry.getObject("entity");
    Duration delay = (Duration) scriptEntry.getObject("delay");
    // Report to dB
    dB.report(scriptEntry, getName(), action.debug() + location.debug() + qty.debug() + (items != null ? aH.debugList("items", items) : "") + (entity != null ? entity.debug() : "") + (speed != null ? speed.debug() : "") + (delay != null ? delay.debug() : ""));
    dList entityList = new dList();
    // Do the drop
    switch(Action.valueOf(action.asString())) {
        case DROP_EXP:
            dEntity orb = new dEntity(location.getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB));
            ((ExperienceOrb) orb.getBukkitEntity()).setExperience(qty.asInt());
            entityList.add(orb.toString());
            break;
        case DROP_ITEM:
            for (dItem item : items) {
                if (qty.asInt() > 1 && item.isUnique()) {
                    dB.echoDebug(scriptEntry, "Cannot drop multiples of this item because it is Unique!");
                }
                for (int x = 0; x < qty.asInt(); x++) {
                    dEntity e = new dEntity(location.getWorld().dropItem(location, item.getItemStack()));
                    if (e.isValid()) {
                        e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d));
                        if (delay != null) {
                            ((Item) e.getBukkitEntity()).setPickupDelay(delay.getTicksAsInt());
                        }
                    }
                    entityList.add(e.toString());
                }
            }
            break;
        case DROP_ENTITY:
            if (qty.asInt() > 1 && entity.isUnique()) {
                dB.echoDebug(scriptEntry, "Cannot drop multiples of this entity because it is Unique!");
                entity.spawnAt(location);
                entityList.add(entity.toString());
                break;
            }
            for (int x = 0; x < qty.asInt(); x++) {
                ArrayList<Mechanism> mechanisms = new ArrayList<Mechanism>();
                for (Mechanism mechanism : entity.getWaitingMechanisms()) {
                    mechanisms.add(new Mechanism(new Element(mechanism.getName()), mechanism.getValue()));
                }
                dEntity ent = new dEntity(entity.getEntityType(), mechanisms);
                ent.spawnAt(location);
                entityList.add(ent.toString());
            }
            break;
    }
    // Add entities to context so that the specific entities dropped can be fetched.
    scriptEntry.addObject("dropped_entities", entityList);
}
Also used : ArrayList(java.util.ArrayList) ExperienceOrb(org.bukkit.entity.ExperienceOrb) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Item(org.bukkit.entity.Item) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) ArrayList(java.util.ArrayList) List(java.util.List) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 ExperienceOrb (org.bukkit.entity.ExperienceOrb)1 Item (org.bukkit.entity.Item)1