Search in sources :

Example 1 with PlayerAnimation

use of net.citizensnpcs.util.PlayerAnimation in project Citizens2 by CitizensDev.

the class AnimationTriggerPrompt method acceptInput.

@Override
public Prompt acceptInput(ConversationContext context, String input) {
    if (input.equalsIgnoreCase("back")) {
        return (Prompt) context.getSessionData("previous");
    }
    if (input.equalsIgnoreCase("finish")) {
        context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, new AnimationTrigger(animations));
        return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
    }
    PlayerAnimation animation = Util.matchEnum(PlayerAnimation.values(), input);
    if (animation == null) {
        Messaging.sendErrorTr((CommandSender) context.getForWhom(), Messages.INVALID_ANIMATION, input, getValidAnimations());
    }
    animations.add(animation);
    Messaging.sendTr((CommandSender) context.getForWhom(), Messages.ANIMATION_ADDED, input);
    return this;
}
Also used : PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) StringPrompt(org.bukkit.conversations.StringPrompt) Prompt(org.bukkit.conversations.Prompt)

Example 2 with PlayerAnimation

use of net.citizensnpcs.util.PlayerAnimation in project Denizen-For-Bukkit by DenizenScript.

the class AnimateCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for");
    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;
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), (animation != null ? db("animation", animation.name()) : effect != null ? db("effect", effect.name()) : db("animation", nmsAnimation)), db("entities", entities), db("for", forPlayers));
    }
    for (EntityTag 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) {
                    if (forPlayers != null) {
                        for (PlayerTag player : forPlayers) {
                            NMSHandler.getPacketHelper().sendEntityEffect(player.getPlayerEntity(), entity.getBukkitEntity(), effect.getData());
                        }
                    } else {
                        entity.getBukkitEntity().playEffect(effect);
                    }
                } else if (nmsAnimation != null) {
                    EntityAnimation entityAnimation = NMSHandler.getAnimationHelper().getEntityAnimation(nmsAnimation);
                    entityAnimation.play(entity.getBukkitEntity());
                } else {
                    Debug.echoError("No way to play the given animation on entity '" + entity + "'");
                }
            } catch (Exception e) {
                Debug.echoError(scriptEntry, "Error playing that animation!");
                Debug.echoError(e);
            }
        }
    }
}
Also used : EntityEffect(org.bukkit.EntityEffect) EntityAnimation(com.denizenscript.denizen.nms.interfaces.EntityAnimation) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 3 with PlayerAnimation

use of net.citizensnpcs.util.PlayerAnimation 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

PlayerAnimation (net.citizensnpcs.util.PlayerAnimation)3 List (java.util.List)2 EntityEffect (org.bukkit.EntityEffect)2 Player (org.bukkit.entity.Player)2 EntityAnimation (com.denizenscript.denizen.nms.interfaces.EntityAnimation)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)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 Prompt (org.bukkit.conversations.Prompt)1 StringPrompt (org.bukkit.conversations.StringPrompt)1