1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
import org.bukkit.ChatColor; |
4 |
import org.bukkit.command.Command; |
5 |
import org.bukkit.command.CommandExecutor; |
6 |
import org.bukkit.command.CommandSender; |
7 |
import org.bukkit.entity.Player; |
8 |
|
9 |
public class TeleportCommand implements CommandExecutor { |
10 |
|
11 |
@Override |
12 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
13 |
|
14 |
if (!(sender instanceof Player)) { // it's not a console command |
15 |
return false; |
16 |
} |
17 |
|
18 |
Player p = (Player) sender; |
19 |
|
20 |
if ( ! p.hasPermission("hoeruputils.tp")) { |
21 |
p.sendMessage("You don't have permissions to use teleport"); |
22 |
return true; |
23 |
} |
24 |
|
25 |
if (args.length != 2) { |
26 |
sender.sendMessage("Usage: /tp <source> <destination"); |
27 |
return true; |
28 |
} |
29 |
|
30 |
@SuppressWarnings("deprecation")//user by name is our only option here |
31 |
Player source = p.getServer().getPlayer( args[0] ); |
32 |
if (source == null) { |
33 |
p.sendMessage("Could not find source: " + args[0]); |
34 |
return true; |
35 |
} |
36 |
|
37 |
@SuppressWarnings("deprecation")//user by name is our only option here |
38 |
Player dest = p.getServer().getPlayer( args[1] ); |
39 |
if (dest == null) { |
40 |
p.sendMessage("Could not find destination: " + args[1]); |
41 |
return true; |
42 |
} |
43 |
|
44 |
if (args[0].equals(args[1]) ) { |
45 |
p.sendMessage("you can't tp a player to himself"); |
46 |
return true; |
47 |
} |
48 |
dest.sendMessage( ChatColor.GRAY + source.getName() + " was teleported to you."); |
49 |
source.sendMessage( ChatColor.GRAY + "You was teleported to " + dest.getName() ); |
50 |
|
51 |
if (p != source && p != dest) { |
52 |
p.sendMessage( ChatColor.GRAY + source.getName() + " was teleported to " + dest.getName() ); |
53 |
} |
54 |
|
55 |
source.teleport( dest ); |
56 |
|
57 |
return true; |
58 |
} |
59 |
} |