'plugin' is returning null..

Discussion in 'Plugin Development' started by Codmikeg, Apr 5, 2013.

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

    Codmikeg

    Code:
    package me.Codmikeg.endHelmetTwo;
     
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.entity.Player;
     
    public class testDamage {
        endHelmetMain plugin;
     
        public testDamage(endHelmetMain plugin){
            this.plugin = plugin;
        }
     
        public void dealD(final Player player){
            if(player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.ADVENTURE){}
            else{
    //line 17            Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
                    public void run(){
                        player.sendMessage("Aye it works");
                    }
                }, 5, 20);
            }
        }
    }
    
    Line 17 returns null when called.. endHelmetMain is my main class.. could someone point to the issue thats right under my nose? I'll give you hugs. <3
     
  2. Post the stack trace and your main class where you initialize testDamage class and where you call the dealD method.

    Also, why are you checking if they're creative mode or adventure mode then going for else instead of just checking if they're survival mode ? :confused:
     
  3. Offline

    Codmikeg

    Code:
    package me.Codmikeg.endHelmetTwo;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class endHelmetMain extends JavaPlugin {
        public final Logger log = Logger.getLogger("Minecraft");
     
     
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(new endHelmetListener(this), this);
            getCommand("debugger").setExecutor(new endHelmetCommandExecutor(this));
            getCommand("debugstop").setExecutor(new endHelmetCommandExecutor(this));
       
       
        }
        @Override
        public void onDisable(){
       
        }
     
    }
    
    Thats my main class... cluttered right? ;D
    And I know I dont have any messages or stuff in the onEnable(), because I have no need for them yet.

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'debugger' in plugin End is Space 2.0 v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:187)
    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServer.java:523)
    at net.minecraft.server.v1_5_R2.PlayerConnection.handleCommand(PlayerConnection.java:966)
    at net.minecraft.server.v1_5_R2.PlayerConnection.chat(PlayerConnection.java:884)
    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:841)
    at net.minecraft.server.v1_5_R2.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:110)
    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:578)
    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:474)
    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:407)
    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    at org.bukkit.craftbukkit.v1_5_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:390)
    at org.bukkit.craftbukkit.v1_5_R2.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:119)
    at org.bukkit.craftbukkit.v1_5_R2.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:115)
    at me.Codmikeg.endHelmetTwo.testDamage.dealD(testDamage.java:16)
    at me.Codmikeg.endHelmetTwo.endHelmetCommandExecutor.onCommand(endHelmetCommandExecutor.java:23)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    And... good point on the gamemode comment. I think I should hold off on the drinks while I code.
     
  4. You still didn't show where you initialized testDamage class :} the "new testDamage(plugin);" bit.

    And the main class is ok, that logger is a bit wrong though, your plugin is not Minecraft so you should not log through that, you should use this.getLogger() instead (do not store that method as field, use it directly when needed), it also adds your plugin name as prefix.

    You should also follow general Java naming, objects (classes, enums, etc) should be named StartingWithUpperCase and the rest startingWithLowerCase (packages, variables, fields, etc)... oh and constants (enums, final static fields) should be ALL_UPPER_CASE :p ... it's all optional though, but it's recommended.
     
  5. Offline

    Codmikeg

    I PM'd you a link to the class with the initialization. Aswell as all the other classes.

    I apologize if its sloppy, I create stupid stuff to debug.

    And with the java naming.. I am not used to programming in java, Im still getting the hang of it! ahaha learning as I go. Im used to other languages though.
     
  6. I'm going to post the answer here as well, the problem was:
    Code:
    	endHelmetMain plugin;
    	testDamage d = new testDamage(plugin);
    
    At that point, "plugin" is not asigned, the new testDamage() needs to be used where "plugin" is asigned, in the constructor.
     
Thread Status:
Not open for further replies.

Share This Page