An Error Occured When Enabling My Plugin

Discussion in 'Plugin Development' started by KingOfTheEast01, Dec 18, 2016.

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

    KingOfTheEast01

    Hey there, this is my first attempt at programming an actual plugin. I know some basics about Java coding and understand most of the code I have used to make this plugin.

    Now on to the problem. For some reason, whenever I run my server, I receive the following error concerning my plugin:
    Console Error Message (open)

    [19:05:38] [Server thread/INFO]: [EastmanSystem] Enabling EastmanSystem v1.0
    [19:05:38] [Server thread/INFO]: Eastman System: Ello mate! SIO1 is now at full capacity and ready to operate!.
    [19:05:38] [Server thread/ERROR]: Error occurred while enabling EastmanSystem v1.0 (Is it up to date?)
    java.lang.NullPointerException
    at me.LucasEastman.System1IO.SIOM.onEnable(SIOM.java:12) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:329) [craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:360) [craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:322) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.t(MinecraftServer.java:411) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.l(MinecraftServer.java:372) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.a(MinecraftServer.java:327) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:244) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:521) [craftbukkit.jar:git-Bukkit-7f31326]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    [19:05:38] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:05:38] [Server thread/INFO]: Done (6.083s)! For help, type "help" or "?"
    [19:06:07] [User Authenticator #1/INFO]: UUID of player CallMeFilms is 99ccf02e-fcbe-428c-9c00-25a4c1f45a5d
    [19:06:08] [Server thread/INFO]: CallMeFilms[/127.0.0.1:58671] logged in with entity id 267 at ([world]208.79937256667463, 99.28197781731133, 617.1114011778654)
    [19:06:10] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2061ms behind, skipping 41 tick(s)
    [19:06:11] [Server thread/INFO]: CallMeFilms issued server command: /plugins
    [19:06:21] [Server thread/INFO]: CallMeFilms issued server command: /test
    [19:08:18] [Server thread/INFO]: CallMeFilms issued server command: /gamemode 0
    [19:08:18] [Server thread/INFO]: [CallMeFilms: Set own game mode to Survival Mode]
    [19:08:19] [Server thread/INFO]: CallMeFilms issued server command: /gamemode 1
    [19:08:19] [Server thread/INFO]: [CallMeFilms: Set own game mode to Creative Mode]
    [19:10:41] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2120ms behind, skipping 42 tick(s)


    Here is my plugins main class:

    Code:
    package me.LucasEastman.System1IO;
    
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.plugin.java.JavaPlugin;
    import me.LucasEastman.System1IO.Commands.SystemTest;
    
    public class SIOM extends JavaPlugin {
      
        public void onEnable() {
          
            System.out.println("Eastman System: Ello mate! SIO1 is now at full capacity and ready to operate!.");
            this.getCommand("test").setExecutor((CommandExecutor)new SystemTest());
          
        }
      
        public void onDisable() {
          
            System.out.println("Goodbye sir! SIO1 is now shutting down.");
          
        }
    
    }
    
    Here is a class for my "test" command:

    Code:
    package me.LucasEastman.System1IO.Commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class SystemTest implements CommandExecutor     {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          
            Player player = (Player) sender;
          
            if (sender instanceof Player){
              
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aTest Complete: The Eastman System if fully operational"));
              
            }
          
            else {
              
                sender.sendMessage("This test can not be ran be console personnel. Please try again in-game");
              
            }
          
            return false;
          
        }
    
    }
    
    Here is my plugins.yml file:
    Code:
    name: EastmanSystem
    version: 1.0
    main: me.LucasEastman.System1IO.SIOM
    description: A plugin built by Eastman Infinity to give you additional commands, abilities, extras, and more on your Minecraft server!
    
    commands:
       test:
          usage: /<command>
    Please help out, because I have tried a lot and nothing has done anything obviously. Thanks! :D

    -King (A New Plugin Coder)

    @mythbusterma. I noticed you were online when I was looking at another thread you posted in. I was wondering if you could help me with my problem. :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 18, 2016
  2. Online

    timtower Administrator Administrator Moderator

    @KingOfTheEast01 1. Don't log your own plugin in onEnable and onDisable, Bukkit does that for you already.
    2. Don't cast when you don't need to cast.
    3. What does getCommand return? Is there a value or is it null?
     
  3. Offline

    KingOfTheEast01

    For one, thanks for that tip. I didn't really think about the enable message when I made this. Secondly, could you specify the object I shouldn't be casting. And finally, getCommand returns null considering it allows the command to work from my SystemTest file that holds my "test" command.
     
  4. @KingOfTheEast01
    getCommand() only returns null if the command is not from that plugin, or has not been registered. This leads me to believe there is a problem with your plugin.yml. I notice you have a carriage return (is that even a word people use?..) between "description" and "commands". What happens if you remove it?
     
  5. Offline

    KingOfTheEast01

    This didn't have any effect on the plugin.
    I adjusted something in my code and now I only get an error in the console when I run the "/test" command. It also tells me in game there was some sort of error. Should I post the new error here too?
     
    Last edited: Dec 19, 2016
  6. this.getCommand("test").setExecutor((CommandExecutor)new SystemTest());, this line is the problem, you are casting command executor, remove this and it should work fine.
     
  7. Offline

    johnny boy

    Just goes to show a line of code can mess up everything! Remember to only cast if you need to!
     
  8. Offline

    KingOfTheEast01

    Alright, I'm gonna be honest here. I'm a little confused. How am I casting wrong and what exactly do I need to delete?
     
  9. Offline

    Zombie_Striker

    @KingOfTheEast01
    Delete the
    BTW: Don't create the player before even knowing if the sender is a player. Change
    TO

     
  10. Offline

    KingOfTheEast01

    So will the command still work if I remove the cast entirely? Also, thanks for the help with the sender.

    Edit: Ok, that actually worked, but now I have a new problem:

    New Error Message From Log (open)

    [20:21:43] [Server thread/INFO]: CallMeFilms issued server command: /test
    [20:21:43] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin EastmanSystem v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:628) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1278) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1138) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-7f31326]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-7f31326]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.Error: Unresolved compilation problem:
    String literal is not properly closed by a double-quote

    at me.LucasEastman.System1IO.Commands.SystemTest.onCommand(SystemTest.java:23) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-7f31326]
    ... 15 more

     
    Last edited: Dec 22, 2016
  11. Offline

    Zombie_Striker

    @KingOfTheEast01
    You did not close a double quote. Post updated code, and make sure you end every string with a double quote.
     
  12. Offline

    KingOfTheEast01

    Oh, sorry about that. Here's the updated code, but not much has changed. Also, I looked through and it doesn't look like I have any unclosed strings.

    Here it is:

    Code:
    package me.LucasEastman.System1IO.Commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class SystemTest implements CommandExecutor     {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (sender instanceof Player){
               
                Player player = (Player) sender;
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aTest Complete: The Eastman System if fully operational"));
               
            }
           
            else {
               
                sender.sendMessage("This test can not be ran be console personnel. Please try again in-game");
               
            }
           
            return true;
           
        }
    
    }
    
    And my main class:

    Code:
    package me.LucasEastman.System1IO;
    
    import org.bukkit.plugin.java.JavaPlugin;
    import me.LucasEastman.System1IO.Commands.SystemTest;
    
    public class SIOM extends JavaPlugin {
       
        public void onEnable() {
           
            System.out.println("Eastman System: Ello mate! SIO1 is now at full capacity and ready to operate!.");
           
        }
       
        public void onDisable() {
           
            System.out.println("Goodbye sir! SIO1 is now shutting down.");
           
        }
    
    }
    
    And finally my plugin.yml file:

    Code:
    name: EastmanSystem
    version: 1.0
    main: me.LucasEastman.System1IO.SIOM
    description: A plugin built by Eastman Plugins to give you additional commands, abilities, extras, and more on your Minecraft server!
    commands:
        test:
            description: Tests the functionality of the mother plugin.
            usage: /<command>
     
  13. Offline

    Zombie_Striker

    This is the line that it is causing the error. It may seem strange, but ChatColors are not Strings, even though they return string values when appended to existing strings. To fix this, add ""+ to the beginning of the line (so it looks like)
     
  14. Offline

    KingOfTheEast01

    Alright, that helps out a lot! XD That makes sense now. Lol Thanks mate! :D
     
  15. Offline

    Zombie_Striker

    @KingOfTheEast01
    If your problem has been solved, mark this thread as solved.
     
  16. Offline

    KingOfTheEast01

    Well, now it looks like I have a new problem on my hands. After adding the double quotes I received this error:

    New Error Message From Log (open)

    [16:40:13] [Server thread/INFO]: CallMeFilms issued server command: /test
    [16:40:13] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin EastmanSystem v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:628) ~[craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1278) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1138) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-7f31326]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-7f31326]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-7f31326]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.Error: Unresolved compilation problem:
    String literal is not properly closed by a double-quote

    at me.LucasEastman.System1IO.Commands.SystemTest.onCommand(SystemTest.java:23) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-7f31326]
    ... 15 more
    [16:40:16] [Server thread/WARN]: CallMeFilms moved too quickly! -0.38068647175603587,1.1795647764861172,10.121578728161012

     
  17. Offline

    Zombie_Striker

    @KingOfTheEast01
    The problem is with line 23. Can you removing or commenting-out that line?
     
  18. Offline

    KingOfTheEast01

    I don't understand. Line 23 of my code turned out to be the System.out.println in the else section of my if statement. Considering the error occurs when I, a player. run the command and the else statement is meant to respond to the console attempting to perform the command, the error must be being caused by something else in my code. I don't understand why the error message tells me to look at line 23. Is there any possibility something else might be wrong with my code?

    The error message gave me a reference to an org.bukkit file, but there was nothing on that line, but words that I couldn't understand.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 23, 2016
  19. Offline

    KingOfTheEast01

    I believe I'm within the requirements for another bump, considering it's been 24 hours. :D
     
  20. Offline

    mythbusterma

    @KingOfTheEast01

    Perhaps your compiled version that's running on the server is out of date with the version of your source code?
     
  21. Offline

    KingOfTheEast01

    Actually, my source code is from the jar file I created the Bukkit server with.
     
  22. Offline

    mythbusterma

    @KingOfTheEast01

    Try cleaning and rebuilding if you're using Eclipse.

    Also, you're never registering your listener.

    Don't listen to them, they have no clue what they're talking about. There is no reason you couldn't cast this before using it, as the cast is to the same type it needs, and changes nothing.
     
Thread Status:
Not open for further replies.

Share This Page