Search in sources :

Example 1 with EntityAnimation

use of net.aufdemrand.denizen.nms.interfaces.EntityAnimation in project Denizen-For-Bukkit by DenizenScript.

the class AnimateCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    PlayerAnimation animation = scriptEntry.hasObject("animation") ? (PlayerAnimation) scriptEntry.getObject("animation") : null;
    EntityEffect effect = scriptEntry.hasObject("effect") ? (EntityEffect) scriptEntry.getObject("effect") : null;
    String nmsAnimation = scriptEntry.hasObject("nms_animation") ? (String) scriptEntry.getObject("nms_animation") : null;
    // Report to dB
    dB.report(scriptEntry, getName(), (animation != null ? aH.debugObj("animation", animation.name()) : effect != null ? aH.debugObj("effect", effect.name()) : aH.debugObj("animation", nmsAnimation)) + aH.debugObj("entities", entities.toString()));
    // Go through all the entities and animate them
    for (dEntity entity : entities) {
        if (entity.isSpawned()) {
            try {
                if (animation != null && entity.getBukkitEntity() instanceof Player) {
                    Player player = (Player) entity.getBukkitEntity();
                    animation.play(player);
                } else if (effect != null) {
                    entity.getBukkitEntity().playEffect(effect);
                } else {
                    EntityAnimation entityAnimation = NMSHandler.getInstance().getAnimationHelper().getEntityAnimation(nmsAnimation);
                    entityAnimation.play(entity.getBukkitEntity());
                }
            } catch (Exception e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Error playing that animation!");
            }
        // We tried!
        }
    }
}
Also used : EntityEffect(org.bukkit.EntityEffect) EntityAnimation(net.aufdemrand.denizen.nms.interfaces.EntityAnimation) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Aggregations

List (java.util.List)1 EntityAnimation (net.aufdemrand.denizen.nms.interfaces.EntityAnimation)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)1 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 PlayerAnimation (net.citizensnpcs.util.PlayerAnimation)1 EntityEffect (org.bukkit.EntityEffect)1 Player (org.bukkit.entity.Player)1