1.16.5 CommandExecutor not working?

Discussion in 'Spigot Plugin Development' started by TheAspie_, Jul 8, 2021.

  1. This has happened to me a few times, and I have no idea why or how to fix it. CommandExecutor works... then it doesnt?
    Code (Text):

    import org.bukkit.*;
    import org.bukkit.command.*;
    import org.bukkit.entity.*;
    import org.bukkit.event.*;
    import org.bukkit.inventory.*;
    import org.bukkit.inventory.meta.*;

    import java.util.*;

    public class GUI implements CommandExecutor, Listener {

        public Inventory inv;

        Map<UUID, String> map = new HashMap<>();


        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(label.equalsIgnoreCase("choose")){
                if(!(sender instanceof Player)) {
                    sender.sendMessage("login");
                    return true;
                }
                Player player = (Player) sender;
            }
            return false;
        }
        public void createInv(){

            inv = Bukkit.createInventory(null, 9, "Inventory");

            ItemStack item = new ItemStack(Material.FIRE);
            ItemMeta meta = item.getItemMeta();


            meta.setDisplayName(ChatColor.RED + "FIRE");
            List <String> lore = new ArrayList<String>();
            lore.add("Fire");
            meta.setLore(lore);;
            item.setItemMeta(meta);
            inv.setItem(9, item );

            item.setType(Material.WITHER_SKELETON_SKULL);
            meta.setDisplayName(ChatColor.GRAY + "SKULL");
         }

    I hadn't finished it, so the end might be a bit abrupt, but I left my computer and when I started IntelliJ again, CommandExecutor was saying there was no onCommand method, and when I hit the Implement button it implemented
    Code (Text):
    @Override
        public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
            return false;
    but even that returned an error. Everything relating to the ItemStack returns an error (Material, Meta, even the creating of the Inventory), so do ChatColors. This is a very annoying issue, as everything I do retunrs an error, and the only fix I can find is just making a new project. Any help would be appreciated
     
  2. Please show console error.
     
  3. First off, do not return false if the operation succeeded. Also please post the error.
     
  4. There is no console error, that's the issue. IntelliJ is retunring an error, so I can't package it
     
  5. Which error, as I can't even package the plugin as IntelliJ is giving me errors, which I explained in the post
     
  6. It's your coding mistake, so why not check the tutorial again?
     
  7. I don't understand what you mean...?
     
  8. I recommend that you check the command tutorial.
     
  9. Which Tutorial are you reffering to? I don't see how that can help though, aseven if I remove all of the code, or even make a new class, the onCommand method is still not being recognised?
     
  10. You should get rid of the wild card imports first. Also if that actually is your whole class you are missing a bracket at the very end to mark the end of the class.
     
  11. I've done that, but not much has changed lol
     
    • Optimistic Optimistic x 1
  12. Then post the errors that IntelliJ is giving you o_O
     
    • Like Like x 1
  13. It tells me that the onCommand method needs to be implemented, and almost everything under that isn't recognised
     
  14. Try clicking implement methods
     
    • Funny Funny x 1
  15. I have. That still returns an error
     
  16. I have, as I detailed in the post.
     
  17. Remove the wild card imports, clean up the class or create a new one and let it implement CommandExecutor, then click implement methods and transfer the content from your old class one by one. If the error persists post your current code once again :)
     
  18. import org.bukkit.ChatColor;
    import org.bukkit.event.*;
    import org.bukkit.command.*;
    import org.bukkit.Material;

    import java.util.*;


    public class GUI2 implements CommandExecutor, Listener {


    @Override
    public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
    if (label.equalsIgnoreCase("choose")) {
    if (!(sender instanceof Player)) {
    sender.sendMessage("login");
    }
    Player player = (Player) sender;
    }


    public void createInv() {

    inv = Bukkit.createInventory(null, 9, "Inventory");

    ItemStack item = new ItemStack(Material.FIRE);
    ItemMeta meta = item.getItemMeta();


    meta.setDisplayName(ChatColor.RED + "FIRE");
    List<String> lore = new ArrayList<String>();
    lore.add("Fire");
    meta.setLore(lore);
    ;
    item.setItemMeta(meta);
    inv.setItem(9, item);

    item.setType(Material.WITHER_SKELETON_SKULL);
    meta.setDisplayName(ChatColor.GRAY + "SKULL");
    }

    return false;
    }
    }

    So from the above code, everything red returns an error, almost always either "cannot resolve symbol" or "cannot resolve method" and the imports just don't seem or work or something?
     
  19. That makes sense. can you post your pom.xml or build.gradle and check if org.spigotmc:spigot-api is present in your external libraries

    [​IMG]