Problem Accessing yml elements using java for minecraft

Problem Accessing yml elements using java for minecraft : i'd like to have kits where i give players some blocks defined in the config.yml but when i try it, it doesn't work, the yml is valid, the code too, the list in't null, but doesn't show any element event if i put a basic element at the start of the list (BEDROCK one) Version mc + spigot 1.16.5
26 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @Electroking! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Electroking
ElectrokingOP3mo ago
java Code :
No description
Electroking
ElectrokingOP3mo ago
config.yml :
No description
Electroking
ElectrokingOP3mo ago
result in mc using both screens above :
No description
Electroking
ElectrokingOP3mo ago
(merci de me ping dans vos réponses)
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Electroking
ElectrokingOP3mo ago
still need help pls
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Liquid
Liquid3mo ago
@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.
JavaBot
JavaBot3mo ago
Please format your code & make it more readable. For the java programming language, it should look like this:
```java public class Main { public static void main(String[] args){ System.out.println("Hello World!"); } ```
• These are backticks, not quotes.
Electroking
ElectrokingOP3mo ago
working, lets go thank you
JavaBot
JavaBot3mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Electroking
ElectrokingOP3mo ago
No description
Electroking
ElectrokingOP3mo ago
tysm, ill see if i get what i want
Liquid
Liquid3mo ago
happy to help :)
Electroking
ElectrokingOP3mo ago
and, can you tell me how you access id and amount ?
Electroking
ElectrokingOP3mo ago
i tried this but not working
No description
Electroking
ElectrokingOP3mo ago
No description
Liquid
Liquid3mo ago
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 = ...
}
}
Electroking
ElectrokingOP3mo ago
thank you so much bro, its working perfectly
No description
JavaBot
JavaBot3mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Electroking
ElectrokingOP3mo ago
tell me when u've seen, then i can close yml is so weird to get x)
Liquid
Liquid3mo ago
yoo nice everyone has to start somewhere :)
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot3mo ago
Post Closed
This post has been closed by <@278562333977214976>.

Did you find this page helpful?