Teleport player a random coordinates to world with command

Discussion in 'Plugin Development' started by Jedodalci, Jul 31, 2014.

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

    Jedodalci

    Hello ,
    I Search a Method to Random Teleport player to a Coordinates in World.
    Thanks
     
  2. Jedodalci Woah, you have more capitalised words in there than lowercase words. This doesn't give very much information, so we can't provide much help - I'll tell you Java has a Random class, and Entity has a teleport() method.
     
  3. Offline

    TheMcScavenger

    Code:java
    1. public void teleport(Player player, Location location){
    2. player.teleport(location);
    3. }
     
  4. jthort likes this.
  5. Offline

    Jedodalci


    Yes but I want it when the player type / random to be teleported to a random coordinate.
     
  6. Offline

    Pizza371

    AdamQpzm Because there isn't one - I think he thought that Method for regular teleportation, even though it would be pointless :p
     
  7. Offline

    Jedodalci

    Help me I search a random coordinates Method D:
     
  8. Offline

    TheMcScavenger

    Generate three random integers, then teleport the player to a new location with those integers as x, y, z.
     
  9. Jedodalci Then generate 3 random numbers, and teleport them there.

    Pizza371 Yeah, replicates some of the functionality Entity#teleport(Location) provides (but not all of it) without any benefit :S
     
  10. Offline

    TheMcScavenger

    No, I didn't. You didn't take the time to provide us with a question we could answer, I didn't take the time to provide you with an answer you could use.
     
  11. Offline

    Jedodalci

    You Can Post an Example of this three Random.
    Like You
     
  12. Offline

    TheMcScavenger

    Already said that, and that was the point.

    You Can Google Example Of This Three Random.
    Like You

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

    artish1

    Jedodalci
    You should also use the world.getHighestBlockAt(x,y,z), that way they won't spawn inside blocks and suffocate to death. Or if you want to go into more detail, calculate the distance in going down and up the y coordinate, and check the blocktypes to see if its air(or 2 blocks of air for player height), then use an if statement to check which is the shortest distance from the original random location, then teleport your player there. (This is if you want the player to spawn in caves)
     
  14. We posted at the same time, I didn't see your post until I had already posted. And what was the point?
     
  15. Offline

    TheMcScavenger

    The point was that I wanted to give him a worthless function, as he had provided a worthless explanation of his question. No effort = No effort.
     
  16. Offline

    Jedodalci

    AdamQpzm Help me Doesn'tWork D:

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("random")) {
    Player p = (Player) sender;
    Random x = new Random();
    Random z = new Random();
    int randomx;
    int randomz;
    randomx = x.nextInt(getConfig().getInt("xMax"));
    randomz = z.nextInt(getConfig().getInt("zMax"));
    double x1 = randomx;
    double z1 = randomz;
    double y = getConfig().getDouble("Dimensione.Y");
    World w = Bukkit.getServer().getWorld(getConfig().getString("Mondo"));
    p.teleport(new Location(w, x1, y, z1));

    }
    return false;

    }
     
  17. Offline

    Jedodalci

    When I run the command gives me error

    java.lang.NullPointerException is a error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  18. Jedodalci What error? Please provide the full stack trace and the full code
     
  19. Offline

    Jedodalci

    config.yml:

    # AOF Random teleport

    # Configurazione della x e z Massima insieme al Messaggio di Teleport
    # Default: 25000

    xMax: 25000
    zMax: 25000
    Mondo: world
    Dimensione:
    Y: 60

    plugin.yml:

    name: AOFrandom
    version: 1.0
    main: me.jedo.aof.Main
    author: [Xx_Jedo_xX]
    description: Plugin per il teletrasporto Random!
    commands:
    random:
    description: Comando per il Teleport!


    Main class:

    package me.jedo.aof;

    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    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 void onEnable() {
    getLogger().info("Carico le Configurazioni.....");
    getConfig().options().copyDefaults(true);
    saveConfig();
    getLogger().info("Random Teleport Abilitato!");
    }

    public void onDisable() {
    getLogger().info("Disabilitato..");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("random")) {
    Player p = (Player) sender;
    Random x = new Random();
    Random z = new Random();
    int randomx;
    int randomz;
    randomx = x.nextInt(getConfig().getInt("xMax"));
    randomz = z.nextInt(getConfig().getInt("zMax"));
    double x1 = randomx;
    double z1 = randomz;
    double y = getConfig().getDouble("Dimensione.Y");
    World w = Bukkit.getServer().getWorld(getConfig().getString("Mondo"));
    p.teleport(new Location(w, x1, y, z1));

    }
    return false;
    }
    }
     
  20. Offline

    Necrodoom

  21. Offline

    Jedodalci

    Last edited by a moderator: Jun 9, 2016
  22. Offline

    TheMcScavenger

    Jedodalci There's a button called "Edit". Use it.
     
  23. Offline

    Necrodoom

  24. Offline

    TheMcScavenger

    He already posted those. No need to put them on paste bin.
     
  25. Offline

    Jedodalci

    Ok but then how do I teleport the player to random coordinates within what I write?

    I need it within 2 hours and 30 pleasee

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

    Necrodoom

    TheMcScavenger try to write a YML file without indentation.
    Jedodalci do what I said so we can properly follow your code flow.
     
  27. Offline

    JBoss925

    Typed on my phone, forgive my mistakes.
    Code:java
    1. public Location getRandomLoc(int xmax, int xmin, int zmax, int zmin, World w){
    2. Random r = new Random();
    3. double x = r.nextInt(xmax - xmin) + xmin + 1.0;
    4. double z = r.nextInt(zmax-zmin) + zmin + 1.0;
    5. double y = w.getHighestBlockYAt((int) x, (int) z) + 1.0;
    6. return new Location(w, x, y, z);
    7. }
     
  28. Offline

    Jedodalci

    How i Implement Negative Numbers?
    Example

    -9000 ecc...
     
Thread Status:
Not open for further replies.

Share This Page