help

Discussion in 'Spigot Plugin Help' started by 2Hex, Jul 16, 2021.

  1. so im making a plugin where u do /armorstand then a armor stand spawns and starts dancing
    um so the first
    armorStand.setLeftArmPose(new EulerAngle(0, 0, Math.toRadians(38)));
    armorStand.setRightArmPose(new EulerAngle(0, 0, Math.toRadians(61)));
    gets overriden by the next one. so it doesnt dance and only does 1 pose.
    pls help i wanna make it dance (repeatedly)
    any way I can do that?
    Code (Java):
    package me.hex.armorstanddancing.commands;

    import me.hex.armorstanddancing.ArmorStandDancing;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.util.EulerAngle;

    public class SpawnAndDance implements CommandExecutor {


        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

            if (!(sender instanceof Player)) {
                sender.sendMessage("This command can only be run by a player.");
                return false;

            }

            Player player = (Player) sender;
            if(player.hasPermission("dance.spawn")) {
                ArmorStand armorStand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
                armorStand.setArms(true);

                player.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "FLOSSIN DANCE COMIN IN 1 SECOND BOI");
                Bukkit.getScheduler().runTaskTimer(ArmorStandDancing.INSTANCE, () -> {
                    armorStand.setLeftArmPose(new EulerAngle(0, 0, Math.toRadians(38)));
                    armorStand.setRightArmPose(new EulerAngle(0, 0, Math.toRadians(61)));
                    armorStand.setLeftArmPose(new EulerAngle(0, 0, Math.toRadians(313)));
                    armorStand.setRightArmPose(new EulerAngle(0, 0, Math.toRadians(320)));

                }, 20L, 20L);
            }else{
                player.sendMessage(ChatColor.RED + "You can not run this command without the permission 'dance.spawn'");
            }

                return true;
        }

            }

     
     
  2. bump pls help
     
  3. Well of course it only does one pose, you never change the values...
     
  4. What I do to make my runnable loops (So basically multiple runnables on different times) is I use a for loop, it would look something like this:

    Code (Java):
    for (int i = 0; i < amount of loops + 1; i++) {
    new BukkitRunnable() {
        public void Run() {
           Switch (i) {
           case 1:
                 // method
           case 2:
                // method
          }
        }

    }.runTaskLater(plugin, 1, amount of ticks between loops * i)
    }
    (this is probably not going to work if you copy paste it, because i didn't make this code in a Java editor, but maybe that's a good thing, we don't wanna be spoonfeeding you the code)



    With your old code, everything is in 1 runnable, meaning that it all happens at the same time, and the latest values will be used, meaning it doesn't dance.
     
  5. lol i figured it out i used
    if(armorStand.getRightArmPose().getZ() == Math.toRadians(61)){ armorStand.setRightArmPose(new EulerAngle(0, 0, Math.toRadians(320))); }