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

Contents of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/deprecated/SpawnCommand.java_

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1679 - (show annotations) (download)
Wed Jan 25 21:34:56 2012 UTC (12 years, 3 months ago) by torben
File size: 1699 byte(s)
rename deprecated files to .java_
1 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 if ( ! p.hasPermission("hoeruputils.spawn") ) {
23 p.sendMessage("You don't have permissions to use /spawn");
24 return true;
25 }
26
27 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 }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20