Spawning falling blocks crashes server... Halp

Discussion in 'Plugin Development' started by JTGaming2012, Oct 31, 2014.

Thread Status:
Not open for further replies.
  1. Offline



    So I have a a floor of sandstone and I am creating a sorta quicksand game where the floor randomly disappears. However, I want it a bit more visual and interesting so I decided to spawn a falling block when the blocks disappear. So, the problem is, because it is on a scheduled task, it crashes the server because it spawns too many falling blocks at once.

    How can I still have falling blocks without it crashing? One solution I came up with (but failed miserably) was to adjust the repeating task to a shorter timer and only remove one block per loop. But there's a pattern to how the blocks fall - They have a high chance of being chosen from one corner, and a less chance from the opposite...

    Here's my class, any suggestions?

    1. public void run() {
    2. for(int x = -60; x < -47; x ++) {
    3. for(int z = 215; z < 232; z ++) {
    4. Location l = new Location(Bukkit.getWorld("Minigames"), x, 103, z);
    5. Block b = l.getBlock();
    6. if(b.getType() == Material.SANDSTONE) {
    7. int c = x + 60;
    8. if(r.nextInt(30) == 0) {
    9. FallingBlock fb = b.getWorld().spawnFallingBlock(b.getLocation(), Material.SANDSTONE, (byte) 0);
    10. fb.setDropItem(false);
    11. b.setType(Material.AIR);
    12. }
    13. }
    14. }
    15. }
    16. }

    The blocks fall in to lava and on to slabs... Does that effect anything?

    Thanks in advance!
  2. Offline


    please post the error you get when the server crashes.
Thread Status:
Not open for further replies.

Share This Page