/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/WhereisCommand.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/WhereisCommand.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/WhereisCommand.java revision 1236 by torben, Sun Mar 20 16:23:13 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/WhereisCommand.java revision 2432 by torben, Mon Mar 9 13:55:54 2015 UTC
# Line 1  Line 1 
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;
# Line 18  public class WhereisCommand implements C Line 19  public class WhereisCommand implements C
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) {
# Line 35  public class WhereisCommand implements C Line 34  public class WhereisCommand implements C
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          }          }

Legend:
Removed from v.1236  
changed lines
  Added in v.2432

  ViewVC Help
Powered by ViewVC 1.1.20