diff --git a/appinfo.properties b/appinfo.properties index 99885af6..d4b30d9c 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,5 +1,5 @@ -#Thu, 22 Aug 2013 17:08:21 -0400 +#Fri, 23 Aug 2013 21:18:29 -0400 program.VERSION=3.1 -program.BUILDNUM=475 -program.BUILDDATE=08/22/2013 05\:08 PM +program.BUILDNUM=479 +program.BUILDDATE=08/23/2013 09\:18 PM diff --git a/buildnumber.properties b/buildnumber.properties index 75491391..af675bf9 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Thu Aug 22 17:08:21 EDT 2013 -build.number=476 +#Fri Aug 23 21:18:29 EDT 2013 +build.number=480 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java index 8890a9ee..20c4ade3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java @@ -159,9 +159,16 @@ public class Command_adminworld extends TFM_Command if (args.length == 2) { - //set time = args[1] : - - playerMsg("Feature not implemented."); + TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]); + if (timeOfDay != null) + { + TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay); + playerMsg("AdminWorld time set to: " + timeOfDay.name()); + } + else + { + playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight"); + } } else { @@ -176,9 +183,16 @@ public class Command_adminworld extends TFM_Command if (args.length == 2) { - //set weather = args[1] : - - playerMsg("Feature not implemented."); + TFM_AdminWorld.WeatherMode weatherMode = TFM_AdminWorld.WeatherMode.getByAlias(args[1]); + if (weatherMode != null) + { + TFM_AdminWorld.getInstance().setWeatherMode(weatherMode); + playerMsg("AdminWorld weather set to: " + weatherMode.name()); + } + else + { + playerMsg("Invalid weather mode. Can be: off, rain, storm"); + } } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_WeatherListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_WeatherListener.java index 0a7585cf..3352212f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_WeatherListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_WeatherListener.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Listener; +import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,6 +13,17 @@ public class TFM_WeatherListener implements Listener @EventHandler(priority = EventPriority.HIGH) public void onThunderChange(ThunderChangeEvent event) { + try + { + if (event.getWorld() == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF) + { + return; + } + } + catch (Exception ex) + { + } + if (event.toThunderState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean()) { event.setCancelled(true); @@ -22,6 +34,17 @@ public class TFM_WeatherListener implements Listener @EventHandler(priority = EventPriority.HIGH) public void onWeatherChange(WeatherChangeEvent event) { + try + { + if (event.getWorld() == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF) + { + return; + } + } + catch (Exception ex) + { + } + if (event.toWeatherState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean()) { event.setCancelled(true); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java index 2dc3c32f..7068ec7e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -26,6 +27,8 @@ public final class TFM_AdminWorld extends TFM_CustomWorld // private Long cacheLastCleared = null; private Map guestList = new HashMap(); + private WeatherMode weatherMode = WeatherMode.OFF; + private TimeOfDay timeOfDay = TimeOfDay.INHERIT; private TFM_AdminWorld() { @@ -207,6 +210,127 @@ public final class TFM_AdminWorld extends TFM_CustomWorld return cached; } + public static enum WeatherMode + { + OFF("off"), + RAIN("rain"), + STORM("storm,thunderstorm"); + // + private final List aliases; + + private WeatherMode(String aliases) + { + this.aliases = Arrays.asList(StringUtils.split(aliases, ",")); + } + + private void setWorldToWeather(World world) + { + world.setStorm(this == RAIN || this == STORM); + world.setWeatherDuration(this == RAIN || this == STORM ? 20 * 60 * 5 : 0); + + world.setThundering(this == STORM); + world.setThunderDuration(this == STORM ? 20 * 60 * 5 : 0); + } + + public static WeatherMode getByAlias(String needle) + { + needle = needle.toLowerCase(); + for (WeatherMode mode : values()) + { + if (mode.aliases.contains(needle)) + { + return mode; + } + } + return null; + } + } + + public static enum TimeOfDay + { + INHERIT(), + SUNRISE("sunrise,morning", 0), + NOON("noon,midday,day", 6000), + SUNSET("sunset,evening", 12000), + MIDNIGHT("midnight,night", 18000); + // + private final int timeTicks; + private final List aliases; + + private TimeOfDay() + { + this.timeTicks = 0; + this.aliases = null; + } + + private TimeOfDay(String aliases, int timeTicks) + { + this.timeTicks = timeTicks; + this.aliases = Arrays.asList(StringUtils.split(aliases, ",")); + } + + public int getTimeTicks() + { + return timeTicks; + } + + public void setWorldToTime(World world) + { + long time = world.getTime(); + time -= time % 24000; + world.setTime(time + 24000 + getTimeTicks()); + } + + public static TimeOfDay getByAlias(String needle) + { + needle = needle.toLowerCase(); + for (TimeOfDay time : values()) + { + if (time.aliases != null && time.aliases.contains(needle)) + { + return time; + } + } + return null; + } + } + + public WeatherMode getWeatherMode() + { + return weatherMode; + } + + public void setWeatherMode(final WeatherMode weatherMode) + { + this.weatherMode = weatherMode; + + try + { + weatherMode.setWorldToWeather(getWorld()); + } + catch (Exception ex) + { + } + } + + public TimeOfDay getTimeOfDay() + { + return timeOfDay; + } + + public void setTimeOfDay(final TimeOfDay timeOfDay) + { + this.timeOfDay = timeOfDay; + + try + { + timeOfDay.setWorldToTime(getWorld()); + } + catch (Exception ex) + { + } + } + public static TFM_AdminWorld getInstance() { return TFM_AdminWorldHolder.INSTANCE; diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java index d2652936..adef71a1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java @@ -44,6 +44,17 @@ public class TFM_Heartbeat extends BukkitRunnable { for (World world : server.getWorlds()) { + try + { + if (world == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF) + { + continue; + } + } + catch (Exception ex) + { + } + if (world.getWeatherDuration() > 0) { world.setThundering(false); diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 3bcc6bef..77f0bba4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -109,6 +109,7 @@ public class TotalFreedomMod extends JavaPlugin world.setThundering(false); world.setStorm(false); world.setThunderDuration(0); + world.setWeatherDuration(0); } }