Title says all really, I have the code which sets a spawn and saves the coords to a config. It doesn't keep the world though that you've set it too, it just does it to the world your on when you teleport there. Also it always faces a certain direction (north i assume) but I want to to keep the players direction when they do the command. Here's the setspawn code: Code: } else if (args[1].equalsIgnoreCase("Lobby")) { double x = p.getLocation().getBlockX(); double y = p.getLocation().getBlockY(); double z = p.getLocation().getBlockZ(); this.getConfig().set("Spawn_Lobby", x + "," + y + "," + z); saveConfig(); reloadConfig(); p.sendMessage(ChatColor.DARK_RED + "[MCWar]" + ChatColor.DARK_AQUA + " You have set the spawn for the lobby!"); Here's how I teleport there: Code: this.getConfig().getString("Spawn_Lobby"); String[] spawnlobby = this.getConfig().getString("Spawn_Lobby").split(","); double x = Double.parseDouble(spawnlobby[0]); double y = Double.parseDouble(spawnlobby[1]); double z = Double.parseDouble(spawnlobby[2]); Location lobby = new Location(w, x, y, z); p.teleport(lobby); Thanks
I've done this... In my setspawn code: Code: p.getLocation().getPitch(); p.getLocation().getYaw(); And this in my teleport code: Code: lobby.getPitch(); lobby.getYaw(); But it's still not working
Think I may of fixed it now. Here's my code if I haven't. Setspawn: Code: } else if (args[1].equalsIgnoreCase("Lobby")) { double x = p.getLocation().getBlockX(); double y = p.getLocation().getBlockY(); double z = p.getLocation().getBlockZ(); p.getWorld(); p.getLocation().getPitch(); p.getLocation().getYaw(); this.getConfig().set("Spawn_Lobby", x + "," + y + "," + z); saveConfig(); reloadConfig(); p.sendMessage(ChatColor.DARK_RED + "[MCWar]" + ChatColor.DARK_AQUA + " You have set the spawn for the lobby!"); And my teleport: Code: this.getConfig().getString("Spawn_Lobby"); String[] spawnlobby = this.getConfig().getString("Spawn_Lobby").split(","); World w = p.getWorld(); double x = Double.parseDouble(spawnlobby[0]); double y = Double.parseDouble(spawnlobby[1]); double z = Double.parseDouble(spawnlobby[2]); Location lobby = new Location(w, x, y, z); lobby.setPitch(p.getLocation().getPitch()); lobby.setYaw(p.getLocation().getYaw()); p.teleport(lobby);
It works for the direction now that the player stands when they do the setspawn, but it still doesn't get the world you were at when you do setspawn... It just takes you to the coords which are set on any world you are on.
This is my whole teleport join lobby command: Code: if (args[0].equalsIgnoreCase("Join")) { if (p.hasPermission("mcwar.join")) { String name = p.getName(); if (this.inLobby.contains(p) || (this.Teams.contains(p) || this.Zombies.contains(p) ||this.FreeForAll.contains(p))) { p.sendMessage(ChatColor.RED + "You are already playing!"); } else if (this.Dead.contains(p) || (this.Quit.contains(p))) { p.sendMessage(ChatColor.RED + "You Died/Quit! Please wait until the next game."); } else if (this.canjoin) { p.sendMessage(ChatColor.RED + "The game is in already in progress! Please wait until the next game."); } else if (this.Spectate.contains(p)) { p.sendMessage(ChatColor.RED + " You must stop spectating before you can join!"); } else { this.getConfig().getString("Spawn_Lobby"); String[] spawnlobby = this.getConfig().getString("Spawn_Lobby").split(","); double x = Double.parseDouble(spawnlobby[0]); double y = Double.parseDouble(spawnlobby[1]); double z = Double.parseDouble(spawnlobby[2]); Location lobby = new Location(p.getWorld(), x, y, z); lobby.setPitch(p.getLocation().getPitch()); lobby.setYaw(p.getLocation().getYaw()); p.teleport(lobby); this.inLobby.add(p); p.setGameMode(GameMode.SURVIVAL); getServer().broadcastMessage(ChatColor.DARK_RED + "[MCWar] " + ChatColor.GREEN + name + ChatColor.DARK_AQUA + " has joined the game!"); } } else { p.sendMessage(ChatColor.DARK_RED + "You don't have permission to do this command!"); } }
In your save spawn location you must also save the world name this.getConfig().set("Spawn_Lobby.Loc", x + "," + y + "," + z); this.getConfig().set("Spawn_Lobby.World",p.getWorld().getName()); In your spawn part you then do this String[] spawnlobby = this.getConfig().getString("Spawn_Lobby.Loc").split(","); double x = Double.parseDouble(spawnlobby[0]); double y = Double.parseDouble(spawnlobby[1]); double z = Double.parseDouble(spawnlobby[2]); String newWorld = this.getConfig().getString("Spawn_Lobby.World"); Location lobby = new Location(p.getServer().getWorld(newWorld), x, y, z); This should do it.
Still a bit of a problem with the teleporting to the spawn i've set. Whichever way your looking, when you teleport you stay, but I want it so the way and direction and line of sight your looking when you setspawn stays like that when you teleport.
OK in your spawn save do the same thing you did for x,y,z this.getConfig().set("Spawn_Lobby.Yaw", yaw); this.getConfig().set("Spawn_Lobby.Pitch", pitch); and in you spawn just get them and use them to set Location lobby = new Location(p.getServer().getWorld(newWorld), x, y, z,yaw,pitch); lobby.setPitch(p.getLocation().getPitch()); lobby.setYaw(p.getLocation().getYaw());
Ah right, thanks. Is there any other way you can do it without saving it to config? If not i'll do it like that.
If you want the Yaw and Pitch of the spawn location you created then YES you gota save it or how would it know how to face them.
Ok, i've added this: Code: String yaw = this.getConfig().getString("Spawn_Lobby.Yaw"); String pitch = this.getConfig().getString("Spawn_Lobby.Pitch"); Location lobby = new Location(p.getServer().getWorld(newWorld), x, y, z, yaw, pitch); But on the location lobby part it says 'remove arguments to match world, double, double, double?
use this contructor: Location (World world, double x, double y, double z, float yaw, float pitch)EDIT: annoying line breaks...
Am I changing the right thing, because it's not working... Code: World lobby = new Location(p.getServer().getWorld(newWorld), x, y, z, yaw, pitch));
Umm, not sure... This is what i'm using to get the yaw and pitch. Code: String yaw = this.getConfig().getString("Spawn_Lobby.Yaw"); String pitch = this.getConfig().getString("Spawn_Lobby.Pitch");
so, instead of float, you try to pass strings, and excepting the code to magicly turn them into floats?
Location lobby = new Location(p.getServer().getWorld(newWorld), x, y, z,yaw,pitch); yaw and pitch sould be of type float so you need to pass float values yaw and pitch to the above call not strings.
Yeah but...how do I do that, i've tried doing float yaw and float pitch but neither worked It says change it back to string when i do that.
Then how are you retrieving it from the config file? You have to get it from there (and save it to there) as a float.
Because your using String pitch = this.getConfig().getString("Spawn_Lobby.Pitch"); to get the pitch and yaw. So if you are saving them as a string and getting them as a string thin you need to convert them to a float. Float.parseFloat(pitch) be sure you wrap a try{ }catch(NumberFormatException e){} around the section of code you use the Float.parseFloat()