Rip my command

Discussion in 'Spigot Plugin Development' started by Igasi, May 23, 2017.

  1. Code (Text):

    public boolean onCommand(CommandSender thesender, Command cmd, String label,  String[] args){
            if(thesender instanceof CommandBlock){
                CommandBlock p = (CommandBlock) thesender;
            Location loc = p.getLocation();
            //0 = Name, 1 = Level, 2 = Mob, 3 = Health, 4 = Damage, 5 = Speed, 6 = AttackSpeed, 7 = KnockBackResistance, 8 = ArmorBoosts.
            Entity myEntity = loc.getWorld().spawnEntity(loc, EntityType.valueOf(args[1].toUpperCase()));
            LivingEntity li = (LivingEntity)myEntity;
            String name = args[0];
            String level = args[1];
            myEntity.setCustomName(ChatColor.RED + "[" + ChatColor.GOLD + level + ChatColor.RED + "] " + ChatColor.GOLD + name + ChatColor.RED + " [" + ChatColor.GOLD + ((Damageable) myEntity).getHealth() + ChatColor.RED + "/" + ChatColor.GOLD + ((Damageable) myEntity).getMaxHealth() + ChatColor.RED + "]");
            int health = Integer.parseInt(args[3]);
            AttributeInstance myEntityHealth = ((Attributable) myEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH);

            int damage = Integer.parseInt(args[4]);
            AttributeInstance myEntityDamage = ((Attributable) myEntity).getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
            int speed = Integer.parseInt(args[5]);
            AttributeInstance myEntitySpeed = ((Attributable) myEntity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
            int attackspeed = Integer.parseInt(args[6]);
            AttributeInstance myEntityAttackSpeed = ((Attributable) myEntity).getAttribute(Attribute.GENERIC_ATTACK_SPEED);
            int kb = Integer.parseInt(args[7]);
            AttributeInstance myEntityKB = ((Attributable) myEntity).getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
            int ab = Integer.parseInt(args[8]);
            AttributeInstance myEntityAB = ((Attributable)myEntity).getAttribute(Attribute.GENERIC_ARMOR);
            //9 = ItemInHand, 10 = Helmet, 11 = Chestplate, 12 = Legs, 13 = Boots, 14 = Off Hand
            li.getEquipment().setItemInMainHand(new ItemStack(Material.valueOf(args[9].toUpperCase())));
            li.getEquipment().setHelmet(new ItemStack(Material.valueOf(args[10].toUpperCase())));
            li.getEquipment().setChestplate(new ItemStack(Material.valueOf(args[11].toUpperCase())));
            li.getEquipment().setLeggings(new ItemStack(Material.valueOf(args[12].toUpperCase())));
            li.getEquipment().setBoots(new ItemStack(Material.valueOf(args[13].toUpperCase())));
            li.getEquipment().setItemInOffHand(new ItemStack(Material.valueOf(args[14].toUpperCase())));
            //Removing drop chances:

            return false;
    Anyways, this command doesn't work. One might say it is because it runs the spawn line of code before it's attributes, but it doesn't spawn anything. at all.

    someone help me pls my server wont work w/o it

    EDIT: Also, no messages in the console except for /player issued server command: /spawnenemy
    #1 Igasi, May 23, 2017
    Last edited: May 23, 2017
  2. Does the command method even run? If not, there's something wrong with the API/your usage.
  3. I tried a different command and it works.
  4. I'm talking about that command specifically, print out debug messages after each line of code in there to see where it stops.
  5. I've actually never done or read about debug messages because I never thought they were necessary. What would it look like (if there is anything special about spigot compared to normal java)?
  6. Just place System.out.println(message) where something happens in the code to ensure that the code is actually running.
  7. I did and nothing is running .-.

    Also I changed it to a normal command and it's registered and everything, but still wont work
  8. Can we see your code?
  9. Yeah I just edited it
  10. Usually, for debug messages, it is a lot more when trying to find a problem, and are you sending it by a commandblock or by you, since right now it is only for command blocks.
  11. commandblocks. I'm pressing buttons. I changed it for half a minute to test what happens when I do it

    Also nothing is printed when I do it by commandblocks
  12. Change it for player, and with every if() statement, have print to console with System.out.println() in the else and if. Your plugin.yml has the command properly registered correctly, right?
  13. yeah if I do /help the command will pop up.

    I checked and none of the messages printed....
  14. And between these 2 lines?
    Code (Text):

    public boolean onCommand(CommandSender thesender, Command cmd, String label,  String[] args){
    if you put a println, does it work ?
  15. did you register the command in your onEnable?
  16. He doesn't need to register his command in onEnable if onCommand is in the same file, but maybe you've forgotten the
    Code (Text):

  17. I have it there
    I did and it doesnt work :/
  18. Yes, we all make this mistake at first, but they are important, unfortunately.
  19. As I asked before, Your plugin.yml has the command properly registered correctly, right?
  20. yes, I already said so.

    Yeah I learned the concept so I wont make this mistake again