NPE

Discussion in 'Plugin Development' started by mastermustard, Feb 17, 2013.

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

    mastermustard

    Hello everyone in my plugin controlledcreative, when i utilize one of the events it gives an NPE. It comes from the line on which i call out the config. this goes for all events with the same error.

    Item Drop event:
    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void ItemDrop(PlayerDropItemEvent event){
            Player player = event.getPlayer();
       
            if(!(player.hasPermission(DB))){
                if(player.getGameMode() == GameMode.CREATIVE){
                    boolean drop = plugin.getConfig().getBoolean("Allow-Item-Drop"); //error here(line 69)
                    if(!drop){
                    event.getItemDrop().getItemStack().getType();
                        event.setCancelled(true);
                    }
                   
                }
            }
        }
    Main:
    Code:
    package com.gmail.btincher99;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class controlledcreative extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has been disabled");
        }
     
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion()");
            Bukkit.getServer().getPluginManager().registerEvents(new  CCBlockListener(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new  CCPlayerListener(), this);
            PluginManager pm = this.getServer().getPluginManager();
             
            pm.addPermission(new CCBlockListener().BLB);
            pm.addPermission(new CCBlockListener().BUB);
           
            pm.addPermission(new CCPlayerListener().AB);
            pm.addPermission(new CCPlayerListener().DB);
            pm.addPermission(new CCPlayerListener().IB);
           
            getConfig().options().copyDefaults(true);
            saveConfig();
       
        }
    }
    config:
    Code:
    Allow-Creative-PvP: false
    Allow-Flying-PvP: false 
    Allow-Item-Drop: false 
    Allow-Chest-Interact: false 
    Allow-Crafting: false 
    Allow-Dispenser-Interact: false 
    Allow-Furnace-Interact: false 
    Allow-Enchanting: false
    Allow-EndChest-Interact: false
    Allow-Brewing: false 
    Allow-Anvil-Interact: false 
    Allow-Beacon-Interact: false 
    Allow-Villager-Trading: false 
    Allow-Bedrock: false
    Allow-Lava: false
    Allow-Beacon-Place: false
    Allow-Water: false
    Allow-TnT-Place: false
    Error:
    Code:
    [SEVERE] Could not pass event PlayerDropItemEvent to ControlledCreative v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.v1_4_R1.EntityHuman.a(EntityHuman.java:441)
        at net.minecraft.server.v1_4_R1.EntityHuman.drop(EntityHuman.java:403)
        at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:1310)
        at net.minecraft.server.v1_4_R1.Packet107SetCreativeSlot.handle(SourceFile:21)
        at net.minecraft.server.v1_4_R1.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.v1_4_R1.PlayerConnection.d(PlayerConnection.java:113)
        at net.minecraft.server.v1_4_R1.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
        at com.gmail.btincher99.CCPlayerListener.ItemDrop(CCPlayerListener.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 16 more
     
  2. Offline

    raGan.

    Variable plugin on that line is null. (I'm 99% sure)
     
  3. Offline

    mastermustard

    tis its not (or shouldnt be) heres the full code for that listener http://pastie.org/6208079
     
  4. Offline

    raGan.

    You are calling wrong constructor when registering listener. Yes it is.
     
  5. Offline

    mastermustard

    so would i change in the onEnable() or in the Listener
     
  6. Offline

    raGan.

    You are calling wrong constructor (of the listener) when registering listener.
     
  7. Offline

    mastermustard

    would i change it to an "instance"?
     
  8. Offline

    raGan.

    You are calling wrong constructor (of the listener) when registering listener in onEnable().
     
  9. Offline

    mastermustard

    hmmph i seriousely have no clue what to do ive gone over the wiki page still can't figure out what i should do...
     
  10. Offline

    raGan.

    What wiki page ? You are calling the wrong listener constructor. Do you know what that means ? You can start by googling "what is constructor in java".
     
    Deleted user likes this.
  11. Offline

    mastermustard

    i do know what it is... i just can't figure out what to change it to. and this is the page http://wiki.bukkit.org/Event_API_Reference
     
  12. Offline

    raGan.

    I told you everything you need to know. Identify constructors of your listener and see why plugin is null.
     
  13. Offline

    mastermustard

    I'm sorry but I've tried everything to fix this, I don't know what to do

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  14. Offline

    beastman3226

    Check you listener. Does it have a constructor? If so when you initialize your listener follow the constructor's parameters. If the problem persists delete your constructor and initialize it in the onEnable() like this:
    Code:java
    1. getServer().getPluginManager().registerEvents(new BlockBreakLoggerListener(), this);
     
  15. Offline

    Burnett1

    I couldnt see an onEnable and onDisable???
     
  16. Offline

    Deleted user

    Your listener is set up wrong.
    The end.

    It's in the Main class...
     
    chasechocolate likes this.
  17. Offline

    Burnett1

    oh lol didn't realize it was a separate class. Dum me.
     
Thread Status:
Not open for further replies.

Share This Page