Teleporting Chances

Discussion in 'Plugin Development' started by Divinity Realms, Feb 19, 2015.

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

    Divinity Realms

    Im trying to make it so when a player respawns theres 5 locations that a player can spawn at. Its a random. I also want all locations to have the same chance. Can you guys help? heres what I have so far:
        public void respawnEvent(PlayerRespawnEvent event){
            World world = plugin.getServer().getWorld("world");
            Location loc1 = new Location(world, -90.500, 16, 0, 64, 0);
            Location loc2 = new Location(world, -65.500, 20, 12.500, -80, 0);
            Location loc3 = new Location(world, -34.500, 29, 25.500, 180, 0);
            Location loc4 = new Location(world, -65.500, 20, 38.500, 180, 0);
            Location loc5 = new Location(world, -109.500, 16, 22.500,-140, 0);
            Location locm = new Random().nextInt(loc1,loc2,loc3,loc4,loc5);
  2. Offline


    @Divinity Realms Put the locations in a List, then use Random#nextInt with the size of the list (keep the location list in a field as well as the random, there is not reason to create new objects every time a player respawns).
  3. Offline

    Divinity Realms

    @Konato_K Thx! and @CodePlaysMinecrat doesnt work xD
  4. Offline


    You're not even teleporting the player.
  5. Offline

    Divinity Realms

    @Arrays I know lol im just wondering how I can make the random work first..
  6. Offline


    1. Check if the world actually exists before you start defining variables.
    2. Try using "Bukkit.getWorld(string) instead of .getServer.getWorld()
  7. Offline

    Divinity Realms

    @Arrays ok thanks.. But how can I make this random work -.-
  8. Offline


    @Divinity Realms konato said all.
    Create an arraylist when the plugin load and store your 5 locations in.
    Then do a random for return a number between 0 and 4
    Then get back the location in the arraylist by a arraylist.get(int)
    And teleport the player
Thread Status:
Not open for further replies.

Share This Page