I am making a lava bucket that when ever you place it, it will turn the lava into cobblestone and start making cobblestone all the way down untill it hits a block. I have some of the plugin made but i don't know whats wrong with my while loop. When ever someone places a genbucket (which is what im calling these items) the server crashes. https://hastebin.com/pabimizeje.cs
Try checking if Code (Java): loc.getBlock().getRelative(BlockFace.DOWN).getType() != null) { } and remove the semi colon after the if statement.
The block from Block#getRelative(), nor its type, can be null. Check whether the type is solid Code (Java): while (!loc.getBlock().getRelative(BlockFace.DOWN).getType().isSolid()) { }
You really shouldn't be using a while loop in on the main thread . Just do all the pre calculations and place all the blocks. Like in a for loop. Keep decreasing the y axis and place a block until it hits the ground.
There's not really anything wrong in running a while loop in the main thread, as long as it's not infinite ofcourse, since that'll crash the server yes. As long as your while loop doesn't loop thousands of times, it shouldn't be any issue.
You can make something like this: Code (Text): int x = loc.getX(); int z = loc.getZ() int y = loc.getY();// or something like this, writting on the phone for(int i ; i< y - 1; i++){ // test if the block bellow the y level of the lava - i is air, if it returns true, place a cobblestone, if not, break the loop then replace the lava with a cobblestone as well }
the main problem is in the while loop: Code (Text): while (loc.getBlock().getRelative(BlockFace.DOWN) != null); { //this is where everything goes wrong if (event.getBlock().equals(Material.AIR)) event.getBlock().setType(Material.COBBLESTONE); } the location is always in the same position that causing an infinite loop, you need to change the location to -1 y-axis when block below is solid until you get the block is non-solid. but remember to check the y coordinate is equals or above 0.
this is what i have now but its not working it places one cobblestone block then does nothing (i have switched to the PlayerBukketEmptyEvent listener) https://hastebin.com/fizajovija.go