001    package org.bukkit.command.defaults;
002    
003    import java.util.List;
004    
005    import org.apache.commons.lang.Validate;
006    import org.bukkit.Bukkit;
007    import org.bukkit.ChatColor;
008    import org.bukkit.World;
009    import org.bukkit.command.Command;
010    import org.bukkit.command.CommandSender;
011    import org.bukkit.entity.Player;
012    
013    import com.google.common.collect.ImmutableList;
014    
015    public class ToggleDownfallCommand extends VanillaCommand {
016        public ToggleDownfallCommand() {
017            super("toggledownfall");
018            this.description = "Toggles rain on/off on a given world";
019            this.usageMessage = "/toggledownfall";
020            this.setPermission("bukkit.command.toggledownfall");
021        }
022    
023        @Override
024        public boolean execute(CommandSender sender, String currentAlias, String[] args) {
025            if (!testPermission(sender)) return true;
026    
027            World world = null;
028    
029            if (args.length == 1) {
030                world = Bukkit.getWorld(args[0]);
031    
032                if (world == null) {
033                    sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'");
034                    return true;
035                }
036            } else if (sender instanceof Player) {
037                world = ((Player) sender).getWorld();
038            } else {
039                world = Bukkit.getWorlds().get(0);
040            }
041    
042            Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'");
043            world.setStorm(!world.hasStorm());
044    
045            return true;
046        }
047    
048        @Override
049        public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
050            Validate.notNull(sender, "Sender cannot be null");
051            Validate.notNull(args, "Arguments cannot be null");
052            Validate.notNull(alias, "Alias cannot be null");
053    
054            return ImmutableList.of();
055        }
056    }