command autocomplete is shotwing command twice

Discussion in 'Plugin Development' started by ADX20, Feb 11, 2023.

Thread Status:
Not open for further replies.
  1. Offline

    ADX20

    I am new to plugin development.
    If I open the chat and start typing my command it is listed twice. One time as intended and another time with the name of my main class as prefix. As seen in the picture.
    My main class:

    Code:java
    1.  
    2. package io.github.ADX20.XPConsumables;
    3.  
    4. import java.util.ArrayList;
    5. import java.util.HashMap;
    6. import org.bukkit.Material;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class XPConsumables extends JavaPlugin {
    10.  
    11. protected HashMap<Material, Food> foods;
    12.  
    13. @Override
    14. public void onEnable() {
    15. this.getCommand("xpc").setExecutor(new XPConsumablesCommandExecutor(this));
    16. getServer().getPluginManager().registerEvents(new MenuListener(this), this);
    17. getLogger().info("onEnable has been Invoked");
    18.  
    19.  
    20. foods = new HashMap<Material,Food>();
    21.  
    22. foods.put(Material.RABBIT_STEW, new Food(Material.RABBIT_STEW, 10, getLore()));
    23. foods.put(Material.HONEY_BOTTLE, new Food(Material.HONEY_BOTTLE, 5, getLore()));
    24. }
    25.  
    26. private ArrayList<String> getLore(){
    27.  
    28. ArrayList<String> lore = new ArrayList<String>();
    29. lore.add("sample lore");
    30.  
    31. return lore;
    32. }
    33.  
    34. }
    35.  



    My Plugin.yml:
    Code:yml
    1.  
    2. name: XPConsumables
    3. main: io.github.ADX20.XPConsumables.XPConsumables
    4. version: 1.0
    5. api-version: 1.19
    6. author: ADX20
    7. commands:
    8. XPC:
    9. description: XPConsumables menu.
    10. usage: /xpc [info | add | del]
    11.  


    and a snippet from my command executor class:
    Code:java
    1.  
    2. package io.github.ADX20.XPConsumables;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9.  
    10.  
    11. public class XPConsumablesCommandExecutor implements CommandExecutor{
    12.  
    13. private final XPConsumables xpcons;
    14.  
    15. public XPConsumablesCommandExecutor(XPConsumables xpcons) {
    16. this.xpcons = xpcons;
    17. }
    18.  
    19. @Override
    20. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    21.  
    22. if(command.getName().equalsIgnoreCase("xpc") || args[1].equalsIgnoreCase("info")) {
    23. if(! (sender instanceof Player)) {
    24.  
    25. sender.sendMessage("This Command can only be run by a player.");
    26.  
    27. }else {
    28. Player player = (Player) sender;
    29.  


    I already tried to rewrite the plugin.yml, tweak the .setExecutor in the main and even remove the EventListener. All without any results.
    Maybe I am missing something or have done something wrong.

    Thanks in advance
     

    Attached Files:

    Last edited: Feb 11, 2023
  2. Offline

    Strahan

    Well, you can go into spigot.yml and set
    Code:
    commands:
      send-namespaced: false
    but that will stop all namespaced commands. Unsure of the method to target just a specific command off the top of my head. But if you don't care about that, then that is one possible solution.
     
  3. Offline

    ADX20

    Thanks, that helped me a lot. I initially thought it had to do something with my code
     
    Strahan likes this.
Thread Status:
Not open for further replies.

Share This Page