Hello all I am trying to find the cardinal direction of the player however it all seems to be returning the same value of: 'N'? Code: Code (Text): public String getPlayerDirection(Player player){ double yaw = playerSelf.getLocation().getYaw(); if (yaw >= 0 && yaw < 90) { // South return "S"; } else if (yaw >= 90 && yaw < 180) { // West return "W"; } else if (yaw >= 80 && yaw < 90) { // East return "E"; } else { // North return "N"; } } Thanks!
first things first, in: Code (Text): public String getPlayerDirection(Player player){ double yaw = playerSelf.getLocation().getYaw(); if (yaw >= 0 && yaw < 90) { // South return "S"; } else if (yaw >= 90 && yaw < 180) { // West return "W"; } else if (yaw >= 80 && yaw < 90) { // East return "E"; } else { // North return "N"; } } you have player as the given variable and playerSelf as the variable you are messing with, but no where does it set playerSelf to player. go ahead and try changing it to: Code (Text): public String getPlayerDirection(Player player){ double yaw = player.getLocation().getYaw(); if (yaw >= 0 && yaw < 90) { // South return "S"; } else if (yaw >= 90 && yaw < 180) { // West return "W"; } else if (yaw >= 80 && yaw < 90) { // East return "E"; } else { // North return "N"; } } and see if that helps.
Here is what I have that seems to work for me. Code (Java): public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ if(sender instanceof Player){ Player p = (Player) sender; double y = p.getLocation().getYaw(); String direction = new String(); if(y >= 135 || y < -135){ direction = "North"; } if(y >= -135 && y < -45){ direction = "East"; } if(y >= -45 && y < 45){ direction = "South"; } if(y >= 45 && y < 135){ direction = "West"; } p.sendMessage(String.valueOf(p.getLocation().getYaw())); p.sendMessage(direction); return true; } return false; } https://imgur.com/a/NrMU8T6
A few things here... 1. Whats the compile error? Its a pain to debug an error without the error. 2. What are you using this for? There is probably a better method, avoid the xy problem.