Hello, I am working on a plugin right now and i need to add a random Tp part to the plugin but i do not know how to do this. I need it to randomly tp the player (Not on water or in the sky/blocks) How would i do this? Thanks
I have a random TP but it is not really working properly as it is TPint the players but it is sending the players around the same distance
Code: public static void tp(Player p){ Location originalLocation = p.getLocation(); Random random = new Random(); Location teleportLocation = null; int x = random.nextInt(50) + -50; int y1 = 150; int z = random.nextInt(50)+ -50; teleportLocation = new Location(p.getWorld(), x, y1, z); boolean isOnLand = false; while (isOnLand == false) { teleportLocation = new Location(p.getWorld(), x, y1, z); if (teleportLocation.getBlock().getType() != Material.AIR ) { isOnLand = true; } else y1--; } p.teleport(new Location(p.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 1, teleportLocation.getZ())); p.sendMessage(ChatColor.GREEN + "You have been teleported " + (int)teleportLocation.distance(originalLocation) + " blocks away!"); return; }
@killerzz1 Your random will only teleport the player from -50 to 49. Please set the random to the size you want plus one, which will then teleport the player from -50 to 50.