Listener NullPointerException

Discussion in 'Plugin Development' started by Max9403, Feb 26, 2012.

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

    Max9403

    My code is for a friend of mine for custom logins, anyway i get NullPointerExceptions when I try and do anything to my custom config file, you can see where they happen cause everything is wrapped in a nice try catch. Here is my code:
    Show Spoiler
    Code:
    package net.sourceforge.users.max9403;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Animals;
    import org.bukkit.entity.Monster;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockDamageEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityTargetEvent;
    import org.bukkit.event.player.*;
     
    public class KickItPL implements Listener                                                                   
    {
        public KickIt plugin;
        public KickIt command;
     
        public KickItPL(KickIt plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            String Joiner = player.getName();
            try {
                if(plugin.getPlayerInfo().getBoolean("users."+Joiner+".kick")){
                        player.kickPlayer("You have been temporarily baned for typing your password wrong too many times");
                } else {
                player.sendMessage(ChatColor.RED+""+ChatColor.MAGIC+"-----------------------------------------------------");
                player.sendMessage(ChatColor.GREEN+                "                  Please Login or Register by typing:");
                player.sendMessage(ChatColor.GREEN+                "    /login [password] or /register [password] [password]");
                player.sendMessage(ChatColor.GREEN+                "                        No spaces are permited");
                player.sendMessage(ChatColor.RED+""+ChatColor.MAGIC+"-----------------------------------------------------");
                }
            } catch (NullPointerException e){
                player.sendMessage(ChatColor.RED+""+ChatColor.MAGIC+"-----------------------------------------------------");
                player.sendMessage(ChatColor.GREEN+                "                  Please Login or Register by typing:");
                player.sendMessage(ChatColor.GREEN+                "    /login [password] or /register [password] [password]");
                player.sendMessage(ChatColor.GREEN+                "                        No spaces are permited");
                player.sendMessage(ChatColor.RED+""+ChatColor.MAGIC+"-----------------------------------------------------");
            }
        }
    snip
    }
    
     
  2. Offline

    Daniel Heppner

    You're not providing enough information. What does the stack trace say?
     
  3. Offline

    Max9403

    it has only done this since they update the event system

    Code:
    11:18:37 [SEVERE] Could not pass event org.bukkit.event.player.PlayerChatEvent to Wild Logins
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1026)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:61)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:749)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:732)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:537)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1024)
    ... 11 more
    Caused by: java.lang.NullPointerException
    at net.sourceforge.users.max9403.KickItPL.onPlayerChat(KickItPL.java:242)
    ... 16 more
    
     
  4. also, your are missing the @EventHandler thiny ad PlayerPickupItemEvent





    Edit: you never defined plugin, aren't it?
     
  5. Offline

    Max9403

    I have
    Code:
    public KickIt plugin;
    thanks for telling me about PlayerPickipItem

    and I can edit fine from my Command Executor file
     
  6. Offline

    Daniel Heppner

    What's line 242 of KickItPl? Also, you might review the Java formatting standards. Your code has some formatting issues.
     
  7. Offline

    Max9403

    line 242 is
    Code:
    plugin.getPlayerInfo().getBoolean("users."+player.getName()+".logedin");
    but I seem to have forgotten to add plugin = instance; in:
    Code:
    public KickItPL(KickIt instance) {
            instance.getServer().getPluginManager().registerEvents(this, instance);
            plugin = instance;
        }
    seams I forgot to initialize pluign
    I guess that is what ferrybig meant

    seems I got confused when I read the new event system

    Runs perfect now

    now I need to get the message that shows not to appear twice when they join the world
     
    ZNickq likes this.
Thread Status:
Not open for further replies.

Share This Page