Hey, i have only a short question. I will make a random TP for my Server-Ssystem. But the Problem is, randomly players gets teleported in the ground. I think the issue is that, thats the koordinate gets savechecked before the chunk is complete generated. Now my question, is world.loadChunk async? if yes a must create a bukkit task that runs later. Here my code Code (Java): /** * Errechnet eine sichere Position. * * @param player {@link Player} * @param world {@link World} * @param max_x {@link Integer} * @param max_z {@link Integer} * @return {@link Location} und null wenn unsicher. */ private Location getGoodLocation(World world, int max_x, int max_z) { Location teleportlocation = null; Random random = new Random(); int x = random.nextInt(max_x); int y = 170; int z = random.nextInt(max_z); Location targetlocation = new Location(world, x, y, z); targetlocation.getWorld().loadChunk(x, y, true); while (targetlocation.getBlockY() > 0) { Block block = targetlocation.getBlock(); if (block.getType() == Material.LAVA || block.getType() == Material.WATER || block.getType() == Material.CACTUS) { break; } else if (block.getType() == Material.AIR) { targetlocation.subtract(0.0, 1.0, 0.0); } else if (block.getType() != Material.AIR) { teleportlocation = targetlocation; break; } } if (teleportlocation != null) { return teleportlocation.add(0.0, 1.0, 0.0); } else { return null; } } Iam enjoyed for any suggestions or help.
You found a bug. See your Github ticket. Looks like getHighestBlockAt returns Material of highest-solid+1
Not work i get stuck in the ground Code (Java): private Location getGoodLocation(World world, int max_x, int max_z) { Location teleportlocation = null; Random random = new Random(); int x = random.nextInt(max_x); int z = random.nextInt(max_z); world.loadChunk(x, z, true); int y = world.getHighestBlockYAt(x, z); Location targetlocation = new Location(world, x, y, z).subtract(0.0, 1.0, 0.0); Block block = targetlocation.getBlock(); if(block.getType() != Material.WATER && block.getType() != Material.LAVA) { teleportlocation = targetlocation; } return teleportlocation; }
Yea. Simple get the highest block in the world int y = world.getHighestBlockYAt(x, z); then get the blockface down from the location and check whatever you want. then teleport the player.
Reported and pr submitted: https://hub.spigotmc.org/jira/brows...resolved ORDER BY priority DESC, updated DESC https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/621/overview