#Lists

1 messages · Page 1 of 1 (latest)

hollow slate
#

stuff

gentle cosmos
#

hi

#

okay

hollow slate
#

hi

gentle cosmos
#

pls send the full code you already have to send your message pls

hollow slate
#
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-------------------------------"));
        }```
gentle cosmos
#

thanks

#

one sec ps

#

yeah

#

it's easy

hollow slate
#

what am I doing wrong then

gentle cosmos
#

do you want me to explain the problem or do you just want me to send you a fixed version? 😛

hollow slate
#

explain

gentle cosmos
#

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?

hollow slate
#

yea

gentle cosmos
#

so you want to move the sender.sendMessage(ChatUtil.color("&8&m-------------------------------"));OUTSIDE of the loop

#

gimme a sec pls

hollow slate
#

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-------------------------------"));
gentle cosmos
#
        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-------------------------------"));
hollow slate
#

what I sent seems to work 🤷‍♂️

gentle cosmos
#

yeah what you sent works too

#

it's just two different approaches

hollow slate
#

yea

gentle cosmos
#

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

hollow slate
#

just tested yours

#

and it prints out rule 1 twice

gentle cosmos
#

what even is "rules"?

hollow slate
#

a list

gentle cosmos
#

then your list contains the same rule twice

hollow slate
#

nope

gentle cosmos
#

yes

#

bruh it's a for loop

#

java works

hollow slate
#
-------
rule 1
rule 1
rule 2
-------
#

that's what yours do

gentle cosmos
#

if it prints the same thing twice, your list contains the same rule twice

gentle cosmos
hollow slate
#

no

gentle cosmos
#

oh

hollow slate
#
-------
rule 1
rule 2
---------
gentle cosmos
#

ugh yeah of course

#

no duplicated rule #1

#

of course

hollow slate
#

yea

#

yw

gentle cosmos
#

then you fucked up your list

hollow slate
#

seems to work the way I did it so 🤷‍♂️

gentle cosmos
#

alright, if you think so

hollow slate
#

wym if I think so

gentle cosmos
#

nah it's fine

hollow slate
#

anyways thanks for your help