[SOLVED] Mapping Values Are Not Allowed Here: Configuration Issues

Discussion in 'Plugin Development' started by np98765, Sep 4, 2012.

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

    Sagacious_Zed Bukkit Docs

    depending on what stringObject is, it may return true....
     
  2. Offline

    PandazNWafflez

    If you compare stringObject == stringObject1 it could be true, but he is defining a new String in his, so as I said
    Code:
    stringObject == "NEW STRING WITH QUOTATION MARKS"
    will be false.
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    Code:
    public class Main {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            String stringObject = "string";
            
            System.out.println(stringObject == "string");
        }
    
    }
    compile and run this class and tell me what it returns ;)

    Show Spoiler
    On my jvm it returns true thus 'stringObject == string' does not always return false.
     
  4. Offline

    mavis



    Indentations are very important in YAML. This would be a correct YAML:
    Code:
    grenades:
        egg:
            grenade-radius: 10
            grenade-effect: 'confusion'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10
    When in doubt, use a YAML parser (like this one) to quickly find YAML formatting errors.


    Also, the accepted method in Java for string value comparisons is definitely to use the equals() method. If case doesn't matter, you could use .equalsIgnoreCase()
    Code:
    String s = "Some String";
     
    if (s.equalsIgnoreCase("some string")) {
        // strings match -- case insensitive
    }
    else if (s.equals("Some String")) {
        // strings match -- case sensitive
    }
    else {
        // no match
    }
    

    Also, in Java, Strings are immutable objects, so String s = "some string" and String s1 = "some string" are the same object even if they were instantiated separately.
     
  5. Offline

    WarmakerT

    Plugin is null

    public class_name(main_Class instance){
    plugin = instance;
    }
     
  6. Offline

    np98765

    -_-
     
  7. Offline

    WarmakerT

    Didn't read the whole thread X3
    this.getServer().getPluginManager().registerEvents(new EggListener(this), this);
     
  8. Offline

    np98765

    This is why I am so lost and utterly annoyed. :'(
     
  9. Offline

    WarmakerT

    Fine D: I'll read the thread. :p
     
    np98765 likes this.
  10. Offline

    np98765

    I meant that as an "I've tried (almost) everything possible". :p

    But do read the thread. ^_^
     
  11. Offline

    WarmakerT

    It'd be helpful if you told us what exactly is null.
    The plugin variable, the config, or the string.
     
  12. Offline

    np98765

    Sure, let me add some messages.

    I'm thinking that I did something wrong outside of the actual code...

    WarmakerT

    Here are the results of:
    Code:
     
    System.out.println("1");
    System.out.println(plugin.getConfig().getKeys(false));
    System.out.println(plugin);
    System.out.println(plugin.getConfig().getInt("grenades.egg.grenade-effect"));
    

    Error (open)

    Code:
     
     
    18:09:26 [INFO] 1
    18:09:26 [SEVERE] Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: mapping values are not allowed here
     in "<string>", line 4, column 31:
                    confusion-duration: 10
                                      ^
     
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55)
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:138)
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:202)
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:121)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    at com.lavacraftserver.UltimateGrenades.EggListener.onProjectileHit(EggListener.java:35)
    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$1.execute(JavaPluginLoader.java:330)
    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.EntityProjectile.h_(EntityProjectile.java:159)
    at net.minecraft.server.World.entityJoinedWorld(World.java:1239)
    at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:498)
    at net.minecraft.server.World.playerJoinedWorld(World.java:1221)
    at net.minecraft.server.World.tickEntities(World.java:1119)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: mapping values are not allowed here
     in "<string>", line 4, column 31:
                    confusion-duration: 10
                                      ^
     
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:733)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:305)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:563)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:230)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:123)
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:53)
    ... 23 more
    18:09:26 [INFO] [grenades]
    18:09:26 [INFO] UltimateGrenades v1.0
    18:09:26 [INFO] confusion
     
    


    The config looks like:

    Code:
     
    grenades:
        egg:
            grenade-radius: 10
            grenade-effect: 'confusion'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10     
     
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  13. Offline

    WarmakerT

    No idea =\
     
  14. Offline

    np98765

    Do you know what a mapping value is? I've run this through two YAML parsers, and I haven't gotten an error. Everything looks right, and I really have no clue what to do... I've been telling someone that I'll get this plugin out for almost a week now, and I'm getting kind of annoyed and really frustrated...
     
  15. Offline

    WarmakerT

    http://forums.bukkit.org/threads/solved-mapping-values-are-not-allowed-here.30798/
     
  16. Offline

    np98765

    Already tried that, same thing. -_-

    Code:
    #This is an awesome plugin!
    grenades:
        egg:
            grenade-radius: 10
            grenade-effect: 'confusion'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10
     
    
    EDIT: As in the first-line-comment thing, right? I took that literally. The original reason was because the OP didn't comment his comment. I don't have any comments, but I still tried..
     
  17. Offline

    WarmakerT

    Post the WHOLE configuration file.
     
  18. Offline

    np98765

    That is the whole configuration... ?
     
  19. Offline

    WarmakerT

    Ow. Small :p
    Edit.:
    Code:yml
    1. grenades:
    2. egg:
    3. grenade-radius: 10
    4. grenade-effect: 'confusion'
    5. blindness-duration: 10
    6. burn-time: 10
     
  20. Offline

    np98765

    Yeah, it was originally

    Code:
    #This is an awesome plugin!
    grenades:
        egg:
            grenade-radius: 10
            grenade-effect: 'confusion'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10
        snowball:
            grenade-radius: 10
            grenade-effect: 'blindness'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10  
        enderpearl:
            grenade-radius: 10
            grenade-effect: 'burn'
            confusion-duration: 10
            blindness-duration: 10
            burn-time: 10   
    
    but I removed the other parts so I could focus on the egg one.
     
  21. Offline

    WarmakerT

    I think it's incorrectly formatted, try this:
    Code:yaml
    1.  
    2. grenades:
    3. egg:
    4. grenade-radius: 10
    5. grenade-effect: 'confusion'
    6. blindness-duration: 10
    7. burn-time: 10
    8. snowball:
    9. grenade-radius: 10
    10. grenade-effect: 'burn'
    11. confusion-duration: 10
    12. blindness-duration: 10
    13. burn-time: 10
    14. enderpearl:
    15. grenade-radius: 10
    16. grenade-effect: 'burn'
    17. confusion-duration: 10
    18. blindness-duration: 10
    19. burn-time: 10
    20.  
     
  22. Offline

    np98765

    I tried doing that before, and it didn't work... But I'm willing to try it 50 times if it will eventually work. -_-
     
  23. Offline

    WarmakerT

    Ok, great then! Tell me if it works! [​IMG]
     
  24. Offline

    np98765

    WarmakerT

    Here are the results....
    Show Spoiler

    Code:
    18:39:45 [INFO] 1
    18:39:45 [SEVERE] Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: mapping values are not allowed here
    in "<string>", line 4, column 31:
                    confusion-duration: 10
                                      ^
     
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55)
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:138)
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:202)
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:121)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    at com.lavacraftserver.UltimateGrenades.EggListener.onProjectileHit(EggListener.java:35)
    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$1.execute(JavaPluginLoader.java:330)
    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.EntityProjectile.h_(EntityProjectile.java:159)
    at net.minecraft.server.World.entityJoinedWorld(World.java:1239)
    at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:498)
    at net.minecraft.server.World.playerJoinedWorld(World.java:1221)
    at net.minecraft.server.World.tickEntities(World.java:1119)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: mapping values are not allowed here
    in "<string>", line 4, column 31:
                    confusion-duration: 10
                                      ^
     
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:733)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:305)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:563)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:230)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
    at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:123)
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:53)
    ... 23 more
    18:39:45 [INFO] [grenades]
    18:39:45 [INFO] UltimateGrenades v1.0
    18:39:45 [INFO] confusion
    
     
  25. Offline

    WarmakerT

    The rest of the prints worked, so go on :D XD
     
  26. Offline

    np98765

    The rest of the prints worked before, too. ^_^

     
  27. Offline

    Sagacious_Zed Bukkit Docs

    You should not have to single quote strings.
     
  28. Offline

    mavis

    Are you absolutely sure that you're using spaces for indentation in your config file and not tabs?

    It seems like that error is pointing out a problem with the formatting of your config file. If you aren't already, be sure you're using an editor that will show you all the whitespaces and tabs. Any good editor/IDE will do this. Eclipse will do it and so will Notepad++. Hell, even Microsoft Word will work for that purpose.

    You may also want to set the editor's option to insert spaces when you press the tab key to prevent formatting flubs.

    The number of spaces indenting a level don't matter. It only matters that they are actually spaces and that all the entries at a given level are indented exactly the same.

    Here I'm using tildes (~) to indicate spaces and I'm using a consistent 2 spaces per level indentation.
    Code:
    grenades:
    ~~egg:
    ~~~~grenade-radius:~10
    ~~~~grenade-effect:~'confusion'
    ~~~~confusion-duration:~10
    ~~~~blindness-duration:~10
    ~~~~burn-time:~10
    ~~snowball:
    ~~~~grenade-radius:~24
    ~~~~grenade-effect:~'blindness'
    ~~~~blindness-duration:~16
    
    The space after a colon is also very important in YAML.


    On a style and good practice note: I'm confused as to why you have all three of "confusion-duration", "blindness-duration", and "burn-time" for each section when it seems that two of those won't be needed at all when there is only a single effect, i.e. - confusion. If there's a reason it's just not obvious to me. :D

    As to Zed's remark about strings: I may be wrong, but I think it is actually the case (in YAML) that one doesn't need to enclose EVERY string in quotes, but some may need to be depending on their contents. In this case I believe he is correct that the string in question should not require quotes.
     
  29. Offline

    np98765

    Sagacious_Zed: I've tried without the single quotes, yet I'll try again.
    mavis: I'm absolutely positive I'm using spaces. I've written half a dozen configs before, and never encountered a problem -- And I've edited enough plugin configs to know that YAML doesn't like tabs.
    I actually prefer using 2 spaces, I just tried 4 because I was trying everything that could possibly causing an issue.

    I did put spaces after the colons...?

    I have those three because this plugin will be publicly released -- The user can define which effect goes to which grenade, so I need all of the settings there (unless I make them add it in themselves).
    As far as I know, having extra unused lines in the config doesn't ruin anything as long as they're formatted correctly, correct?
    And, I will eventually be turning that into a string list, so the user can add as many effects as they desire. So I do need all of those there unless I want the user to manually type the ones they need.
     
  30. Offline

    mavis

    Yeah, I don't think it will hurt anything to have unused entries there. Just my preference, but I feel that it would be better to document your config format quite well for your users' benefit and do away with the unused lines, but that's just my opinion/preference.
     
Thread Status:
Not open for further replies.

Share This Page