1 |
package dk.thoerup.bukkit.hoeruputils; |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
|
3 |
|
import org.bukkit.ChatColor; |
4 |
import org.bukkit.Location; |
import org.bukkit.Location; |
5 |
import org.bukkit.Server; |
import org.bukkit.Server; |
6 |
import org.bukkit.command.Command; |
import org.bukkit.command.Command; |
19 |
@Override |
@Override |
20 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
21 |
|
|
22 |
if (!(sender instanceof Player)) { |
|
|
sender.sendMessage("Whereis: What are you"); |
|
|
return true; |
|
|
} |
|
23 |
|
|
24 |
if (args.length != 1) { |
if (args.length != 1) { |
25 |
sender.sendMessage("Usage: /whereis <playername>"); |
sender.sendMessage("Usage: /whereis <playername>"); |
26 |
return true; |
return true; |
27 |
} |
} |
28 |
|
|
29 |
|
@SuppressWarnings("deprecation")//user by name is our only option here |
30 |
Player target = server.getPlayer(args[0]); |
Player target = server.getPlayer(args[0]); |
31 |
|
|
32 |
if (target == null) { |
if (target == null) { |
34 |
return true; |
return true; |
35 |
} |
} |
36 |
|
|
37 |
Location targetLoc = target.getLocation(); |
Location targetLoc = target.getLocation(); |
38 |
Player player = (Player) sender; |
Player player = (Player) sender; |
39 |
|
|
40 |
|
if (player.getLocation().getWorld() != targetLoc.getWorld()) { |
41 |
|
sender.sendMessage("Whereis: player " + args[0] + " is in another world: " + targetLoc.getWorld().getName() ); |
42 |
|
return true; |
43 |
|
} |
44 |
|
|
45 |
int dist = calcDistance(player.getLocation(), targetLoc); |
int dist = calcDistance(player.getLocation(), targetLoc); |
46 |
int bearing = calcBearing(player.getLocation(), targetLoc); |
int bearing = calcBearing(player.getLocation(), targetLoc); |
47 |
|
|
48 |
|
|
49 |
target.sendMessage("Whereis: you are tracked by " + player.getName() ); |
//target.sendMessage("Whereis: you are tracked by " + player.getName() ); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
player.sendMessage("Whereis: " + target.getName() + " is at " + (int)targetLoc.getX() + "," + (int)targetLoc.getY() + "," +(int)targetLoc.getZ() ); |
player.sendMessage( ChatColor.WHITE + String.format("Whereis: %s is at %d,%d,%d", target.getName(), (int)targetLoc.getX(), (int)targetLoc.getY(), (int)targetLoc.getZ()) ); |
54 |
player.sendMessage("Distance: " + dist + ", bearing: " + bearing + "(" + getBearingStr(bearing) + ")" ); |
player.sendMessage( ChatColor.WHITE + "Distance: " + dist + ", bearing: " + bearing + "(" + getBearingStr(bearing) + ")" ); |
55 |
|
|
56 |
return true; |
return true; |
57 |
} |
} |