Multiple command help

Discussion in 'Spigot Plugin Help' started by Teh_Matt_GRyt, Dec 26, 2017.

  1. Hi guys I started a plugin with permissions and config file!
    The permissions was easy to add but the config idk what happend and 2 commands arent working!
    Here is my main class and the two commands (Donate + Donators)

    Code (Text):
    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.Teh_Matt_GR.MyPlugin1.Commands.PluginInfo;
    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin {
       
        public String prefix = getConfig().getString("prefix");
               
        public void onEnable() {
            registerConfig();
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
           
            getCommand("plugininfo").setExecutor(new PluginInfo());
           
            logger.info(pdfFile.getName() + " Are succesfull enabled! - Plugin By Teh_Matt_GR! ("
                    + pdfFile.getVersion() + ")");
        }
       
        private void registerConfig() {
            getConfig().options().copyDefaults(true);
            saveConfig();
           
        }

        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
           
            logger.info(pdfFile.getName() + " Are succesfull disabled! - Plugin By Teh_Matt_GR! ("
                    + pdfFile.getVersion() + ")");

        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("donate"))
            if (!sender.hasPermission("Donates.donate")) {
                sender.sendMessage(ChatColor.RED + "You haven't permissions to do that!");
                return true;
        }
            if (!(sender instanceof Player)) {
                sender.sendMessage("You must be a player to use this command!");
                return false;
            }

            Player player = (Player) sender;

            player.sendMessage(new String[] {
                    ChatColor.BOLD + prefix + ChatColor.GREEN + "Donate to: " + ChatColor.RED + getConfig().getString("Donate")
                    + ChatColor.GREEN + " or from: " + ChatColor.RED + getConfig().getString("DonateSite")});
           
            return true;
        }
       
        public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("donators"))
            if (!sender.hasPermission("Donates.donators")) {
                sender.sendMessage(ChatColor.RED + "You haven't permissions to do that!");
                return true;
        }
            if (!(sender instanceof Player)) {
                sender.sendMessage("You must be a player to use this command!");
                return false;
            }

            Player player = (Player) sender;

            player.sendMessage(new String[] {
                    ChatColor.BOLD + prefix + ChatColor.GOLD + ChatColor.BOLD + " The top Donators are:",
                    ChatColor.DARK_GREEN + "1. " + getConfig().getString("TopDonator" + " $" + getConfig().getString("TopDonatorMoney" + "$")),
                    ChatColor.DARK_GREEN + "2. " + getConfig().getString("TopDonator2" + " $" + getConfig().getString("TopDonator2Money" + "$")),
                    ChatColor.DARK_GREEN + "3. " + getConfig().getString("TopDonator3" + " $" + getConfig().getString("TopDonator3Money" + "$")),
                    ChatColor.DARK_GREEN + "4. " + getConfig().getString("TopDonator4" + " $" + getConfig().getString("TopDonator4Money" + "$")),
                    ChatColor.DARK_GREEN + "5. " + getConfig().getString("TopDonator5" + " $" + getConfig().getString("TopDonator5Money" + "$"))});
           
            return true;
        }
    }
     
  2. Wrong Forum, should be in Spigot Plugin Development
     
  3. k... ill add it there :p
     
  4. Is this all in one class file?
    If so, I would suggest separating them into different class files for each command and registering them in the main class. It will be much more organized and easy to find the problem.