diff options
author | EvilSeph <evilseph@gmail.com> | 2012-10-29 02:39:05 -0400 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-10-29 02:48:40 -0400 |
commit | 8cc80425f0484b90e75efdfd4c0bd0583dd95110 (patch) | |
tree | 31c3b06d81c2f841ce9e764bd22e7b0c65317d5f /src/main | |
parent | 9ea682a4a10e496c4708399e2a21cbc6413d8e2f (diff) | |
download | bukkit-8cc80425f0484b90e75efdfd4c0bd0583dd95110.tar bukkit-8cc80425f0484b90e75efdfd4c0bd0583dd95110.tar.gz bukkit-8cc80425f0484b90e75efdfd4c0bd0583dd95110.tar.lz bukkit-8cc80425f0484b90e75efdfd4c0bd0583dd95110.tar.xz bukkit-8cc80425f0484b90e75efdfd4c0bd0583dd95110.zip |
Add default WeatherCommand. Partially fixes BUKKIT-2671
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/command/SimpleCommandMap.java | 1 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/defaults/WeatherCommand.java | 78 |
2 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index 6254c0a2..8b28d906 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -54,6 +54,7 @@ public class SimpleCommandMap implements CommandMap { fallbackCommands.add(new DefaultGameModeCommand()); fallbackCommands.add(new SeedCommand()); fallbackCommands.add(new DifficultyCommand()); + fallbackCommands.add(new WeatherCommand()); } public SimpleCommandMap(final Server server) { diff --git a/src/main/java/org/bukkit/command/defaults/WeatherCommand.java b/src/main/java/org/bukkit/command/defaults/WeatherCommand.java new file mode 100644 index 00000000..07e93c51 --- /dev/null +++ b/src/main/java/org/bukkit/command/defaults/WeatherCommand.java @@ -0,0 +1,78 @@ +package org.bukkit.command.defaults; + +import com.google.common.collect.ImmutableList; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.util.StringUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class WeatherCommand extends VanillaCommand { + private static final List<String> WEATHER_TYPES = ImmutableList.of("clear", "rain", "thunder"); + + public WeatherCommand() { + super("weather"); + this.description = "Changes the weather"; + this.usageMessage = "/weather <clear/rain/thunder> [duration in seconds]"; + this.setPermission("bukkit.command.weather"); + } + + @Override + public boolean execute(CommandSender sender, String currentAlias, String[] args) { + if (!testPermission(sender)) return true; + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); + return false; + } + + int duration = (300 + new Random().nextInt(600)) * 20; + if (args.length >= 2) { + duration = getInteger(sender, args[1], 1, 1000000) * 20; + } + + World world = Bukkit.getWorlds().get(0); + + world.setWeatherDuration(duration); + world.setThunderDuration(duration); + + if ("clear".equalsIgnoreCase(args[0])) { + world.setStorm(false); + world.setThundering(false); + Command.broadcastCommandMessage(sender, "Changed weather to clear for " + (duration / 20) + " seconds."); + } else if ("rain".equalsIgnoreCase(args[0])) { + world.setStorm(true); + world.setThundering(false); + Command.broadcastCommandMessage(sender, "Changed weather to rainy for " + (duration / 20) + " seconds."); + } else if ("thunder".equalsIgnoreCase(args[0])) { + world.setStorm(true); + world.setThundering(true); + Command.broadcastCommandMessage(sender, "Changed weather to thundering " + (duration / 20) + " seconds."); + } + + return true; + } + + @Override + public boolean matches(String input) { + return input.equalsIgnoreCase("weather"); + } + + @Override + public List<String> tabComplete(CommandSender sender, String alias, String[] args) { + Validate.notNull(sender, "Sender cannot be null"); + Validate.notNull(args, "Arguments cannot be null"); + Validate.notNull(alias, "Alias cannot be null"); + + if (args.length == 1) { + return StringUtil.copyPartialMatches(args[0], WEATHER_TYPES, new ArrayList<String>(WEATHER_TYPES.size())); + } + + return ImmutableList.of(); + } +} |