Solved How to set spawn?

Discussion in 'Plugin Development' started by Giorgio, Oct 4, 2012.

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

    Giorgio

    I have a Quick question on how to set spawn in a location and teleporting there later? with /spawn and /setspawn? How. Thanks for helping!
     
  2. Offline

    The_Coder

    Ok I don't know if bukkit has something for this but you could just make one it is easy.
     
  3. Offline

    Kazzababe

    Code:
    World world = player.getWorld();
    Location loc = player.getLocation();
    world.setSpawnLocation(loc.getBlockX(), loc.getBlockY() + 1, loc.getBlockZ());
    Code:
    player.teleport(player.getWorld().getSpawnLocation());
     
    Giorgio likes this.
  4. Offline

    Giorgio

    Wow thank you very much! worked like a charm.
     
  5. Offline

    JJSfluffyduck

    This is what i do to set spawn at the player location
    Code:
    Player player = (Player) sender;
    int LocX = (int) player.getLocation().getX() - 1;
    int LocY = (int) player.getLocation().getY() - 1;
    int LocZ = (int) player.getLocation().getZ();
     
    if (commandLabel.equalsIgnoreCase("setspawn")) {
    if (player.isOp()) {
    // Location spawn1 = new Location(player.getWorld(),LocX, LocY,
    // LocZ);
     
    player.getServer().getWorld("world")
    .setSpawnLocation(LocX, LocY, LocZ);
    player.sendMessage(ChatColor.GREEN + "Spawn Set at: x, " + LocX
    + " y, " + LocY + " z, " + LocZ);
     
    
     
  6. Offline

    KeybordPiano459

  7. Offline

    Giorgio

    Ok thank you all for the help and replies!
     
  8. Offline

    Kazzababe

    Not a problem, Im glad to help!
     
  9. Offline

    Kingofawesome15

    Where do i type that in? The start.bat?
     
    Maulss, C0nsole and jorisk322 like this.
  10. Offline

    Tacola

    World world = Bukkit.getWorlds().get(0);
    world.setSpawnLocation(-195, 66, 243);

    To set it one time I do this in the onEnable event. Use your X,Y,Z and make sure you have the correct world.
    The Player method mentioned above works for setting it realtime.
    the bat file is for os commands.
     
  11. Offline

    fireblast709

    Code:java
    1. public void setspawn(Player p)
    2. {
    3. Location l = p.getLocation();
    4. String worldname = l.getWorld().getName();
    5. getConfig().set("worlds."+worldname+".x", l.getX());
    6. getConfig().set("worlds."+worldname+".y", l.getY());
    7. getConfig().set("worlds."+worldname+".z", l.getZ());
    8. getConfig().set("worlds."+worldname+".pitch", l.getPitch());
    9. getConfig().set("worlds."+worldname+".yaw", l.getYaw());
    10. p.sendMessage("Spawn set");
    11. }
    12.  
    13. public Location getPlayerSpawn(Player p)
    14. {
    15. String worldname = p.getWorld().getName();
    16. Double x = getConfig().getDouble("worlds."+worldname+".x", l.getX());
    17. Double y = getConfig().getDouble("worlds."+worldname+".y", l.getY());
    18. Double z = getConfig().getDouble("worlds."+worldname+".z", l.getZ());
    19. Float pitch = getConfig().getFloat("worlds."+worldname+".pitch", l.getPitch());
    20. Float yaw = getConfig().getFloat("worlds."+worldname+".yaw", l.getYaw());
    21. if(x == null || y == null || z == null || pitch == null || yaw == null)
    22. {
    23. return null;
    24. }
    25. else
    26. {
    27. return new Location(p.getWorld(), x, y, z, yaw, pitch);
    28. }
    29. }
    30.  
    31. @EventHandler
    32. public void onRespawn(PlayerRespawnEvent event)
    33. {
    34. event.setRespawnPosition(getPlayerSpawn(event.getPlayer()));
    35. }

    A few lines of code that handle a big part of it. You still need to do the config though, and make, say, a command /setspawn
     
    thomasb454 likes this.
  12. Offline

    cman1885

    No, this is for making plugins.
     
  13. Epic Fail lol
     
    HeyAwesomePeople likes this.
  14. Offline

    iWesley23

    How would I put this in my plugin? If you need the code I will give it to you. Or add me on skype: iWesley23
     
  15. Offline

    JPG2000

    iWesley23 its very easy if your using one spawn point. Just check for the players location and do bukkit.setspawn
     
  16. Offline

    iWesley23


    I have my own plugin called "Simple Hub" Where I do /sethub to set a spawn point, then do /hub to go where I did /sethub. What would I have to do to put that in my own plugin?
     
  17. Offline

    JPG2000

    iWesley23 For set hub get the players location, save and and set it to a spawn point. For /hub just save the location or server.getspawn and teleport the player to it. Homostoly I said it 2 times, if its to hard learn java again.
     
  18. Offline

    rguz10

    No, the real fail is you bumping a year old thread.
     
  19. Offline

    iWesley23

    I fixed it, but thanks.
     
  20. Offline

    xNamesi

    Guys you can take this code. i used it for my plugin saves you figureing out where to place it. this is setspawn and spawn.

    Code:java
    1. //Server Spawn
    2. if(label.equalsIgnoreCase("spawn")) {
    3. if(!sender.hasPermission("ezcmd.spawn")) {
    4. sender.sendMessage(ChatColor.DARK_RED + "eZCommand" + ChatColor.DARK_GRAY + ChatColor.BOLD + ">" + ChatColor.RED + " You Don't Have Permission!");
    5. return true;
    6. }
    7. p.sendMessage(ChatColor.YELLOW + "eZCommand" + ChatColor.DARK_GRAY + ChatColor.BOLD + ">" + ChatColor.AQUA + " Teleporting To Spawn..");
    8. p.teleport(p.getWorld().getSpawnLocation());
    9. }
    10.  
    11. //Server Set Spawn
    12. if(label.equalsIgnoreCase("setspawn")) {
    13. if(!sender.hasPermission("ezcmd.setspawn")) {
    14. sender.sendMessage(ChatColor.DARK_RED + "eZCommand" + ChatColor.DARK_GRAY + ChatColor.BOLD + ">" + ChatColor.RED + " You Don't Have Permission!");
    15. return true;
    16. }
    17. World world = p.getWorld();
    18. Location loc = p.getLocation();
    19. p.sendMessage(ChatColor.YELLOW + "eZCommand" + ChatColor.DARK_GRAY + ChatColor.BOLD + ">" + ChatColor.AQUA + " Server Spawn Successfully Set!");
    20. world.setSpawnLocation(loc.getBlockX(), loc.getBlockY() + 1, loc.getBlockZ());
    21. }
     
  21. Offline

    Booshayy


    I realize this is completely off-topic and the problem is solved, but.
    You could do this, just a tip ;D
    Code:
    if cmd.getName().equalsIgnoreCase("setspawn") && player.isOp() { //you could replace this with player.hasPermission("hub.setspawn")
    Just realized this thread is a year and a half old .___.
     
  22. Offline

    Phasesaber

    //Sorry to bring up an old post!

    THANK YOU! I had no idea that the PlayerRespawnEvent had a setRespawnPosition! :D
     
Thread Status:
Not open for further replies.

Share This Page