From 0601176f552c74f3668a49b2559d938745e0a78f Mon Sep 17 00:00:00 2001 From: ementalo Date: Tue, 26 Apr 2011 12:13:39 +0000 Subject: [PATCH] [trunk] weather / thunder refactor git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1277 e251c2fe-e539-e718-e476-b85c1f46cddb --- .../essentials/commands/Commandthunder.java | 86 +++++++------------ .../essentials/commands/Commandweather.java | 63 +++++++------- 2 files changed, 63 insertions(+), 86 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index 48177e949..ca7a15a0b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -4,10 +4,12 @@ import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.World; + public class Commandthunder extends EssentialsCommand { - public Commandthunder() + public Commandthunder() { super("thunder"); } @@ -15,56 +17,34 @@ public class Commandthunder extends EssentialsCommand @Override public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception { - switch (args.length) - { - case 0: - if (user.isAuthorized("essentials.thunder")) - { - user.sendMessage("§cUsage: /" + commandLabel + " [duration]"); - break; - } - user.sendMessage("§cYou are not allowed to change the thunder"); - break; - case 1: - if (user.isAuthorized("essentials.thunder")) - { - if(args[0].equalsIgnoreCase("true")) - { - user.getWorld().setThundering(true); - user.sendMessage("§7You enabled thunder in your world"); - break; - } - if(args[0].equalsIgnoreCase("false")) - { - user.getWorld().setThundering(false); - user.sendMessage("§7You disabled thunder in your world"); - break; - } - user.sendMessage("§cUsage: /" + commandLabel + " [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 + " [duration]"); - } - user.sendMessage("§cYou are not allowed to change the thunder"); - break; - } - } + + if (args.length < 1) + { + user.sendMessage("§cUsage: /" + commandLabel + " [duration]"); + return; + } + + if (!user.isAuthorized(this)) + { + 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) + { + + world.setThundering(setThunder ? true : false); + world.setThunderDuration(Integer.parseInt(args[1]) * 20); + user.sendMessage("§7You " + (setThunder ? "enabled" : "disabled") + " thunder in your world for " + args[1] + " seconds"); + } + else + { + world.setThundering(setThunder ? true : false); + user.sendMessage("§7You " + (setThunder ? "enabled" : "disabled") + " thunder in your world"); + } + + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index b13eadb43..2d7e9c076 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.World; public class Commandweather extends EssentialsCommand @@ -16,41 +17,37 @@ public class Commandweather extends EssentialsCommand @Override 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 + " [duration]"); - break; - case 1: - if (args[0].equalsIgnoreCase("storm")) - { - user.getWorld().setStorm(true); - user.sendMessage("§7You set the weather in your world to storm"); - break; - } - if (args[0].equalsIgnoreCase("sun")) - { - user.getWorld().setStorm(false); - user.sendMessage("§7You set the weather in your world to sun"); - break; - } - user.sendMessage("§cUsage: /" + commandLabel + " [duration]"); - case 2: - if (args[0].equalsIgnoreCase("storm")) - { - user.getWorld().setStorm(true); - user.getWorld().setWeatherDuration(Integer.parseInt(args[1]) * 20); - user.sendMessage("§7You set the weather in your world to storm for " + args[1] + " seconds"); - 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 + " [duration]"); + return; + } + + if (!user.isAuthorized(this)) + { + user.sendMessage("§cThe power of the sky has been denied to you"); + return; + } + + boolean isStorm = args[0].equalsIgnoreCase("storm"); + World world = user.getWorld(); + user.charge(this); + if (!args[1].isEmpty() || args[1] != null) + { + + world.setStorm(isStorm ? true : false); + 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; + } + else + { + world.setStorm(isStorm ? true : false); + user.sendMessage("§7You set the weather to " + (isStorm ? "storm" : "sun") + " in your world"); + return; } } } + + +