Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ToggleDownfallCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.List;
4 
5 import org.apache.commons.lang.Validate;
6 import org.bukkit.Bukkit;
7 import org.bukkit.ChatColor;
8 import org.bukkit.World;
11 import org.bukkit.entity.Player;
12 
13 import com.google.common.collect.ImmutableList;
14 
15 public class ToggleDownfallCommand extends VanillaCommand {
16  public ToggleDownfallCommand() {
17  super("toggledownfall");
18  this.description = "Toggles rain on/off on a given world";
19  this.usageMessage = "/toggledownfall";
20  this.setPermission("bukkit.command.toggledownfall");
21  }
22 
23  @Override
24  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
25  if (!testPermission(sender)) return true;
26 
27  World world = null;
28 
29  if (args.length == 1) {
30  world = Bukkit.getWorld(args[0]);
31 
32  if (world == null) {
33  sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'");
34  return true;
35  }
36  } else if (sender instanceof Player) {
37  world = ((Player) sender).getWorld();
38  } else {
39  world = Bukkit.getWorlds().get(0);
40  }
41 
42  Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'");
43  world.setStorm(!world.hasStorm());
44 
45  return true;
46  }
47 
48  @Override
49  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
50  Validate.notNull(sender, "Sender cannot be null");
51  Validate.notNull(args, "Arguments cannot be null");
52  Validate.notNull(alias, "Alias cannot be null");
53 
54  return ImmutableList.of();
55  }
56 }
boolean testPermission(CommandSender target)
boolean hasStorm()
static World getWorld(String name)
Definition: Bukkit.java:257
void sendMessage(String message)
void setPermission(String permission)
void setStorm(boolean hasStorm)
static List< World > getWorlds()
Definition: Bukkit.java:229
String getName()