#Lists
1 messages · Page 1 of 1 (latest)
hi
pls send the full code you already have to send your message pls
List<String> rules = Config.RULES.getStrings();
StringBuilder stringBuilder = new StringBuilder();
for (String rule : rules) {
stringBuilder.append(rule).append("\n");
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
sender.sendMessage(ChatUtil.color(stringBuilder.toString()));
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
}```
what am I doing wrong then
do you want me to explain the problem or do you just want me to send you a fixed version? 😛
explain
okay
you have a for loop. it runs for EVERY line you have
just imagine you have list consisting of "aaaaaaa", "bbbbbbbbb" and "ccccccccc"
currently you say "for every aaaaaa, bbbb or cccc, print a line of ---------------"
but you only want that line saying "---------------" once
right?
yea
so you want to move the sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));OUTSIDE of the loop
gimme a sec pls
so
for (String rule : rules) {
stringBuilder.append(rule).append("\n");
}
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
sender.sendMessage(ChatUtil.color(stringBuilder.toString()));
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
for (String rule : rules) {
stringBuilder.append(rule).append("\n");
sender.sendMessage(ChatUtil.color(stringBuilder.toString()));
}
sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));
what I sent seems to work 🤷♂️
yea
but tbh
may I suggest sth that might help you in the future?
?learnjava
doesnt work in threads
ugh
enter that command in any normal channel
I don't mean to offend you but
to me it seems like you havent understood how a for loop works
you should definitly check it out
no offense
what even is "rules"?
a list
then your list contains the same rule twice
nope
if it prints the same thing twice, your list contains the same rule twice
and that's what you were looking for, isn't it?
no
oh
-------
rule 1
rule 2
---------
then you fucked up your list
seems to work the way I did it so 🤷♂️
alright, if you think so
nah it's fine
anyways thanks for your help