2011-04-23 00:26:10 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-04-23 00:26:10 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2017-06-11 00:17:43 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2011-04-23 00:26:10 +00:00
|
|
|
import org.bukkit.Server;
|
2011-04-26 12:13:39 +00:00
|
|
|
import org.bukkit.World;
|
2011-04-23 00:26:10 +00:00
|
|
|
|
2017-06-11 00:17:43 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-04-24 22:13:14 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public class Commandweather extends EssentialsCommand {
|
|
|
|
public Commandweather() {
|
|
|
|
super("weather");
|
|
|
|
}
|
2011-04-23 00:26:10 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
//TODO: Remove duplication
|
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
final boolean isStorm;
|
|
|
|
if (args.length < 1) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
final World world = user.getWorld();
|
|
|
|
if (args.length > 1) {
|
2011-04-26 12:13:39 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
world.setStorm(isStorm);
|
|
|
|
world.setWeatherDuration(Integer.parseInt(args[1]) * 20);
|
|
|
|
user.sendMessage(isStorm ? tl("weatherStormFor", world.getName(), args[1]) : tl("weatherSunFor", world.getName(), args[1]));
|
|
|
|
} else {
|
|
|
|
world.setStorm(isStorm);
|
|
|
|
user.sendMessage(isStorm ? tl("weatherStorm", world.getName()) : tl("weatherSun", world.getName()));
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 12:47:32 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
if (args.length < 2) //running from console means inserting a world arg before other args
|
|
|
|
{
|
|
|
|
throw new Exception("When running from console, usage is: /" + commandLabel + " <world> <storm/sun> [duration]");
|
|
|
|
}
|
2011-10-18 16:12:41 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
final boolean isStorm = args[1].equalsIgnoreCase("storm");
|
|
|
|
final World world = server.getWorld(args[0]);
|
|
|
|
if (world == null) {
|
|
|
|
throw new Exception(tl("weatherInvalidWorld", args[0]));
|
|
|
|
}
|
|
|
|
if (args.length > 2) {
|
2011-10-18 16:12:41 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
world.setStorm(isStorm);
|
|
|
|
world.setWeatherDuration(Integer.parseInt(args[2]) * 20);
|
|
|
|
sender.sendMessage(isStorm ? tl("weatherStormFor", world.getName(), args[2]) : tl("weatherSunFor", world.getName(), args[2]));
|
|
|
|
} else {
|
|
|
|
world.setStorm(isStorm);
|
|
|
|
sender.sendMessage(isStorm ? tl("weatherStorm", world.getName()) : tl("weatherSun", world.getName()));
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 00:17:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return Lists.newArrayList("storm", "sun");
|
|
|
|
} else if (args.length == 2) {
|
|
|
|
return COMMON_DURATIONS;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
List<String> worlds = Lists.newArrayList();
|
|
|
|
for (World world : server.getWorlds()) {
|
|
|
|
worlds.add(world.getName());
|
|
|
|
}
|
|
|
|
return worlds;
|
|
|
|
} else if (args.length == 2) {
|
|
|
|
return Lists.newArrayList("storm", "sun");
|
|
|
|
} else if (args.length == 3) {
|
|
|
|
return COMMON_DURATIONS;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-04-23 00:26:10 +00:00
|
|
|
}
|