Solved My plugin isn't loading (has to due with my code)

Discussion in 'Spigot Plugin Development' started by MinerDude010, Feb 9, 2017.

  1. So I made a simple plugin that clears the chat with a command, and has an automated broadcast message. My code exports from eclipse without any errors, but when I start my server it doesn't load the plugin. I have a plugin.yml and config.yml set up properly, (that I know for sure). But I'm pretty sure it's in my code. I just started learning Java literally yesterday so I don't know what the problem(s) is/are since there are no errors.

    Here's my code:

    Code (Text):
    package theFlameNetwork;

    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.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;

    public class TheFlameNetwork extends JavaPlugin {

    public int broadcastnumber = 0;



        public static Plugin plugin;

        public void Broadcasts() {
       
            final int time = getConfig().getInt("Time");
       
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(TheFlameNetwork.plugin, new Runnable() {
                public void run() {
                               
                    if (broadcastnumber == 0) {
                        int broadcasts = getConfig().getStringList("Broadcasts").size();
                        broadcastnumber = broadcasts;
                    }
               
                    String header = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Header"));
                    Bukkit.getServer().broadcastMessage(header);
               
                    String message = ChatColor.translateAlternateColorCodes('&', getConfig().getStringList("Broadcasts").get(broadcastnumber - 1));
                    Bukkit.getServer().broadcastMessage(message);
               
                    broadcastnumber = broadcastnumber - 1;
               
                }
            },0, 20 * time);
       
        }

        @Override
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
            System.out.println("[TheFlameNetwork] Plugins Loaded! -- Created by Gavin");
        }


        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
       
       
            //-----Clear Chat-----//
       
            if(cmd.getName().equalsIgnoreCase("cc")) {
                String clearMessage = getConfig().getString("clearMessage");
                    for(Player player : Bukkit.getOnlinePlayers())
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', clearMessage + " \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', clearMessage));
                }
               
       
            if(cmd.getName().equalsIgnoreCase("clearchat")) {
                String clearMessage = getConfig().getString("clearMessage");
                for(Player player : Bukkit.getOnlinePlayers())
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', clearMessage + " \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', clearMessage));
            }
       
            return false;
       
        }
    }
    Thank you very much in advance!
     
    #1 MinerDude010, Feb 9, 2017
    Last edited: Feb 9, 2017
  2. I'm not sure why. It might be repeating task may not be firing because your "plugin" variable hasn't had a value assigned to it. Use "this" because your class extends JavaPlugin. Like this:
    Code (Text):
     Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { ...
    instead of:
    Code (Text):
     Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(TheFlameNetwork.plugin, new Runnable() { ...
     
  3. Building on what @El_Chupe suggested (which is the correct, and more conventional way to do it), does your plugin not enable at all? Or is it when you enter the command?
     
  4. I changed it but the plugin is still not loading.
     
  5. It does not enable at all.
     
  6. Is it in the plugin list (/plugins)? Also, instead of writing clearchat code twice, just use an OR to check for both cc and clearchat (or list cc as an alias of clearchat in plugin.yml).

    Lastly, please refrain from double posting. If you need to amend your post, there's an edit button at your disposal :p
     
  7. Nope, not in the plugins list. And thx for the tips!
     
  8. Did you move/upload the .jar file to the right folder? Is it readable?
     
  9. Yes. It's in the plugins folder. Everything was working just fine before I added the timed broadcast code.
     
  10. did you create plugin.yml in the correct configuration and placement within your jar?
     
  11. Yes. Here's what it looks like:
    Code (Text):

    main: theFlameNetwork.theFlameNetwork
    version: 0.0.6
    name: TheFlameNetwork

    commands:
        clearchat:
            description: Clears the chat
        cc:
            description: Clears the chat (quicker to type)

    permissions:
        theflame.clearchat:
            default: op
     
     
  12. hmm, i would try working back to the moment you added something that made your plugin unloadable, and narrow it down to what causes the issue..
     
  13. "public class TheFlameNetwork"
    "main: theFlameNetwork.theFlameNetwork"

    Also: you should make your package names more unique to the project, so instead of just your network also what the plugin does (even if it's just the core you could do theFlameNetwork.core)
    That brings me to another note: package names should always be lowercased, so theflamenetwork.core
     
  14. Code (Text):
    package theFlameNetwork;
    nice.
     
  15. Try:
    Code (Java):

        public void Broadcasts() {
         
            final int time = getConfig().getInt("Time");
         
            new BukkitRunnable() {
                public void run() {
                                 
                    if (broadcastnumber == 0) {
                        int broadcasts = getConfig().getStringList("Broadcasts").size();
                        broadcastnumber = broadcasts;
                    }
                 
                    String header = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Header"));
                    Bukkit.getServer().broadcastMessage(header);
                 
                    String message = ChatColor.translateAlternateColorCodes('&', getConfig().getStringList("Broadcasts").get(broadcastnumber - 1));
                    Bukkit.getServer().broadcastMessage(message);
                 
                    broadcastnumber = broadcastnumber - 1;
                 
                }
            }.runTaskTimer(this, 0, 20*time)
         
        }
    try it, it may work
     
  16. Try:
    Code (Java):

        public void Broadcasts() {
         
            final int time = getConfig().getInt("Time");
         
            new BukkitRunnable() {
                public void run() {
                                 
                    if (broadcastnumber == 0) {
                        int broadcasts = getConfig().getStringList("Broadcasts").size();
                        broadcastnumber = broadcasts;
                    }
                 
                    String header = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Header"));
                    Bukkit.getServer().broadcastMessage(header);
                 
                    String message = ChatColor.translateAlternateColorCodes('&', getConfig().getStringList("Broadcasts").get(broadcastnumber - 1));
                    Bukkit.getServer().broadcastMessage(message);
                 
                    broadcastnumber = broadcastnumber - 1;
                 
                }
            }.runTaskTimer(this, 0, 20*time)
         
        }
    try it, it may work
     
  17. Also, apart from what everybody said... Where are you setting the value of `plugin`? Why are you using Plugin instead of your class name if it extends JavaPlugin? It doesn't have any sense...
     
  18. @Z3tr0nix that won't change a thing (also, [accidental] double post ;) )
     
  19. its a try...

     
  20. For god sake use a for loop