A bug I can't squash...

Discussion in 'Plugin Development' started by Mike1022, Dec 4, 2013.

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

    Mike1022

    Hello all!

    This is my first time making a plugin and I am about to finish it! :D I have compiled it and made it into a jar. There is just one problem. I when I load it onto my plugin testing server, I get an error.

    Error:

    2013-12-04 08:59:11 [INFO] This server is running CraftBukkit version git-Bukkit-1.6.4-R2.0-b2918jnks (MC: 1.6.4) (Implementing API version 1.6.4-R2.0)
    2013-12-04 08:59:11 [SEVERE] Could not load 'plugins/Lagtest.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: com.castlecraft1.BukkitProject1
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugins(CraftServer.java:241)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(CraftServer.java:219)
    at net.minecraft.server.v1_6_R3.PlayerList.<init>(PlayerList.java:56)
    at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.java:107)
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:393)
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.ClassNotFoundException: com.castlecraft1.BukkitProject1
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
    ... 9 more
    I think it has something to do with the server thinking that there is no class file. The problem is, there is a class file.
    Here is the source code:
    Code:java
    1. package com.castlecraft1.BukkitProject1;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public final class MainClass extends JavaPlugin{
    10.  
    11. private static final String commandLabel = null;
    12.  
    13. @Override
    14. public void onEnable(){
    15. getLogger().info("onEnable has been invoked!");}
    16.  
    17. @Override
    18. public void onDisable() {
    19. getLogger().info("onDisable has been invoked!");}
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    22. Player player = (Player) sender;
    23. if (commandLabel.equalsIgnoreCase("Lagtest")){
    24. player.sendMessage(ChatColor.GREEN + "Lag test complete.");
    25. }
    26. return false;
    27.  
    28. }}
    29.  
    30.  
    31.  


    Code:java
    1. My plugin.ymlname: Lagtest
    2. main: com.castlecraft1.BukkitProject1
    3. version: 0.0.1
    4. commands:
    5. Lagtest:
    6. description: Tests for lag
    7. usage: /Lagtest
    8. permission: test.lagtest
    9. permission-message: You don't have permission to use the command!
    10.  


    Thanks for any help!

    - Mike1022
     
  2. Offline

    The_Coder

    Change main in plugin.yml to this:
    com.castlecraft1.BukkitProject1.MainClass
     
  3. Offline

    Mike1022

    Ok now the plugin loaded. But now I have this problem when I try to do /lagtest:

    Code:java
    1. 14:29:03 [SEVERE] null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'lagtest' in plugin Lagtest v0.0.1
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    5. at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:528)
    6. at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:968)
    7. at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:886)
    8. at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:837)
    9. at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    10. at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    11. at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    12. at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    13. at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    14. at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    15. at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    16. at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    17. at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    18. at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    19. Caused by: java.lang.NullPointerException
    20. at com.castlecraft1.BukkitProject1.MainClass.onCommand(MainClass.java:23)
    21. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    22. ... 15 more
    23.  
     
  4. Offline

    The_Coder

    Well just a little tip. Don't cast to a player without checking if they are a player first. That may be the problem. Also there is not commandLabel variable just use label or cmd.
     
  5. Offline

    RealDope

    Don't try to follow the tutorial word for word (using the variable commandLabel..) if you aren't going to consistently do so. You changed the method declaration to using label instead of commandLabel.
     
  6. Offline

    Mike1022

    Sorry, I am fairly new to Java. I don't know what you mean by "Don't cast to a player without checking if they are a player first." Also, when I use cmd or label, it Eclipse gives me a syntax error.
     
  7. Offline

    The_Coder

    Casting a object to another object example:
    Code:java
    1. Player player = (Player) sender;

    You are casting player to sender. So what if the console used this command you would get an error. As for the label do:
    Code:java
    1. if(label.equalsIgnoreCase("what ever")) {
    2. //Stuff
    3. }
     
  8. Offline

    Mike1022

    Ok, thanks for all your help! 1 more question, so when I do /Lagtest in-game. It says Lagtest complete, (Like it's supposed to.) but under that it says /Lagtest.
     
  9. Offline

    iiHeroo


    Probably because you enabled the usage in the plugin.yml
     
  10. Offline

    The_Coder

    because you aren't checking any of the arguments.
    Code:
    //If command equals /Lagtest in-game
    if(args[0].equalsIngoreCase("in-game")) {
        //Do stuff
    }
     
  11. Offline

    sgavster

    The_Coder [​IMG]

    Mike1022

    You need to return true; under the bracket after you send the message
     
    Max_The_Link_Fan likes this.
  12. Offline

    _Filip

  13. Offline

    cummo15

    Mike1022 You should not check the commands label but the actual command its self with cmd.getName().
     
Thread Status:
Not open for further replies.

Share This Page