Setting Multiple blocks (No Lag)

Discussion in 'Plugin Development' started by Squid_Boss, Oct 15, 2013.

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

    Squid_Boss

    In one of my plugins I'm working on, I have to change 80 blocks into another block, and it's causing a bit of lag. I have all of the 80 block locations set into another class, and in the main class I retrieve those locations and set them to gold blocks. Here is the exact code I am using:
    Code:java
    1. Blocks.block1.getBlock().setType(Material.GOLD_BLOCK);

    Imagine this same thing 80 times. It lags quite a bit, so would anyone know of a faster way to set that many blocks? *Maybe storing the blocks in like a config, and getting the locations from the config?*
     
  2. Offline

    MiniDigger

    That will delay the method even more :D. You could store all the Locations in a list and looping through the list and setting the block type. This will make your method a bit smaller but it will take the same time. I dont think you can make that faster.
     
  3. Offline

    Squid_Boss

  4. Offline

    MiniDigger

    But they dont use the Bukkit API :D. If you dont use the api you have to take care of such ugly things like relection and obfuscated code. But gomeow said "There will a method in CB to do this soon hopefully" so that you can use tha api. Maybe he can say something about this :D
     
  5. Offline

    Squid_Boss

    Well, after doing some testing I've concluded that setting 80 blocks wasn't the cause of lag, I have to look elsewhere in the code :p. I am always up for ways to shorten my code, though!
     
  6. Offline

    MiniDigger

  7. Offline

    Squid_Boss

    Thanks. :)
     
Thread Status:
Not open for further replies.

Share This Page