#Reading a text file without crashing the server

1 messages · Page 1 of 1 (latest)

agile ledge
#

hello, i have a file with a lot of coordinates shown like that:
54 62 -354
-961 69 -81
428 69 424
40 70 -246
-679 69 -967
-229 72 70
131 103 -1117
89 76 -1133
637 69 -352
-827 69 219

how can i make so my code, for each line, gets the line and executes an ig command with those

i have already tried file reader, and I cannot find a solution to the fact that my server crashes after 30 seconds because it cannot handle the loop

Do you have the solution for this ? i have more than 10000 coordinates

cobalt dew
#

your server shouldnt be crashing reading 10k cordinets from a file but

Why do you have 10k coordinets in your file

jolly pagoda
#

do it async

#

and on start up

#

but yeah

#

also sounds like a data design problem

cobalt dew
#

the reason its crashing is more of less calling new Location()

jolly pagoda
#

probably IO as well

#

I mean it has to call your disk

#

which is... expensive

cobalt dew
#

yep since calling new Location loads the chunk for that Location

jolly pagoda
#

no?

cobalt dew
#

It did in my experiences

jolly pagoda
#

hmm, well I believe getBlock or getChunk will

#

but the instantiation shouldn't unless im not updated here

cobalt dew
#

Ah i could be wrong then, he also could be calling those methods too

#

Just seems odd reading through those strings causes a server to crash

jolly pagoda
#

yeah good point

#

yeah well, if the file is large enough

#

since yaml also has to parse the shit

cobalt dew
#

sounds like its just a normal .txt file

jolly pagoda
agile ledge
#

lemme post my actual code

#

it is a .txt file

#
                 for(String line; (line = br.readLine()) != null; ) {
                     x=x+1;
                    Bukkit.dispatchCommand(console, "setblock " + String.valueOf(line) + " chest");
                       Bukkit.broadcastMessage("Placing chest in " + String.valueOf(line) + " : " + String.valueOf(x) + " / 10 550");
                    try {
                        Thread.sleep(250);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                 }
             } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
cobalt dew
#

reeeeee

#

why are you calling

#

Thread.sleep()

agile ledge
#

i tried the bukkit sleep thing

cobalt dew
#

you dont need to sleep for this also you dont need to use a command to set a block

agile ledge
#

i need sleep else it crashes

cobalt dew
#

You do know calling that method hangs the thread right

jolly pagoda
#

^

agile ledge
#

the console command thingy?

cobalt dew
#

No Thread.sleep()

jolly pagoda
#

but also, you do wanna invoke that file buffer on another thread

cobalt dew
#

Another thing: When setting thousands of blocks like this you might be better to try the NBT methods of setting a block, heard theres loads better performance when doing this its also how plugins like FAWE handle setting loads of blocks

agile ledge
#

so should i import fast async we ?

#

and then do what ? since reading each line of my file is too fast for the server

cobalt dew
#

Do Concure's thing first of invoking the file buffer on another thread

Another thing to note: You cant modify Blocks async so you cant really set the actual block asynchronusly

#

You dont want to import fawe really just to do this either

agile ledge
#

i'll be honest, i don't know much about java, i had to learn it to do plugins

#

but i definitely dont need someone to spoonfeed me

cobalt dew
agile ledge
#

why would the code need to get the actual block state

#

since i want to place blocks there

#

i still dont understand

#

assuming all the chunks are loaded

#

i just need to take 1 line, replace the block there, then move on to line 2