2011-04-23 00:26:10 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-04-23 00:26:10 +00:00
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import org.bukkit.Server;
|
2011-04-26 12:13:39 +00:00
|
|
|
import org.bukkit.World;
|
2011-10-18 16:12:41 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-04-23 00:26:10 +00:00
|
|
|
|
2011-04-24 22:13:14 +00:00
|
|
|
|
2011-04-23 00:26:10 +00:00
|
|
|
public class Commandweather extends EssentialsCommand
|
|
|
|
{
|
2011-04-24 22:13:14 +00:00
|
|
|
public Commandweather()
|
2011-04-23 00:26:10 +00:00
|
|
|
{
|
|
|
|
super("weather");
|
|
|
|
}
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
//TODO: Remove duplication
|
2011-04-23 00:26:10 +00:00
|
|
|
@Override
|
2011-11-18 19:30:05 +00:00
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-04-23 00:26:10 +00:00
|
|
|
{
|
2012-08-07 23:52:43 +00:00
|
|
|
final boolean isStorm;
|
2011-04-26 12:13:39 +00:00
|
|
|
if (args.length < 1)
|
2011-04-24 22:13:14 +00:00
|
|
|
{
|
2012-08-07 23:52:43 +00:00
|
|
|
if (commandLabel.equalsIgnoreCase("sun") || commandLabel.equalsIgnoreCase("esun"))
|
|
|
|
{
|
|
|
|
isStorm = false;
|
|
|
|
}
|
|
|
|
else if (commandLabel.equalsIgnoreCase("storm") || commandLabel.equalsIgnoreCase("estorm")
|
|
|
|
|| commandLabel.equalsIgnoreCase("rain") || commandLabel.equalsIgnoreCase("erain"))
|
|
|
|
{
|
|
|
|
isStorm = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isStorm = args[0].equalsIgnoreCase("storm");
|
2011-04-26 12:13:39 +00:00
|
|
|
}
|
2011-11-18 19:30:05 +00:00
|
|
|
final World world = user.getWorld();
|
2011-04-26 22:46:34 +00:00
|
|
|
if (args.length > 1)
|
2011-04-26 12:13:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
world.setStorm(isStorm ? true : false);
|
|
|
|
world.setWeatherDuration(Integer.parseInt(args[1]) * 20);
|
2011-05-15 01:30:54 +00:00
|
|
|
user.sendMessage(isStorm
|
2011-11-21 01:55:26 +00:00
|
|
|
? _("weatherStormFor", world.getName(), args[1])
|
|
|
|
: _("weatherSunFor", world.getName(), args[1]));
|
2011-04-26 12:13:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
world.setStorm(isStorm ? true : false);
|
2011-05-15 01:30:54 +00:00
|
|
|
user.sendMessage(isStorm
|
2011-11-21 01:55:26 +00:00
|
|
|
? _("weatherStorm", world.getName())
|
|
|
|
: _("weatherSun", world.getName()));
|
2011-10-18 16:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-19 12:47:32 +00:00
|
|
|
|
2011-11-28 02:54:19 +00:00
|
|
|
//TODO: Translate these
|
2011-10-19 12:47:32 +00:00
|
|
|
@Override
|
2011-11-18 19:30:05 +00:00
|
|
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-10-19 12:47:32 +00:00
|
|
|
{
|
2011-10-18 16:12:41 +00:00
|
|
|
if (args.length < 2) //running from console means inserting a world arg before other args
|
|
|
|
{
|
2011-10-19 12:47:32 +00:00
|
|
|
throw new Exception("When running from console, usage is: /" + commandLabel + " <world> <storm/sun> [duration]");
|
2011-10-18 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 19:30:05 +00:00
|
|
|
final boolean isStorm = args[1].equalsIgnoreCase("storm");
|
|
|
|
final World world = server.getWorld(args[0]);
|
2011-10-18 16:12:41 +00:00
|
|
|
if (world == null)
|
|
|
|
{
|
2011-10-19 12:47:32 +00:00
|
|
|
throw new Exception("World named " + args[0] + " not found!");
|
2011-10-18 16:12:41 +00:00
|
|
|
}
|
|
|
|
if (args.length > 2)
|
|
|
|
{
|
|
|
|
|
|
|
|
world.setStorm(isStorm ? true : false);
|
2011-10-19 12:47:32 +00:00
|
|
|
world.setWeatherDuration(Integer.parseInt(args[2]) * 20);
|
2011-10-18 16:12:41 +00:00
|
|
|
sender.sendMessage(isStorm
|
2011-11-21 01:55:26 +00:00
|
|
|
? _("weatherStormFor", world.getName(), args[2])
|
|
|
|
: _("weatherSunFor", world.getName(), args[2]));
|
2011-10-18 16:12:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
world.setStorm(isStorm ? true : false);
|
|
|
|
sender.sendMessage(isStorm
|
2011-11-21 01:55:26 +00:00
|
|
|
? _("weatherStorm", world.getName())
|
|
|
|
: _("weatherSun", world.getName()));
|
2011-04-24 22:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-23 00:26:10 +00:00
|
|
|
}
|