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