random tp which teleports you to aanother world

Discussion in 'Plugin Development' started by Lewishjames, Mar 2, 2015.

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


    So I have been attempting to make a /RTP plugin which will teleport you to a world called "wild" However its not working and just wont telport the Player.

    This is my code so far.

    package me.rtp;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Random;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin{
        public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
        public void onEnable(){
            Bukkit.getServer().getLogger().info("Plugin Enabled!");
        ArrayList<Player> cooldown = new ArrayList<Player>();
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            final Player p = (Player) sender;
            // No cooldown found or cooldown has expired, save new cooldown
            if (command.getName().equalsIgnoreCase("Wild") && sender instanceof Player){
                    return true;
                Location originalLocation = p.getLocation();
                Random random = new Random();
                Location teleportLocation = null;
                int x = random.nextInt(100) + 1;
                int y = 150;
                int z = random.nextInt(100) + 1;
                boolean isOnLand = false;
                while (isOnLand == false) {
                        teleportLocation = new Location(p.getWorld(), x, y, z);
                        if (teleportLocation.getBlock().getType() != Material.AIR) {
                                isOnLand = true;
                        } else y--;    
                World world = Bukkit.getWorld("Wild");
                if(world == null){
                WorldCreator creator = new WorldCreator("Wild");
                world = creator.createWorld();
                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! ####LEWIS PLUGIN COPYRIGHT HELD.");
                return isOnLand;
  2. Offline


  3. Offline


    Thanks @Skionz will see if that fixes it.


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 13, 2016
  4. Offline


Thread Status:
Not open for further replies.

Share This Page