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

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/SpawnCommand.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1587 - (hide annotations) (download)
Mon Aug 8 15:44:27 2011 UTC (12 years, 9 months ago) by torben
File size: 1699 byte(s)
make /spawn permissions controlled
1 torben 1520 package dk.thoerup.bukkit.hoeruputils;
2    
3     import org.bukkit.Location;
4     import org.bukkit.World;
5     import org.bukkit.command.Command;
6     import org.bukkit.command.CommandExecutor;
7     import org.bukkit.command.CommandSender;
8     import org.bukkit.entity.CreatureType;
9     import org.bukkit.entity.Player;
10    
11     public class SpawnCommand implements CommandExecutor {
12    
13    
14     @Override
15     public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
16    
17     if (!(sender instanceof Player)) {
18     return false;
19     }
20     Player p = (Player) sender;
21    
22 torben 1587 if ( ! p.hasPermission("hoeruputils.spawn") ) {
23     p.sendMessage("You don't have permissions to use /spawn");
24     return true;
25     }
26    
27 torben 1520 if (args.length < 1 || args.length > 2) {
28     p.sendMessage("Usage: /spawn <creature> [count] ");
29     return true;
30     }
31    
32     CreatureType creature = CreatureType.fromName( args[0] );
33    
34     if (creature == null) {
35     try {
36     creature = CreatureType.valueOf( args[0].toUpperCase() );
37     } catch (IllegalArgumentException e) {}
38     }
39    
40     if (creature == null) {
41     p.sendMessage("No creature named : " + args[0] );
42     StringBuilder sb = new StringBuilder();
43     for(CreatureType ct : CreatureType.values() ) {
44     sb.append( " ");
45     sb.append( ct.getName() );
46     }
47     p.sendMessage("Valid creatures:" + sb.toString() );
48     return true;
49     }
50    
51    
52     int count = 1;
53     if (args.length == 2) {
54     try {
55     count = Integer.parseInt(args[1]);
56     if (count > 16)
57     count = 16;
58     } catch (Exception e) {
59     p.sendMessage("Invalid number : " + args[1]);
60     return true;
61     }
62     }
63    
64    
65     World w = p.getWorld();
66     Location l = p.getLocation();
67     for (int i=0; i<count; i++) {
68     w.spawnCreature(l, creature);
69     }
70    
71     return true;
72     }
73     }

  ViewVC Help
Powered by ViewVC 1.1.20