Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.seadragon91.chunktesting;
- import java.util.Random;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.WorldCreator;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.generator.ChunkGenerator;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitRunnable;
- public class ChunkTesting extends JavaPlugin {
- /*
- * Problem: Regenerating a chunk in a air world at players location, doesn't send the player an chunk update.
- * Using the method refreshChunk() from class world should send to all players the chunk, but it doesn't work.
- *
- * By running the command /chunktesting. This steps will be occur.
- * 1) Generates a air world.
- * 2) Teleports the player to the air world.
- * 3) Generates a cube of stone to see the the dark and have a place for placing blocks.
- * 4) Regenerate the chunk at players location, will remove stone the chunk will be then dark.
- *
- * Now try to fly to the wall and try to place blocks against the wall, they don't appear.
- * Disconnect and reconnect and you should see your "placed" blocks.
- *
- */
- @Override
- public void onDisable() {
- this.getLogger().info("disabled");
- }
- @Override
- public void onEnable() {
- this.getLogger().info("enabled.");
- }
- // returns a chunk generator full with air
- class AirChunkGenerator extends ChunkGenerator {
- @Override
- public byte[] generate(World world, Random random, int cx, int cz) {
- return new byte[65536];
- }
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!command.getName().equalsIgnoreCase("chunktesting"))
- return false;
- if (!(sender instanceof Player)) {
- sender.sendMessage("[ChunkTesting] This command doesn't work from the console.");
- return true;
- }
- final Player player = (Player) sender;
- // set players gamemode to creative
- player.setGameMode(GameMode.CREATIVE);
- // set player flying to true
- player.setFlying(true);
- // create air world
- final World airWorld = this.getServer().createWorld(WorldCreator.name("chunktesting").generator(new AirChunkGenerator()));
- // create a cube of stone at 0 0 0
- for (int x = 0; x < 30; x++) {
- for (int y = 0; y < 30; y++) {
- for (int z = 0; z < 30; z++) {
- airWorld.getBlockAt(x, y, z).setType(Material.STONE);
- }
- }
- }
- // teleport player to the top of the cube
- player.teleport(new Location(airWorld, 5, 33, 5));
- player.sendMessage("[ChunkTesting] Please wait 5s...");
- // schedule snyc delayed task for 5s
- this.getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable() {
- @Override
- public void run() {
- // regenerate the chunk at players location
- airWorld.regenerateChunk(player.getLocation().getChunk().getX(), player.getLocation().getChunk().getZ());
- // refresh the chunk at players location
- airWorld.refreshChunk(player.getLocation().getChunk().getX(), player.getLocation().getChunk().getZ());
- player.sendMessage("[ChunkTesting] Now try to place blocks against the wall.");
- }
- }, 100L);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement