PlayerCount Plugin

Discussion in 'Plugin Development' started by gcop, Jul 21, 2017.

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

    gcop

    I cant figure out what is wrong with this plugin.. In the console when it loads into minecraft, the plugin cant load because the server can not find the Main. I dont know how to fix this..
    Code:
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin implements Listener{
          
        public static main plugin;
        @Override
        public void onEnable() {
            LoadConfiguration();
            plugin = this;
            System.out.println(this+" has been Enabled");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        @Override
        public void onDisable() {
            System.out.println(this+" has been Disabled");
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("list")) {
              
                //Main Command
                if(args.length == 0 && sender.hasPermission("orecloudplayercount.list")) {
                    List<String> words = plugin.getConfig().getStringList("orecloudplayercount.list");
                    String allplayers = "" + Bukkit.getOnlinePlayers() + "/" + Bukkit.getMaxPlayers();
                    int staffp = 0;
                    int donatorp = 0;
                    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
                    for (Player playerP : players) {
                        if (playerP.hasPermission("orecloudplayercount.staff")) {
                            staffp++;
                        }
                        if (playerP.hasPermission("orecloudplayercount.donator")) {
                            donatorp++;
                        }
                    }
                    String staffpp = "" + staffp;
                    String donatorpp = "" + donatorp;
                    for (String m : words) {
                        m = m.replaceAll("%allplayers%", allplayers);
                        m = m.replaceAll("%staff%", staffpp);
                        m = m.replaceAll("%donators%", donatorpp);
                        m = m.replaceAll("&([0-9a-fA-F])", "§$1");
                        sender.sendMessage(m);
                    }
                  
                  
                }else if (args.length == 1){
                  
                    //Reload
                    if (args[0].equalsIgnoreCase("reload") && sender.hasPermission("orecloudplayercount.reload")) {
                        getConfig();
                        reloadConfig();
                        getServer().getPluginManager().disablePlugin(plugin);
                        getServer().getPluginManager().enablePlugin(plugin);
                        sender.sendMessage(ChatColor.GREEN+"OreCloudPlayerCount Config Reloaded");
                    }
                } else if (args.length < 2) {
                    return false;
                }
            }
            return false;
        }
      
        public void LoadConfiguration() {
            List<String> words = new ArrayList<String>();
            String path = "orecloudplayercount.list";
            words.add("&3--------=[ &9OreCloud &3]=--------");
            words.add("&3There are &6(&e%allplayers%&6) &3players online.");
            words.add("&5Online staff: &d%staff%");
            words.add("&2Online Donators: &a%donators%");
            getConfig().addDefault(path, words);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    }
    Here is the plugin.yml:

    Code:
    main: me.gcop.orecloudplayercount.main
    name: OreCloudPlayerCount
    version: 1.0
    author: gcop
    description: Adds custom commands to the server.
    commands:
    list:
      description: Lists the PlayerCount.
      permission: orecloudplayercount.list
      permission-message: §cYou don’t have permission!
    Here is the config.yml:

    Code:
    OreCloudPlayerCount:
      list:
      - '&3--------=[ &9OreCloud &3]=--------'
      - '&3There are &6(&e%allplayers%&6) &3players online.'
      - '&5Online staff: &d%staff%'
      - '&2Online Donators: &a%donators%'
    
     
  2. Offline

    Davesan

    I cannot find the first line in your first code what I am looking for:
    Code:
    package me.gcop.orecloudplayercount;
    Which should be there, may you forgot to paste it too, although the imports are there... may you don't event use packaging..? Your class must be in the me.gcop.orecloudplayercount package.

    When you set up your plugin.yml file, to the 'main' you write it in <package>.<class> format. Also, start all your class names with UPPER case letters, always. So, do not use 'main' as the name as your main class, use "Main" instead.

    Please check if you are not using
    Code:
    me.gcop.orecloudplayercount.main
    as your package, and the full path would be then
    Code:
    me.gcop.orecloudplayercount.main.main
    I cannot think more currently, if you set the right path for the file containing your main class (which extends JavaPlugin), then it must load or throw a different exception, not that.

    You don't need to log that your plugin is enabled
     
Thread Status:
Not open for further replies.

Share This Page