Solved Bukkit Plugin Not Loading Correctly

Discussion in 'Plugin Development' started by AngryCupcake274, Dec 16, 2014.

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

    AngryCupcake274

    Hello, I have another problem I can't figure out.

    I just updated my server to the 1.8 build, and some of my plugins say they're out-of-date. I have added the new jarfile to the build path, and this error only occurs on the first load of the plugin. By this I mean that if I reload the server, I don't get the error. Here is the error I get that first time:
    Code:
    [19:11:13] [Server thread/INFO]: [cVoteList] Enabling cVoteList v1.2.6
    [19:11:13] [Server thread/ERROR]: Error occurred while enabling cVoteList v1.2.6 (Is it up to date?)
    java.lang.NullPointerException
        at me.AngryCupcake274.cVoteList.cVoteList.onEnable(cVoteList.java:21) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-6b061e2]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-6b061e2]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-6b061e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:340) [craftbukkit.jar:git-Bukkit-6b061e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-6b061e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-6b061e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-6b061e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-6b061e2]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-6b061e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:473) [craftbukkit.jar:git-Bukkit-6b061e2]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_60]
     
  2. Offline

    Jaaakee224

    Show us your code.
     
  3. Offline

    Skionz

    Then you are in the wrong section.
     
  4. Offline

    AngryCupcake274

    @Jaaakee224 here is my code:
    Code:
    package me.AngryCupcake274.cVoteList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class cVoteList extends JavaPlugin implements Listener {
        Server server = Bukkit.getServer();
        ConsoleCommandSender console = server.getConsoleSender();
        PluginDescriptionFile pdf = this.getDescription();
    
        @Override
        public void onEnable() {
            console.sendMessage(ChatColor.RED + "cVoteList " + ChatColor.GREEN
                    + pdf.getVersion() + ChatColor.AQUA + " Enabled!");
        }
    
        @Override
        public void onDisable() {
            console.sendMessage(ChatColor.RED + pdf.getName() + "cVoteList " + ChatColor.GREEN
                    + pdf.getVersion() + ChatColor.DARK_PURPLE + " Disabled!");
        }
    
        public boolean onCommand(CommandSender sender, Command cmd,
                String commandLabel, String[] args) {
    
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("vote")) {
                // player typed '/vote'
              
                if (p.hasPermission("cvotelist.vote")
                        || p.hasPermission("cvotelist.*") || p.hasPermission("*.*")) {
                    // player has permission
                  
                    p.sendMessage("");
    
                    p.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD
                            + "Click this link: " + ChatColor.DARK_PURPLE + ""
                            + ChatColor.BOLD + "Site 1: goo.gl/h9K0sb");
    
                    p.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD
                            + "Click this link: " + ChatColor.DARK_PURPLE + ""
                            + ChatColor.BOLD + "Site 2: goo.gl/p3eBDg");
    
                    p.sendMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD
                            + "Click this link: " + ChatColor.DARK_PURPLE + ""
                            + ChatColor.BOLD + "Site 3: goo.gl/KC9spQ");
    
                    p.sendMessage("");
    
                    return true;
                }
                p.sendMessage(ChatColor.RED + "You don't have permission!");
                return true;
            }
            return false;
        }
    }
    @Skionz I said that [I updated my server] noting that I updated my server, if that has anything to do with it. The main problem is the error I'm getting. I've gotten this error before, but this is a weird one. As I said, if I reload my server, I don't get the error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  5. Offline

    Skionz

    @AngryCupcake274 Initializing all of your variable onEnable will get rid of the NPE.
     
  6. Offline

    AngryCupcake274

    @Skionz what variables? There aren't any in my program unless you mean the
    Code:
    Server server = Bukkit.getServer();
    ConsoleCommandSender console = server.getConsoleSender();
    PluginDescriptionFile pdf = this.getDescription();
     
  7. Offline

    Skionz

  8. Offline

    AngryCupcake274

    @Skionz I don't seem to be getting an error, let me try another plugin to make sure....

    I don't seem to be getting any errors, I wont mark the thread as solved in case I'm wrong.

    Thank you all for all your help!

    P.S. I guess we know that Bukkit will be giving us some development issues with variables.
     
  9. Offline

    Skionz

    @AngryCupcake274 Honestly, I am not sure why it does this. Personally I have always initialized my variables inside the constructor rather then outside and I guess with Bukkit development I consider the onEnable method similar to a constructor.
     
  10. Offline

    AngryCupcake274

    @Skionz I have always put my variables just in the main class (like normal Java) but now I guess I'll have to get used to the new Bukkit style.

    Once again, thanks for your help!
     
Thread Status:
Not open for further replies.

Share This Page