Last active
December 16, 2015 10:08
-
-
Save Xyene/5417528 to your computer and use it in GitHub Desktop.
Test for the bulk block change API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.*; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.PlayerInteractEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class BulkBlockTest extends JavaPlugin implements Listener { | |
@Override | |
public void onEnable() { | |
Bukkit.getPluginManager().registerEvents(this, this); | |
} | |
@EventHandler | |
public void dig(PlayerInteractEvent event) { | |
Player player = event.getPlayer(); | |
player.sendMessage(ChatColor.GREEN + "Beginning chunk transformation..."); | |
long start = System.currentTimeMillis(); | |
Location loc = player.getTargetBlock(null, 200).getLocation(); | |
World world = loc.getWorld(); | |
Chunk c = world.getChunkAt(loc); | |
int cx = c.getX() << 4; | |
int cz = c.getZ() << 4; | |
for (int x = cx; x < cx + 16; x++) { | |
for (int z = cz; z < cz + 16; z++) { | |
for (int y = 0; y < 128; y++) { | |
world.setBlockTypeFast(x, y, z, Material.GLASS); | |
} | |
} | |
} | |
event.getPlayer().updateChunk(c); | |
long millis = System.currentTimeMillis() - start; | |
player.sendMessage(ChatColor.GREEN + "Transformation complete in " + (millis / 1000) + " seconds (" + millis + "ms)!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment