Something Wrong with the Initialization

Discussion in 'Plugin Development' started by baugh70, Dec 8, 2013.

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

    baugh70

    Okay here is the code. I am having a problem with the onEnable() it seems as well as the initialization of the strings for the config values in EventListener.java.

    Main Class (Levels.java): http://pastebin.com/5JF3nUCV
    Listener Class (EventListener.java): http://pastebin.com/PgiJr7bm
     
  2. Offline

    reider45

    register the events in yourr onenable baugh70
     
  3. Offline

    baugh70

  4. Offline

    The_Doctor_123

    *Sigh*..
    Code:java
    1. public class EventListener extends JavaPlugin implements Listener{

    You cannot have more than one instance of JavaPlugin in a plugin.
     
    Cirno and reider45 like this.
  5. Offline

    baugh70

    Then how should I get the config values?
     
  6. Offline

    The_Doctor_123

    baugh70
    You use your plugin variable.
     
  7. Offline

    Wolfey

    Or you can use this:
    Code:java
    1.  
    2. Bukkit.getPluginManager().getPlugin("yourPluginName").getConfig().blahBlahBlah();
    3.  
     
  8. Offline

    The_Doctor_123

    Wolfey
    Why not just use the plugin variable..? It's there already.
     
  9. Offline

    Wolfey

    I just prefer this, it's much cleaner and nicer, I mean he doesn't have to use it since he already has the plugin variable, but you don't have to initialize anything with this.
     
  10. Offline

    baugh70

  11. Offline

    fireblast709

    baugh70 move all of the getConfig() initialization into the constructor and prefix them with plugin. So like
    Code:
    plugin.getConfig().getString("some.string");
     
  12. Offline

    baugh70

    fireblast709

    It's no longer an error with that, it is line 13 of Levels.java
     
  13. Offline

    fireblast709

    baugh70 update the code of the EventsListener class :3
     
  14. Offline

    baugh70

    fireblast709

    It's backwars cus I use multicraft, but this is the error.

    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:409)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.java:165)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.a(MinecraftServer.java:268)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.f(MinecraftServer.java:308)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.l(MinecraftServer.java:331)
    09.12 01:27:38 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:270)
    09.12 01:27:38 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:288)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    09.12 01:27:38 [Server] INFO at me.baugh70pkerb0y.Levels.Levels.onEnable(Levels.java:13)
    09.12 01:27:38 [Server] INFO at me.baugh70pkerb0y.Levels.eventlistener.EventListener.<init>(EventListener.java:20)
    09.12 01:27:38 [Server] INFO java.lang.NullPointerException

    EventListener.java line 20 is "private FileConfiguration config = Bukkit.getPluginManager().getPlugin("Levels").getConfig();"

    Levels.java line 13 is new EventListener(this);
     
  15. Offline

    The_Doctor_123

    baugh70
    Use your Levels instance reference named "plugin" to get the config instead.
     
  16. Offline

    baugh70

    In the constructor?

    The_Doctor_123

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  17. Offline

    fireblast709

    baugh70 yes in the constructor.
    Code:
    plugin.getConfig().otherMethods()
     
  18. Offline

    baugh70

    @ fireblast709
    But then the methods can't access it.

    Can anyone else see the problem?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  19. Offline

    L33m4n123

    Please post your updated code. Because the one that is on top of there is (hopefully) by now outdated since they told you how to fix quite a few things
     
  20. Offline

    baugh70

    Last edited by a moderator: Jun 5, 2016
  21. Offline

    L33m4n123

    And what exactly is your issue?
     
  22. Offline

    baugh70

    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:409)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.java:165)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.a(MinecraftServer.java:268)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.f(MinecraftServer.java:308)
    09.12 01:27:38 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.l(MinecraftServer.java:331)
    09.12 01:27:38 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:270)
    09.12 01:27:38 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:288)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
    09.12 01:27:38 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    09.12 01:27:38 [Server] INFO at me.baugh70pkerb0y.Levels.Levels.onEnable(Levels.java:13)
    09.12 01:27:38 [Server] INFO at me.baugh70pkerb0y.Levels.eventlistener.EventListener.<init>(EventListener.java:20)
    09.12 01:27:38 [Server] INFO java.lang.NullPointerException

    EventListener.java line 20 is "private FileConfiguration config = Bukkit.getPluginManager().getPlugin("Levels").getConfig();"

    Levels.java line 13 is new EventListener(this);

    L33m4n123

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  23. Offline

    Wolfey

    Can I see your plugin.yml really quick?
     
  24. Offline

    L33m4n123

    You get an NPE here

    Code:
    private FileConfiguration config = Bukkit.getPluginManager().getPlugin("Levels").getConfig();
    Looks or me like it has issues getting the Plugin called "Levels"
     
  25. Offline

    baugh70

    Code:
    name: Levels
    main: me.baugh70pkerb0y.Levels.Levels
    version: 1.0
    author: Baugh70
    description: Enchant with items and stuff
    permissions:
        levels.*:
            description: Get all commands!
            default: op
        levels.foodlevels:
            description: Enable food levels.
            default: true
        levels.foodlevels:
            description: Enable attack levels.
            default: true
        levels.itemenchanting:
            description: Enable item enchanting with items.
            default: true
    Wolfey

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  26. Offline

    L33m4n123

    The Only guess I have now is that new EventListener(this); gets called before it is fully enabled since it is still in the onEnable. I would suggest changing the constructor in the EventListener to

    Code:java
    1. public EventListener(Levels plugin){
    2. main = plugin;
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4.  
    5. }


    and change following

    Code:java
    1. private FileConfiguration config = Bukkit.getPluginManager().getPlugin("Levels").getConfig();


    to

    Code:java
    1. JavaPlugin main;
    2. private FileConfiguration config = main.getConfig();


    because it cannot get the Plugin when it is not enabled yet
     
Thread Status:
Not open for further replies.

Share This Page