Config.yml and getConfig() problem

Discussion in 'Plugin Development' started by Gartenzaun, Dec 30, 2014.

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

    Gartenzaun

    Hello everybody,

    I have a problem with getting an Integer from my config.yml file.

    My code:

    Code:
    int x = JumpAndRunPlugin.plugin.getConfig().getInt("0.start.x");
    My config.yml file looks like that:

    Code:
    '0':
      start:
        x: 167
    I don't know why it doesn't work...

    Thank you for your answers.
     
  2. Offline

    sipsi133

  3. Offline

    Gartenzaun

    Do you mean the console errors?
     
  4. Offline

    xize

    @Gartenzaun

    He ments the console errors yes.

    on a other note could you show how you save it?

    from what I think what is going wrong is that you save it like:

    Code:
    int index = 0;
    config.set(index + ".yourpath", somethig); //starting with int litteral
    config.save();
    
    maybe you should try:
    Code:
    int index = 0;
    config.set(""+ index+".yourpath", somethig); //starting with litteral string
    config.save();
    
    Perhaps it doesn't change anything though, I rarely use ints at the begin of a yaml key so I would assume its being taken litterly by yaml thats why it also adds ' ' in your config, but ive heard from other people it should work as normal keys fine to so maby Im not making much sense there.
     
  5. Offline

    Gartenzaun

    Thanks for your answer, but it doesn't work too. The config looks always the same:

    Code:
    '0':
      start:
        x: 136
    Code:
    int i = this.getConfig().getInt("id." + args[1]);
                                //this works !
                                    Location startLocation = p.getLocation();
                                    Integer startX = startLocation.getBlockX();
    this.getConfig().set(i + ".start.x", startX);

    Code:
    30.12 14:22:05 [Server] INFO ... 13 more
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
    30.12 14:22:05 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
    30.12 14:22:05 [Server] INFO at sun.reflect.GeneratedMethodAccessor529.invoke(Unknown Source) ~[?:?]
    30.12 14:22:05 [Server] INFO at gartenzaun.DruckplattenEventListener.onMove(DruckplattenEventListener.java:91) ~[?:?]
    30.12 14:22:05 [Server] INFO Caused by: java.lang.NullPointerException
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInPosition.handle(PacketPlayInPosition.java:35) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInFlying.a(SourceFile:137) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:249) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO org.bukkit.event.EventException
    30.12 14:22:05 [Server] ERROR Could not pass event PlayerMoveEvent to JumpAndRunPlugin v0.1
    30.12 14:22:05 [Server] INFO ... 13 more
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
    30.12 14:22:05 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
    30.12 14:22:05 [Server] INFO at sun.reflect.GeneratedMethodAccessor529.invoke(Unknown Source) ~[?:?]
    30.12 14:22:05 [Server] INFO at gartenzaun.DruckplattenEventListener.onMove(DruckplattenEventListener.java:91) ~[?:?]
    30.12 14:22:05 [Server] INFO Caused by: java.lang.NullPointerException
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInPosition.handle(PacketPlayInPosition.java:35) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInFlying.a(SourceFile:137) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:249) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    30.12 14:22:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    I tested my code and everything with the Event Listener works until I want to get the int startX from the config file...
     
  6. Offline

    xize

    @Gartenzaun

    which line is here: DruckplattenEventListener.java:91 the same as you mentoid on your snippet?

    try to use int instead of Integer, as Integer is more the reference type or Object Integers can be null whilst a int cannot.

    does this key exist in your config?: "id." + args[1] < the key name 'id', isn't that supposed to be a number?
     
  7. Offline

    gal0511Dev

    @Gartenzaun Do this:
    Instead of this:
    Code:
    int x = JumpAndRunPlugin.plugin.getConfig().getInt("0.start.x");
    You need to add this ,0 so just replace it with this:
    Code:
    int x = JumpAndRunPlugin.plugin.getConfig().getInt("0.start.x", 0);
     
    Last edited: Dec 30, 2014
  8. Offline

    1Rogue

    All that does is supply a default if the config is unable to get the value. It doesn't change the issue that he is still not retrieving the needed value.

    My guess is that "plugin" is null. You should not have a public static field that you access, pass your main class instance via constructor.
     
  9. Offline

    Gartenzaun

    Line 91 is that: JumpAndRunPlugin.plugin.reloadConfig();

    And my main class (snippet):
    Code:
    public class JumpAndRunPlugin extends JavaPlugin {
        public static JumpAndRunPlugin plugin;
        @Override
        public void onEnable() {
            configWerteLaden(); // is defined below
            new DruckplattenEventListener(this);
        }
        public void onDisable() {
            this.saveConfig();
        }
     
  10. Offline

    sipsi133

    @Gartenzaun your plugin variable is null, thats the problem.
     
  11. Offline

    Gartenzaun

    And how do I solve this problem? In my other plugins it worked...
     
  12. @Gartenzaun First off don't do it that way. Pass instance through a constructor. Second, if you are going to do it that way in onEnable do plugin = this; and in onDisable do plugin = null;
     
  13. Offline

    Gartenzaun

    Oh sry, I forgot this! Thank you!

    Everything works now. Thank you a lot !

    #closed
     
    Last edited: Dec 30, 2014
  14. Locked, per request.
     
Thread Status:
Not open for further replies.

Share This Page