Solved Command failing to be executed. Nothings wrong..

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 31, 2016.

Thread Status:
Not open for further replies.
  1. Hey!

    When doing /ChatXFeatures nothing happens. It's not opening the inventory (GUI) (I've tried with a player.sendMessage and still doesn't work) There are no console errors.


    Code (Text):
    package GUI;

    import java.util.Arrays;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import me.DecisionsYT.Main;

    public class GUI implements CommandExecutor, Listener {

        Main plugin;
        ItemStack tab;

            public GUI(Main passedPlugin) {
                this.plugin = passedPlugin;
                tab = new ItemStack(Material.EMERALD_BLOCK);
                ItemMeta tabmeta = tab.getItemMeta();
                tabmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("GUI-Tab-Enabled")));
                tabmeta.setLore(Arrays.asList(new String[] { ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("GUI-Tab-Enabled-Lore")) }));
        public void onInvClick(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            if (e.getCurrentItem().isSimilar(tab)) {
            if (plugin.getConfig().getBoolean("Tab-Enabled")) {
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Tab-Disabled-GUI")));
                plugin.getConfig().set("Tab-Enabled", false);
                if (!plugin.getConfig().getBoolean("Tab-Enabled")) {
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Tab-Enabled-GUI")));
                    plugin.getConfig().set("Tab-Enabled", true);

        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            Inventory inv = Bukkit.getServer().createInventory(null, 54, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("GUI-Name")));
            Player player = (Player) sender;
            if (player.hasPermission("ChatX.GUI")) {
                inv.setItem(1, tab);
            return true;

    Code (Text):
    package me.DecisionsYT;

    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;

    import Broadcasting.Broadcast;
    import ChatChannels.DonorChat;
    import ChatChannels.StaffChat;
    import ChatFilter.AntiAdvertise;
    import ChatFilter.AntiSpam;
    import ChatFilter.AntiSwear;
    import ChatFilter.CmdSpy;
    import ChatFormat.ChatFormat;
    import ClearChat.ClearChat;
    import Events.Join;
    import Events.Quit;
    import Events.UnknownCommand;
    import GUI.GUI;
    import HelpCommand.Help;
    import Punishments.Kick;
    import ReloadConfig.Reload;
    import TabList.Tab;

    public class Main extends JavaPlugin implements Listener  {
        public void onEnable() {
              PluginManager pm = Bukkit.getServer().getPluginManager();
              CmdSpy cmdSpy = new CmdSpy(this);
              pm.registerEvents(this, this);
                  pm.registerEvents(new AntiSwear(this), this);
                  pm.registerEvents(cmdSpy, this);
                  pm.registerEvents(new Tab(this), this);
                  pm.registerEvents(new GUI(this), this);
                  pm.registerEvents(new Join(this), this);
                  pm.registerEvents(new Quit(this), this);  
                  pm.registerEvents(new AntiSpam(this), this);
                  pm.registerEvents(new ChatFormat(this), this);
                  pm.registerEvents(new AntiAdvertise(this), this);
                  pm.registerEvents(new UnknownCommand(this), this);
                  getCommand("SC").setExecutor(new StaffChat(this));
                  getCommand("StaffChat").setExecutor(new StaffChat(this));
                  getCommand("DC").setExecutor(new DonorChat(this));
                  getCommand("DonorChat").setExecutor(new DonorChat(this));
                  getCommand("ClearChat").setExecutor(new ClearChat(this));
                  getCommand("CC").setExecutor(new ClearChat(this));
                  getCommand("ChatX").setExecutor(new Help(this));
                  getCommand("Broadcast").setExecutor(new Broadcast(this));
                  getCommand("BC").setExecutor(new Broadcast(this));
                  //Reload Config
                  getCommand("ChatXReload").setExecutor(new Reload(this));
                  getCommand("Kick").setExecutor(new Kick(this));
                  getCommand("ChatXFeatures").setExecutor(new GUI(this));
              Bukkit.getServer().getConsoleSender().sendMessage("§b§lChatX has been enabled!");
        public void onDisable() {
            Bukkit.getServer().getConsoleSender().sendMessage("§b§lChatX has been disabled!");
  2. latiku


    well, where the fuck is the command?
  3. Look closely.

    It implements CommandExecutor. It gets registered in the MAIN class.
  4. latiku


    no, you look closely
    when is the getCommand#getName ever mentioned, usually it'd be
    Code (Java):
    yet, you don't have that line
  5. It doesn't need to be. You should only have that when your commands are in your Main class AKA the extends JavaPlugin one. This is a different way. In which you have a separate class for every single one of your commands. Also, why would all of my other commands registered exactly in the same way work.
    • Funny Funny x 1
  6. Relax... You're wrong. You don't need to check for the command name, since you're using setExecutor() the only time that onCommand will be executed is when the command it's registered to in the getCommand().setExecutor() line.

    As for the problem in the post, add debug statements at each if statement in the onCommand method & find out where it stops working, if it's executed at all.
  7. Thank you! At least someone hear is smart, and knows this stuff!

    As for debugging, will do!
    • Funny Funny x 1
  8. latiku


    oh, i find your message ironic because you didn't spell "here" right

    i'm dead.
  9. -_- Good!
    • Agree Agree x 1
    • Funny Funny x 1
  10. Dude, what's your problem? If you dont have anything helpful to say, get off the thread.
    • Funny Funny x 1
  11. Fixed it. I hadn't added an if (!player.hasPermission("ChatX.GUI")) {
    • Like Like x 1
Thread Status:
Not open for further replies.