Solved My Plugin's Command wont work

Discussion in 'Plugin Development' started by TekxWolf, Jul 12, 2015.

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

    TekxWolf

    So basically I'm making a plugin to do custom gui's (I know theres a plugin called SimpleGUI creator, its outdated and kept throwing errors on my console.

    But anyways, as the thread states my plugin's command won't work

    Main class code (open)

    Code:
    package io.github.TekxWolf.EasyGui;
    
    import static org.bukkit.ChatColor.BOLD;
    import static org.bukkit.ChatColor.DARK_AQUA;
    import static org.bukkit.ChatColor.DARK_GRAY;
    import static org.bukkit.ChatColor.GRAY;
    import static org.bukkit.ChatColor.RED;
    
    import java.io.File;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class EasyGui extends JavaPlugin{
        @Override
        public void onEnable(){
            File file = new File(getDataFolder(), "config.yml");
            if(!file.exists()) {
                try {
                    getConfig().options().copyDefaults(true);
                    saveConfig();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        @Override
        public void onDisable(){
           
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            final Player p = (Player) sender;
            String Command = this.getConfig().getString("Command");
            String CommandHelp = String.format("/EGui %s  - Initiates the gui", Command);
            String PluginPrefix = "" + DARK_GRAY + BOLD + "[" + DARK_AQUA + "EGui" + DARK_GRAY + BOLD + "]";
            String Version = "" + DARK_GRAY + BOLD + "[" + DARK_AQUA + "v0.01" + DARK_GRAY + BOLD + "]";
            Inventory Inv = Bukkit.createInventory(p, 54, "Inventory");
            if(cmd.getName().equalsIgnoreCase("egui")){
                if(args.length == 0){
                    p.sendMessage(PluginPrefix + GRAY + " Version " + Version);
                    return true;
                } else
                if(args[0].equalsIgnoreCase("info")){
                    p.sendMessage(
                        " "
                        + DARK_AQUA + "Plugin Name: EasyGui"
                        + DARK_AQUA + "Plugin Version: v0.01"
                        + DARK_AQUA + "Plugin page: [Insert URL here]"
                        + DARK_AQUA + "Like this plugin? Want to help me make more?"
                        + DARK_AQUA + "Donate to me here: [Insert URL Here]"
                        + " "
                    );
                    return true;
                } else
                if(args[0].equalsIgnoreCase("help")){
                    p.sendMessage(
                        DARK_AQUA + "---------- Welcome to EGui ----------"
                        + GRAY + "/EGui help  -  Shows this help page"
                        + GRAY + CommandHelp
                        + GRAY + "/EGui  - Shows plugin Version"
                        + GRAY + "/EGui info - Shows plugin information"
                        + DARK_AQUA + "-------------------------------------"
                    );
                    return true;
                } else
                if (args[0].equalsIgnoreCase(Command)){
                    for(int a= 1; a <= 54; a++){
                        //
                        String NamePath = String.format("Item%d.Name", a);
                        String Name = this.getConfig().getString(NamePath);
                        // Format the path to accordance with the integer 'a
                        // then get the string associated with the path
                        String AmountPath = String.format("Item%d.Amount", a);
                        int Amount = this.getConfig().getInt(AmountPath);
                        // Format the path to accordance with the integer 'a
                        // then get the string associated with the path
                        String LorePath = String.format("Item%d.Lore", a);
                        List<String> Lore = this.getConfig().getStringList(LorePath);
                        // Format the path to accordance with the integer 'a
                        // then get the string associated with the path'
                        String MaterialPath = String.format("Item%d.Lore", a);
                        Material material = Material.getMaterial(getConfig().getString(MaterialPath));
                        Inv.setItem(a, new CustomItem(material, Amount, Name, Lore));
                        // This is setting each item in its slot in accordance to the Config.yml
                    }
                    return true;
                } else
                if(args.length > 1){
                    p.sendMessage(PluginPrefix + RED + " Too many Arguments");
                    return true;
                } else {
                    p.sendMessage(PluginPrefix + RED + " Uknown Command. Please use '/EGui help' for a list of possible commands");
                    return true;
                }
            }
           
            return false;
        }
    }

    And heres my plugin.yml
    Code:
    name: EasyGui
    main: io.github.TekxWolf.EasyGui.EasyGui
    version: 0.01
    Commands:
      EGui:
        description: BaseCommand for EasyGui
        usage: /EGui
    When I try to run the command /EGui i get this
    Code:
    >egui
    [18:32:10 INFO]: Unknown command. Type "/help" for help.
    
    There's no Errors and as far as I can tell my plugin is set up properly...

    Any help is appreciated,
    Thanks in advance
     
  2. Offline

    mariosunny

    Have you checked your server console to ensure that your plugin was successfully loaded?
     
  3. Offline

    TekxWolf

    Positive
    Code:
    [20:13:48 INFO]: Preparing start region for level 0 (Seed: -8804380286814850783)
    [20:13:49 INFO]: Preparing spawn area: 7%
    [20:13:50 INFO]: Preparing spawn area: 40%
    [20:13:51 INFO]: Preparing spawn area: 69%
    [20:13:52 INFO]: Preparing spawn area: 91%
    [20:13:53 INFO]: Preparing start region for level 1 (Seed: -8804380286814850783)
    [20:13:54 INFO]: Preparing spawn area: 53%
    [20:13:54 INFO]: Preparing start region for level 2 (Seed: -8804380286814850783)
    [20:13:55 INFO]: [EasyGui] Enabling EasyGui v0.01
    [20:13:55 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:13:55 INFO]: Done (8.139s)! For help, type "help" or "?"
    >plugins
    [20:14:26 INFO]: Plugins (1): EasyGui
    
     
  4. Offline

    Creeperzombi3

    @TekxWolf
    Off Topic: but instead of
    Code:
    import static org.bukkit.ChatColor.BOLD;
    import static org.bukkit.ChatColor.DARK_AQUA;
    import static org.bukkit.ChatColor.DARK_GRAY;
    import static org.bukkit.ChatColor.GRAY;
    import static org.bukkit.ChatColor.RED;
    Use
    Code:
    import static org.bukkit.ChatColor.*;
    It's easier for me, maybe for you too =D
     
    Konato_K likes this.
  5. Offline

    TekxWolf

    Yea I was using Chatcolor.* , I guess eclipse changed it xD

    Can anyone useful actually help me find out how to fix this please? :'(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  6. Offline

    MOMOTHEREAL

    @TekxWolf
    Not entirely sure, but I think Plugin YAMLs are case sensitive, maybe? Try to change "Commands:" to "commands:".
     
    TekxWolf and Konato_K like this.
  7. Offline

    TekxWolf

    @MOMOTHEREAL
    I tried and tested, changing it to "commands:" made it unusable i believe because It wouldn't load after that
     
  8. Offline

    MOMOTHEREAL

    @TekxWolf What do you mean, made it unusable? Case sensitivity should not affect if the plugin is usable or not. I am 100% commands: would work under normal circumstances (if you used Commands before, commands works too). This is not related to the "usability" of the thing.
     
    TekxWolf likes this.
  9. Offline

    Konato_K

    @TekxWolf Then post the stacktrace and read what it says
     
  10. Offline

    MOMOTHEREAL

    @Konato_K
    If there were to be an error related to the YAML, it would have been thrown while the plugin was enabling.
     
  11. Offline

    Konato_K

    @MOMOTHEREAL The time is the same as the log you posted previously, your computer has coincidentially taken the same amount of time as before or you're using an old log, put an update log (the one with the lowercase "commands" in YML)
     
  12. Offline

    TekxWolf

    Okay so I discovered the error, @MOMOTHEREAL the plugin.yml was in error but it was more than the "commands:"

    I redid it and added a description and changed the actual command to lowercase and the commands to lower, and wala: works!

    Sorry for ever doubting you. thank you :)
     
  13. Offline

    MOMOTHEREAL

Thread Status:
Not open for further replies.

Share This Page