1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
import org.bukkit.ChatColor; |
4 |
import org.bukkit.Location; |
5 |
import org.bukkit.Server; |
6 |
import org.bukkit.World; |
7 |
import org.bukkit.command.Command; |
8 |
import org.bukkit.command.CommandExecutor; |
9 |
import org.bukkit.command.CommandSender; |
10 |
import org.bukkit.entity.Player; |
11 |
|
12 |
public class ZapCommand implements CommandExecutor { |
13 |
|
14 |
|
15 |
@Override |
16 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
17 |
|
18 |
if (!(sender instanceof Player)) { |
19 |
return false; |
20 |
} |
21 |
|
22 |
Player p = (Player) sender; |
23 |
|
24 |
if (args.length <1 || args.length > 2) { |
25 |
p.sendMessage("Usage: /zap <player> [hard]"); |
26 |
return true; |
27 |
} |
28 |
boolean hard = false; |
29 |
if (args.length == 2) { |
30 |
if ( !args[1].equals("hard") ) { |
31 |
p.sendMessage("Usage: /zap <player> [hard]"); |
32 |
return true; |
33 |
} else if (p.isOp() ){ |
34 |
hard = true; |
35 |
} else { |
36 |
p.sendMessage("Only ops can zap hard"); |
37 |
return true; |
38 |
} |
39 |
} |
40 |
|
41 |
|
42 |
Server server = p.getServer(); |
43 |
|
44 |
Player target = server.getPlayer(args[0]); |
45 |
if (target == null) { |
46 |
p.sendMessage("/zap: could not find player " + args[0] ); |
47 |
return true; |
48 |
} |
49 |
|
50 |
World w = target.getWorld(); |
51 |
Location l = target.getLocation(); |
52 |
if (hard == true) { |
53 |
w.strikeLightning(l); |
54 |
} else { |
55 |
w.strikeLightningEffect( l ); |
56 |
} |
57 |
server.broadcastMessage( ChatColor.YELLOW + target.getName() + " was zapped by " + p.getName() ); |
58 |
|
59 |
return true; |
60 |
} |
61 |
} |