1.14 Command not autocompleting

Discussion in 'Spigot Plugin Development' started by Austerzockt, Jun 12, 2019.

Thread Status:
Not open for further replies.
  1. I need help with the plugin i'm writing at the moment. It should contain a /heal command, which works properly, but the tab completion of the command doesnt! Intellij IDEA threw an error in my plugin.yml, but a yaml parser translated it properly
    Code (YAML):
    name: CustomEssentials
    version
    : '2.0'
    author
    : Austerzockt
    main
    : at.austerzockt.test.classes.Main
    commands
    :
      gm
    :
        aliases
    : [gamemode]
        description
    : Sets your GameMode
      heal
    :
        aliases
    : [healplayer]
        description
    : Heals the Player
      fly
    :
        aliases
    : [flymode]
        description
    : Enables/Disabled FlyMode
    a confusing fact is that always the second command has problems with the completion. if i changed it to the fly command, /fly wouldnt auto-complete.
    Here is the Heal Command
    Code (Java):
    package at.austerzockt.test.classes;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.attribute.Attribute;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class HealCMD implements CommandExecutor {

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
            if (cmd.getName().equalsIgnoreCase("heal")) {
                if (sender instanceof Player) {
                    Player p = (Player) sender;
                    if (p.hasPermission("essv2.heal")) {
                        if (args.length == 0) {
                            if (p.hasPermission("essv2.heal.self")) {
                                p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
                                p.setSaturation(20.0F);
                                p.setFoodLevel(20);
                                p.sendMessage(ChatColor.GOLD + "You were healed");
                            }
                        } else if (args.length == 1) {
                            Player p2 = Bukkit.getPlayer(args[0]);
                            if (p.hasPermission("essv2.heal.other") && p2.hasPermission("essv2.heal.nochange")) {
                                p2.setHealth(p2.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
                                p2.setSaturation(20.0F);
                                p2.setFoodLevel(20);
                                p2.sendMessage(ChatColor.GOLD + "You were healed by " + p.getDisplayName());
                                p.sendMessage(p2.getDisplayName() + ChatColor.GOLD + " was healed");



                        }


                        }
                    } else {
                        p.sendMessage(Main.noperm);
                    }

                }
            }
            return false;
        }
    }
     
    and my Main.java
    Code (Java):

    package at.austerzockt.test.classes;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {
        static String noperm = ChatColor.RED + "No Perms";
        static String noplayer = ChatColor.RED + "Not a Player";


        @Override
        public void onEnable()  {
            this.getCommand("gm").setExecutor(new GmCMD());
            this.getCommand("gm").setTabCompleter(new GmTab());
            this.getCommand("fly").setExecutor(new FlyCMD());
            this.getCommand("heal").setExecutor(new HealCMD());
            this.getCommand("heal").setTabCompleter(new HealTab());
            Bukkit.getConsoleSender().sendMessage("Startup");

        }

        @Override
        public void onDisable(){
            Bukkit.getConsoleSender().sendMessage("Stop");

        }

    }
     
    sorry if my english is not very good.
     
  2. Could you please post your HealTab class? Also, you don't need
    Code (Text):
    if (cmd.getName().equalsIgnoreCase("heal")
    since HealCMD will only be used if the player puts in /heal. You also need to return true once a player is healed since right now it's always returning false.
     
    #2 TehBrian, Jun 12, 2019
    Last edited: Jun 12, 2019
  3. The slash in the description may cause issues. You should wrap all strings in quotes to make sure characters don't cause any issues
     
Thread Status:
Not open for further replies.

Share This Page