Solved Multiple command help

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

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

    Resource Staff

    i really like organization xD
    i organize almost everything xD
    i look at the main class for my private plugin
    only has three methods

    one to get instance

    onEnable

    onDisable

    onEnable only calls a class which deals with initialization of the plugin it's self, and that alone is split into various other classes just for the sake of being organized (plus it's easier to find things xD)
     
  2. You either have to make different classes that extends CommandExecutor and ask the Main class to read the command in ur on Enable code of u have to use
    Code (Text):
    {...} else if {... }
    Here:
    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;
        } else 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;
        }
    }
    Btw u might need to correct some things in this code, I tried to write in on mobile and it started getting confusing XD
     
Thread Status:
Not open for further replies.