Liquid
Liquid
JCHJava Community | Help. Code. Learn.
Created by Electroking on 11/27/2024 in #java-help
Problem Accessing yml elements using java for minecraft
everyone has to start somewhere :)
31 replies
JCHJava Community | Help. Code. Learn.
Created by Electroking on 11/27/2024 in #java-help
Problem Accessing yml elements using java for minecraft
yoo nice
31 replies
JCHJava Community | Help. Code. Learn.
Created by Electroking on 11/27/2024 in #java-help
Problem Accessing yml elements using java for minecraft
I'd try something like this: (not tested)
List<Map<?, ?>> kitItems = main.getConfig().getMapList("kits." + key); // using getMapList to obtain List<Map<?,?>>

// now we have a list containing the objects in form of a map, so we can get values by key

if (kitItems != null) {
for (Map<?, ?> kitItem : kitItems) { // loop through every kit entry
String id = (String) kitItem.get("id"); // get id field and cast to string
int amount = (int) kitItem.get("amount"); // get amount field and cast to int

// use the variables
// ItemStack item = ...
}
}
List<Map<?, ?>> kitItems = main.getConfig().getMapList("kits." + key); // using getMapList to obtain List<Map<?,?>>

// now we have a list containing the objects in form of a map, so we can get values by key

if (kitItems != null) {
for (Map<?, ?> kitItem : kitItems) { // loop through every kit entry
String id = (String) kitItem.get("id"); // get id field and cast to string
int amount = (int) kitItem.get("amount"); // get amount field and cast to int

// use the variables
// ItemStack item = ...
}
}
31 replies
JCHJava Community | Help. Code. Learn.
Created by Electroking on 11/27/2024 in #java-help
Problem Accessing yml elements using java for minecraft
happy to help :)
31 replies
JCHJava Community | Help. Code. Learn.
Created by Electroking on 11/27/2024 in #java-help
Problem Accessing yml elements using java for minecraft
@Electroking Whats the output if you print the returned value of
main.getConfig().getList("kits.necro-demon")
main.getConfig().getList("kits.necro-demon")
? I can't really tell, but I assume that YamlConfiguration#getStringList only works on YAML lists that contain ONLY strings, your list however contains Objects with multiple properties (id,amount). Also, to make it easier for people to help you, its recommended to post your code and config using discords code formatting feature, see the message below.
31 replies