Hello everyone Ive created a plugin that is getting popular and people are asking me to fix a little thing they would like. This isssue is when someone sets spawn it sets it to were they want, but not where there looking at? Please if you could help me I really appreciate it! Here is what i got so far. NOTE: it writes the location of spawn on the config.yml. Code:Java public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("setspawn")){if(player.hasPermission("simplespawn.setspawn") || player.isOp()) { int x = player.getLocation().getBlockX(); int y = player.getLocation().getBlockY(); int z = player.getLocation().getBlockZ(); String w = player.getLocation().getWorld().getName().toString(); getConfig().set(".X", Integer.valueOf(x)); getConfig().set(".Y", Integer.valueOf(y)); getConfig().set(".Z", Integer.valueOf(z)); getConfig().set(".W", w); saveConfig(); player.sendMessage(ChatColor.GREEN + "Spawn point set"); player.getWorld().setSpawnLocation(x, y, z); return true;}else{player.sendMessage(ChatColor.RED + "Permission Denied to set Spawn location");}}if(commandLabel.equalsIgnoreCase("spawn")){if(args.length == 0){if(player.hasPermission("simplespawn.spawn") || player.isOp()){ int x = Integer.parseInt(getConfig().getString(".X")); int y = Integer.parseInt(getConfig().getString(".Y")); int z = Integer.parseInt(getConfig().getString(".Z")); World w = getServer().getWorld(getConfig().getString(".W")); Location loc = new Location(w, x, y, z); player.teleport(loc); return true;}else{player.sendMessage(ChatColor.RED + "Permission Denied to spawn");}}else if(args.length == 1){if(player.hasPermission("simplespawn.spawn.other") || player.isOp()){ if (sender.getServer().getPlayer(args[0]) != null) { Player targetPlayer = sender.getServer().getPlayer(args[0]); int x = Integer.parseInt(getConfig().getString(".X")); int y = Integer.parseInt(getConfig().getString(".Y")); int z = Integer.parseInt(getConfig().getString(".Z")); World w = getServer().getWorld(getConfig().getString(".W")); Location loc = new Location(w, x, y, z); targetPlayer.teleport(loc);}else{player.sendMessage(ChatColor.RED + "Player not online!");}}else{player.sendMessage(ChatColor.RED + "Permission Denied to spawn another user");}}}
Kodfod cman1885 I don't know how to define yaw and pitch. Kodfod when i use your code it just gives me an error saying:
Giorgio Have you tried to get the yaw and pitch and set them to a float var? Code:java Player p = (Player)sender;float yaw = p.getLocation().getYaw();float pitch = p.getLocation().getPitch();World w = p.getLocation().getWorld();int x = p.getLocation().getBlockX();int y = p.getLocation().getBlockY();int z = p.getLocation().getBlockZ();Location loc = new Location(w, x, y, z, yaw, pitch);
Kodfod Ok I have not tried this, this is how you define it right? but now how do you set this in as your spawn point? and also how would someone teleport to this location?
yes that is how you would define it, and then you could do: Code:java w.setSpawnLocation(loc); Then do what the poster above me said.
Giorgio Kodfod pitch and yaw are not neccesary http://jd.bukkit.org/apidocs/org/bu...ion(org.bukkit.World, double, double, double) [edit] fixed broken link
Ah because it already has the world argument so then just grab the x, y, and z. or you can listen for the /spawn command and then player.teleport(location); as javoris767 above stated
Im confused, I'm trying to get the players looking location in order to spawn the users where they are looking.
Giorgio This should fix your problems, just make sure you call setSpawn() in onEnable(). Code: public Location spawn; public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if(cmd.getName().equalsIgnoreCase("setspawn")) { if(!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You cannot use this command from console"); } else if(!sender.hasPermission("simplespawn.setspawn")) { sender.sendMessage(ChatColor.RED + "Permission Denied to set Spawn location"); } else { if(args.length != 0) { sender.sendMessage(ChatColor.RED + "Usage: /setspawn"); } else { Player player = (Player)sender; Location location = player.getLocation(); World world = location.getWorld(); double x = location.getX(); double y = location.getY(); double z = location.getZ(); float yaw = location.getYaw(); float pitch = location.getPitch(); FileConfiguration config = getConfig(); config.set(".World", world.getName().toString()); config.set(".X", x); config.set(".Y", y); config.set(".Z", z); config.set(".Yaw", yaw); config.set(".Pitch", pitch); saveConfig(); world.setSpawnLocation((int)x, (int)y, (int)z); this.spawn = location; sender.sendMessage(ChatColor.GREEN + "Spawn point set"); } } } else if(cmd.getName().equalsIgnoreCase("spawn")) { if(args.length > 1) { sender.sendMessage(ChatColor.RED + "Usage: /spawn <player>"); } else if(args.length == 0) { if(!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You cannot use this command from console"); } else if(!sender.hasPermission("simplespawn.spawn")) { sender.sendMessage(ChatColor.RED + "Permission Denied to spawn"); } else { ((Player)sender).teleport(this.spawn); return true; } } else if(args.length == 1) { if(!sender.hasPermission("simplespawn.spawn.other")) { sender.sendMessage(ChatColor.RED + "Permission Denied to spawn another user"); } else { Player target = Bukkit.getPlayerExact(args[0]); if(target == null) { sender.sendMessage(ChatColor.RED + "Player not online!"); } else { target.teleport(this.spawn); } } } } return true; } public void setSpawn() { try { FileConfiguration config = getConfig(); this.spawn = new Location( Bukkit.getWorld(config.getString(".World")), Double.parseDouble(config.getString(".X")), Double.parseDouble(config.getString(".Y")), Double.parseDouble(config.getString(".Z")), Float.parseFloat(config.getString(".Yaw")), Float.parseFloat(config.getString(".Pitch")) ); } catch(Exception e) { getLogger().log(Level.WARNING, "Failed to load spawn location, reverting to default!"); this.spawn = Bukkit.getWorlds().get(0).getSpawnLocation(); } }