Solved String with dots as a key (config)

Discussion in 'Plugin Development' started by raGan., Mar 31, 2013.

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

    raGan.

    It probably sounds very stupid, but what should I do ? Best idea seems to be replacing all dots in key to something else, but I don't want to limit users in any way. (keys are generated) What do you do ?
     
  2. Offline

    stirante

    Maybe I'm just idiot but I don't understand what you wrote. Could you post simple example for people like me? :D
     
  3. Offline

    raGan.

    I want this key to be able to be stored as config key: "example.key". But it is interpreted as "example: key:" in config. I have kind of abstract storage system on top of that, which interprets keys the same way. I need to get rid of the dot without losing original state of that string, so "this.string" != "this.str.ing". I also do not want to lose ability to have other characters there. If I replaced all dots in keys with "#", I would not be able to translate it back to original string that contained both "#"s and dots.

    Edit: stirante
     
  4. Offline

    stirante

    I now understand, but i don't see any sense in trying to save it in this format. With dots I haven't tried but it can also read it wrong. Maybe just replace it to '-'.
     
  5. Offline

    raGan.

    stirante
    I can't do that, because I need to get original string back from the key.
    "this.super-string" would be changed to "this-super-string", and I wouldn't be able to tell if there were only dots or not. I need to make it work both ways.

    Edit: Keys are user input, and I want people to be able to use dots there.
     
  6. Offline

    stirante

    Try this(as always untested):
    Code:
    public void set(String node, String name, Object value){
            final char separator = getConfig().options().pathSeparator();
     
            ConfigurationSection subSection = getConfig().getConfigurationSection(node);
            if (subSection == null) {
           subSection = getConfig().createSection(node);
            }
            subSection.set(name, value);
    }
     
  7. Offline

    raGan.

    I'm not sure if you know what I mean. I need to have 0 subsections, I just need to make toKey(String s) and fromKey(String key) methods that change user input into valid key (no subkeys, only one layer) and then be able to change it back to it's original form. Maybe picking character that is not supported by MC. (I'll take a look at this)
     
  8. Offline

    stirante

    You can get through reflection variable map from MemorySection class from FileConfiguration instance and put there your key with value.
     
  9. Offline

    raGan.

    Too complicated and needs to work with other things than bukkit config. I'll jut use multiple symbols and tell people not to use them. :p Something like "#&#", then regexing back is simple. Thank you anyway.
     
  10. Offline

    skipperguy12

    raGan.
    Wait. If you save it as a String into config, it won't conflict because it will automatically be surrounded with single quotes.

    Ex:
    Blah:
    Blah:
    Blah: 'blah.blah'

    Now, Blah.Blah.Blah will be blah.blah as a String :3
     
  11. Offline

    raGan.

    skipperguy12 (it appears to be "Grum" today)
    I need to have string with dots as single key.
    And since
    this.is: impossible
    I change dots to other group of symbols, because
    this#%#is: possible
     
  12. Offline

    stirante

    raGan.
    But if you will do some reflection it is possible. Here is some pseudo code:
    Code:
    Field field = MemorySection.class.getDeclaredField("map");
    field.setAccessible(true);
    Map map = field.get(getConfig());
    map.put("this.is", "possible");
    field.set(getConfig(), map);
    
    This should add to config 'this.is: possible'.
     
  13. Offline

    raGan.

    stirante
    Maybe, but I use key interface that is implemented by various storage classes, providing various ways of storing data, so I don't actually know if I'm storing into config at that time. And doing instanceof-s is not an option.
     
Thread Status:
Not open for further replies.

Share This Page