How could i make it so you spawn randomly?

Discussion in 'Bukkit Help' started by MrDoomBringer_, Jan 12, 2021.

  1. Offline

    MrDoomBringer_

    Hey, i have an anarchy server, i need it so it spawns in a radius of 1000 by 1000, how could i do that?
     
  2. Offline

    marcelo.mb

    @MrDoomBringer_
    • Generate a random value for the x-coordinate and a random one for the z-coordinate. Notice that the value has to be in a special range.
      Code:
      int xCor = ThreadLocalRandom.current().nextInt( INT_POINT_OF_ORIGIN - 1000, INT_POINT_OF_ORIGIN + 1001);
      int zCor = ThreadLocalRandom.current().nextInt( INT_POINT_OF_ORIGIN - 1000, INT_POINT_OF_ORIGIN + 1001);
    • So we have got an x and a z coordinate. What's missing is the y-coordinate. Unfortunately, we can not get a random value for this, because we do not want to spawn the player in the air or under the ground. Strictly speaking, we want to spawn the player exactly on top of the ground. So we have to find out the ground high at the position x and z.
      1. Solution A: You can look into this class: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html. As you can see you can use the getHighestBlockAt() functions. Very easy to use.
      2. Solution B: Loop from 0 to 255 for the y coordinates and the given x and z coordinates and check when many blocks are instance of air. Then you get your ground high with only a few logical phrases.
    Further notes: If the highest block is instance of leaves I would get new x and y coordinates to not spawn the player on top of a tree.​
    • Do not forget to check the block below our new spawn location to not spawn players on top of lava.
     
    Last edited: Jan 12, 2021
    MrDoomBringer_ likes this.
  3. Offline

    MrDoomBringer_

    Uhh idk how to do that.

    @marcelo.mb

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

    marcelo.mb

    @MrDoomBringer_ So if you only want a plugin for that please have look at the available plugin list. I am sure there is one with this functionality. But if you want to programme this I would say you have to learn java first and familiarize yourself with bukkit.;)
     

Share This Page