As most of you are aware, this is valid YAML: Code: special-drops: - block: IRON_ORE drops: - tool: GOLD_PICKAXE drop: IRON_INGOT - block: WEB drops: - tool: SHEARS drop: WEB - tool: DIAMOND_SWORD drop: STRING^2 - tool: GOLD_SWORD drop: STRING^3 which should result in a list of ConfigurationSections. Problem: I don't see getConfigurationSectionList() anywhere in the API. The config is really annoying to do otherwise, and I need this feature. I get errors when I try to just getList() and try to cast it to List<ConfigurationSection>. Help pls?
@pie_flavor Are you trying to get a configuration section from a string list ? Here a StringList: special-drops: - block: IRON_ORE The plugin cannot read the drops - block: IRON_ORE drops: You should try something like this. special-drops: // You should use '_' and not '-' Im not sure the plugin can read, correct me if i'm wrong. block: drops: tool: drop:
@caderape you can use I believe you can use "-", I usually just use underscores for readability. @pie_flavor , You need to stick to correct spacing if you want sub-sections of your configuration.
@1Rogue Problem is, I'm not sure if casting the list to type ConfigurationSection will actually work. I don't know if it actually stores it as a List<ConfigurationSection> or not, and the API doesn't seem like it implements lists of sections.
So then you can iterate the list of unknowns that is returned and manually check each value if you want, but in my opinion it'd be appropriate to simply let it throw an error if it isn't in the correct format, as that is the result of a user fault.
@1Rogue Not really what I'm talking about. I'm asking if the list of unknowns is even a ConfigurationSection list at all. Does it know that the list is of ConfigurationSections? @Abs0rbed @caderape My syntax and indentation is perfectly correct. If you put it into a YAML parser into, say, JSON, you will see that it creates a list of compound tags.
Generic types are erased at runtime, nothing "knows" what type it is when running. As for the source stage, no you do not, as .getList() returns a List<?>. You can either cast the whole collection to a List<ConfigurationSection>, or manually go through each value. Keep in mind the internal implementation of an object mapping differs between bukkit implementations, as some don't back with ConfigurationSections but rather with a Map<String, Object>.
@Abs0rbed and @caderape said in earlier posts that I did my indentation wrong and I was clearly trying to do something else. It's correct indentation and syntax, right?
@pie_flavor nope, definitely not correct ConfigurationSections (at least from what I've seen in my configs, I don't write them myself though, mainly generated through code). Try making a little test plugin where you create a bunch of sections in the config and see how it indents them. Code: special: IRON_ORE: tool: GOLD_PICKAXE drop: IRON_INGOT WEB: tool: SHEARS drop: WEB Something like that would be valid, with proper spacing (no tabs, I always use 4 spaces between sections) That should be valid, though I just wrote it on the fly.
People probably don't understand what it is you're doing, the syntax is correct for a list of object mappings. It's not seen very often, but it's completely legal.
@1Rogue interesting, I've never seen that before. I just went through all of my configs to see what my plugins generated , it's really different. @pie_flavor I retract that then xD but why not iterate over the paths in your config and create ConfigurationSections based on those paths to get the lowest level sections you want? Not too much code, just a couple for loops Code: for(String s : "topSection".getValues(false).keySet()){ //... } and then create a configurationsection using "topSection".getConfigurationSection(s), add a null check and you're golden. Might be a bit more work than you were hoping for, but if nothing else works, this is pretty reliable.
@pie_flavor Lists generally are, but I've never had this fail on me, and I've never even heard of what you're doing (though it's not surprising, considering my configs are code-generated )
@Abs0rbed Why? I find that it's easier to make the file yourself and call saveDefaultConfig() in onEnable(). Saves space, provides a default config for someone to look at if they screwed up theirs, and is easier to make/edit. Also, it's easy to do what I was doing: Just make a normal list, but use tags instead of strings or whatever. Only put the hyphen on the first tag. Those tags can contain tag-lists of their own, too.
You should still account for both possibilities, for instance: https://github.com/CodeLanx/Codelan.../codelanx/codelanxlib/config/Config.java#L111 This lets me convert whole lists of sections like so: Code:java List<Map<String, Object>> sections = getConfig().getList("example-of-sections").stream().map(Config::getConfigSectionValue).collect(Collectors.toList());
It's a member reference, introduced in java 8. It's equivalent to me doing: Code:java .stream().map((o) -> Config.getConfigSectionValue(o))
@pie_flavor -> is a lambda expression http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax
@Gater12 @1Rogue Where has this been all my life? I can say goodbye to 20 frickin' CommandExecutors in one plugin..