Commands aren't working!

Discussion in 'Plugin Development' started by jmmalcolm3, Jan 22, 2015.

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

    jmmalcolm3

    Alright, so I've made plugins before, but by no means am I an expert. I have tried many, many things to get these simple commands to work, but every time I do the command, it comes up with the default unknown command message, but when I do it without the command name, nothing at all happens, and no errors show up in the console. I've tried both cmd.getName(), and commandLabel, and it doesn't work either way. I even tried copying and pasting it from another plugin I made, and still no success. So please, help.
    (P.S.) Please just tell me what is wrong with the commands, please don't criticize my way of doing unrelated things, unless it is constructive.
    Thanks!
    Main Class:
    Code:
    package me.Jamez.tgg;
    
    import java.io.File;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
        FileConfiguration config;
        FileConfiguration cfg = getConfig();
        FileConfigurationOptions cfgOptions = cfg.options();
        File cfile;
        int z = 1;
        public void onEnable(){
           
            config = getConfig();
            config.options().copyDefaults(true);
            saveConfig();
            cfile = new File(getDataFolder(), "config.yml");
            cfgOptions.header("Use amount for amount of gold each time.\r\nUse time for the amount of time in between in seconds.\r\nUse messagecolor for the color of the message\r\nUse message for the message sent each time to each player");
            cfgOptions.copyHeader(true);
            getLogger().info("Hey there, thanks for using my plugin!");
            Bukkit.getPluginManager().registerEvents(this, this);
            config = getConfig();
            config.options().copyDefaults(true);
            saveConfig();
            cfile = new File(getDataFolder(), "config.yml");
            getLogger().info("Gold Giver enabled!");
            Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
    if(sender instanceof Player){
                Player player = (Player) sender;
              
                if(cmd.getName().equalsIgnoreCase("tgg")){
                        if(args.length == 0){
                                player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.DARK_RED + "You have entered too little.");
                        }else{
                                if(args[0].equalsIgnoreCase("enable")){
                                    if(sender.hasPermission("tgg.enable")){
                                        player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.AQUA + "Started gold distribution");
                                        z ++;
                                         String t = getConfig().getString("time");
                                        int y = Integer.parseInt(t);
                                        getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                                             @SuppressWarnings("deprecation")
                                            @Override
                                             public void run() {
                                                String h = getConfig().getString("amount");
                                             int x = Integer.parseInt(h);
                                                 if(z == 2){
                                                    for (Player player : Bukkit.getOnlinePlayers()) {
                                                       if (player.hasPermission("goldgiver.get")) {
                                                          player.getInventory().addItem(new ItemStack(Material.GOLD_NUGGET, x));
                                                         player.sendMessage(ChatColor.translateAlternateColorCodes ('&', getConfig().getString("message") + (getConfig().getString("message"))));
                                                       }
                                                   }
                                                    
                                                 }
                                             }
                                         }, 20*y);
                                    }
                                    else{
                                        player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.DARK_RED + "Not enough permissions!");
                                    }
                                }
                                else if(args[0].equalsIgnoreCase("reload")){
                                    if(sender.hasPermission("tgg.reload")){
                                        config = YamlConfiguration.loadConfiguration(cfile);
                                        this.reloadConfig();
                                        player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + "TGG v 1.0 reloaded!");
                                }
                                    else{
                                        player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.DARK_RED + "Not enough permissions!");
                                    }
                                }
                                else if(args[0].equalsIgnoreCase("help")){
                                    if(sender.hasPermission("bounce.help")){
                                    player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] "+ ChatColor.DARK_AQUA + "TGG V 1.0 by YourPetHoboJoe");
                                    player.sendMessage(ChatColor.RED + "Do /tgg enable" + ChatColor.AQUA + " To enable gold distribution");
                                    player.sendMessage(ChatColor.RED + "Do /tgg disable" + ChatColor.AQUA + " To disable gold distribution");
                                    player.sendMessage(ChatColor.RED + "Do /tgg help" + ChatColor.AQUA + " To see this page");
                                    player.sendMessage(ChatColor.RED + "Do /tgg reload" + ChatColor.AQUA + " To reload the plugin");
                                }
                                    else{
                                        player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.DARK_RED + "Not enough permissions!");
                                    }
                        }
                                else if(args[0].equalsIgnoreCase("disable")){
                                if(sender.hasPermission("tgg.disable")){
                                       player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.RED + "Stopped gold distribution");                               
                                       }
                                else{
                                    player.sendMessage(ChatColor.BLUE + "[" + ChatColor.GOLD + "GoldGiver"+ ChatColor.BLUE + "] " + ChatColor.DARK_RED + "Not enough permissions!");
                                }
                }
                        }
                }
    }
                return false;
        }
    
    }
    
    Plugin.yml:
    Code:
    name: GoldGiver
    main: me.Jamez.tgg.Main
    version: 1.0
    commands:
        version:
            description: Shows the current version of the plugin
        help:
            description: Main help page
        reload:
            description: Reloads the plugin
        bounce:
            description: Bounces a player
        enable:
            description: Starts gold distribution
        disable:
            description: Ends gold distribution
     
  2. Offline

    Skionz

    @jmmalcolm3 Your command isn't registered. You registered the arguments as commands for some reason.
     
    87pen likes this.
  3. Offline

    87pen

  4. Offline

    jmmalcolm3

    @Skionz Isn't that what I wanted? I want the main command to be /tgg, and the sub commands to be like /tgg enable
     
    Last edited: Jan 22, 2015
  5. Offline

    Luke_Lax

    No, your command is '/tgg' right? So you'll want to register tgg - any arguments are dealt with in the command function and don't need to be registered.
     
  6. Offline

    Skionz

    No. There are plenty of tutorials that explain it.
     
  7. Offline

    Tecno_Wizard

    @jmmalcolm3, two words, learn java. I have nothing else to say. This is a mess.
     
    Luke_Lax likes this.
Thread Status:
Not open for further replies.

Share This Page