[trunk] weather / thunder refactor

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1277 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-04-26 12:13:39 +00:00
parent 80eee83f10
commit 6a892fcfc1
2 changed files with 63 additions and 86 deletions

View file

@ -4,6 +4,8 @@ import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World;
public class Commandthunder extends EssentialsCommand public class Commandthunder extends EssentialsCommand
{ {
@ -15,56 +17,34 @@ public class Commandthunder extends EssentialsCommand
@Override @Override
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
{ {
switch (args.length)
{ if (args.length < 1)
case 0:
if (user.isAuthorized("essentials.thunder"))
{ {
user.sendMessage("§cUsage: /" + commandLabel + " <true/false> [duration]"); user.sendMessage("§cUsage: /" + commandLabel + " <true/false> [duration]");
break; return;
} }
user.sendMessage("§cYou are not allowed to change the thunder");
break; if (!user.isAuthorized(this))
case 1:
if (user.isAuthorized("essentials.thunder"))
{ {
if(args[0].equalsIgnoreCase("true")) user.sendMessage("§cThe power of the Thor has been denied to you");
return;
}
user.charge(this);
World world = user.getWorld();
boolean setThunder = args[0].equalsIgnoreCase("true");
if (!args[1].isEmpty() || args[1] != null)
{ {
user.getWorld().setThundering(true);
user.sendMessage("§7You enabled thunder in your world"); world.setThundering(setThunder ? true : false);
break; world.setThunderDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage("§7You " + (setThunder ? "enabled" : "disabled") + " thunder in your world for " + args[1] + " seconds");
} }
if(args[0].equalsIgnoreCase("false")) else
{ {
user.getWorld().setThundering(false); world.setThundering(setThunder ? true : false);
user.sendMessage("§7You disabled thunder in your world"); user.sendMessage("§7You " + (setThunder ? "enabled" : "disabled") + " thunder in your world");
break;
}
user.sendMessage("§cUsage: /" + commandLabel + " <true/false> [duration]");
}
user.sendMessage("§cYou are not allowed to change the thunder");
break;
case 2:
if (user.isAuthorized("essentials.thunder"))
{
if(args[0].equalsIgnoreCase("true"))
{
user.getWorld().setThundering(true);
user.getWorld().setWeatherDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage("§7You enabled thunder in your world for " + args[1] + " seconds");
break;
}
if(args[0].equalsIgnoreCase("false"))
{
user.getWorld().setThundering(false);
user.getWorld().setWeatherDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage("§7You disabled thunder in your world for " + args[1] + " seconds");
break;
}
user.sendMessage("§cUsage: /" + commandLabel + " <true/false> [duration]");
}
user.sendMessage("§cYou are not allowed to change the thunder");
break;
} }
} }
} }

View file

@ -4,6 +4,7 @@ import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World;
public class Commandweather extends EssentialsCommand public class Commandweather extends EssentialsCommand
@ -16,41 +17,37 @@ public class Commandweather extends EssentialsCommand
@Override @Override
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
{ {
switch (args.length) if (args.length < 1)
{ {
case 0:
user.sendMessage("§cUsage: /" + commandLabel + " <storm/sun> [duration]"); user.sendMessage("§cUsage: /" + commandLabel + " <storm/sun> [duration]");
break; return;
case 1: }
if (args[0].equalsIgnoreCase("storm"))
if (!user.isAuthorized(this))
{ {
user.getWorld().setStorm(true); user.sendMessage("§cThe power of the sky has been denied to you");
user.sendMessage("§7You set the weather in your world to storm"); return;
break;
} }
if (args[0].equalsIgnoreCase("sun"))
boolean isStorm = args[0].equalsIgnoreCase("storm");
World world = user.getWorld();
user.charge(this);
if (!args[1].isEmpty() || args[1] != null)
{ {
user.getWorld().setStorm(false);
user.sendMessage("§7You set the weather in your world to sun"); world.setStorm(isStorm ? true : false);
break; world.setWeatherDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage("§7You set the weather to " + (isStorm ? "storm" : "sun") + " in your world for " + args[1] + " seconds");
return;
} }
user.sendMessage("§cUsage: /" + commandLabel + " <storm/sun> [duration]"); else
case 2:
if (args[0].equalsIgnoreCase("storm"))
{ {
user.getWorld().setStorm(true); world.setStorm(isStorm ? true : false);
user.getWorld().setWeatherDuration(Integer.parseInt(args[1]) * 20); user.sendMessage("§7You set the weather to " + (isStorm ? "storm" : "sun") + " in your world");
user.sendMessage("§7You set the weather in your world to storm for " + args[1] + " seconds"); return;
break;
}
if (args[0].equalsIgnoreCase("sun"))
{
user.getWorld().setStorm(false);
user.getWorld().setWeatherDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage("§7You set the weather in your world to sun for " + args[1] + " seconds");
break;
}
user.sendMessage("§cUsage: /" + commandLabel + " <storm/sun> [duration]");
} }
} }
} }