Solved Whats wrong?

Discussion in 'Plugin Development' started by stamline, Dec 10, 2015.

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

    stamline

    Whats wrong with this code. There is no Line where the error in the console.
    But I know its this class, because when I make it inactive it does not crash

    Here is the crash:
    HTML:
    [18:09:42] [Server thread/INFO]: [KitPVP] Enabling KitPVP v1.0
    [18:09:42] [Server thread/ERROR]: Error occurred while enabling KitPVP v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.albinmedoc.pvp.Events.Interact2.<init>(Interact2.java:21) ~[?:?]
        at me.albinmedoc.pvp.Main.RegisterEvents(Main.java:56) ~[?:?]
        at me.albinmedoc.pvp.Main.onEnable(Main.java:29) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:524) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    [18:09:42] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [18:09:42] [Server thread/INFO]: Done (3,084s)! For help, type "help" or "?"
    Code:
    public class Interact2 implements Listener {
    
        KitsManager kitmanager = new KitsManager(Main.plugin);
        FileConfiguration config    = Main.plugin.getConfig();
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Block b = event.getClickedBlock();
                if((b.getType() == Material.SIGN_POST) || b.getType() == Material.WALL_SIGN){
                    Sign s = (Sign) b.getState();
                    if(s.getLine(1).equals(ChatColor.RED + "[KIT]")){
                        if(kitmanager.kitexist(s.getLine(2).toLowerCase())){
                            kitmanager.giveKit(player, s.getLine(2).toLowerCase());
                        }
                    }else if(s.getLine(1).equals(ChatColor.RED + "[RandomLoc]")){
                        Listeners.randomloc(player);
                    }
                }
            }
        }
    }
    Sorry, I know the error, Its the config...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 10, 2015
  2. Offline

    mcdorli

    You should pass around a instance of the main class instead of having it static
     
  3. Offline

    mine-care

    A couple of things I noticed that require your attention:
    1. Do not abuse static!!!
    2. Encapsulate
    3. I wouldn't recomend naming classes like "listener" and "listener2" because although it doesn't affect performance, it is not old as a convention.
    4. Follow java naming conventions!
     
Thread Status:
Not open for further replies.

Share This Page