mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Implement weather and time control in /adminworld.
This commit is contained in:
parent
1f32455e06
commit
143b323854
@ -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.VERSION=3.1
|
||||||
program.BUILDNUM=475
|
program.BUILDNUM=479
|
||||||
program.BUILDDATE=08/22/2013 05\:08 PM
|
program.BUILDDATE=08/23/2013 09\:18 PM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Thu Aug 22 17:08:21 EDT 2013
|
#Fri Aug 23 21:18:29 EDT 2013
|
||||||
build.number=476
|
build.number=480
|
||||||
|
@ -159,9 +159,16 @@ public class Command_adminworld extends TFM_Command
|
|||||||
|
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
//set time = args[1] : <morning|noon|evening|night>
|
TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
|
||||||
|
if (timeOfDay != null)
|
||||||
playerMsg("Feature not implemented.");
|
{
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -176,9 +183,16 @@ public class Command_adminworld extends TFM_Command
|
|||||||
|
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
//set weather = args[1] : <off|on|storm>
|
TFM_AdminWorld.WeatherMode weatherMode = TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
|
||||||
|
if (weatherMode != null)
|
||||||
playerMsg("Feature not implemented.");
|
{
|
||||||
|
TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
|
||||||
|
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Invalid weather mode. Can be: off, rain, storm");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Listener;
|
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -12,6 +13,17 @@ public class TFM_WeatherListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onThunderChange(ThunderChangeEvent event)
|
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())
|
if (event.toThunderState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -22,6 +34,17 @@ public class TFM_WeatherListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onWeatherChange(WeatherChangeEvent event)
|
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())
|
if (event.toWeatherState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,6 +27,8 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
|
|||||||
//
|
//
|
||||||
private Long cacheLastCleared = null;
|
private Long cacheLastCleared = null;
|
||||||
private Map<Player, Player> guestList = new HashMap<Player, Player>();
|
private Map<Player, Player> guestList = new HashMap<Player, Player>();
|
||||||
|
private WeatherMode weatherMode = WeatherMode.OFF;
|
||||||
|
private TimeOfDay timeOfDay = TimeOfDay.INHERIT;
|
||||||
|
|
||||||
private TFM_AdminWorld()
|
private TFM_AdminWorld()
|
||||||
{
|
{
|
||||||
@ -207,6 +210,127 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
|
|||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enum WeatherMode
|
||||||
|
{
|
||||||
|
OFF("off"),
|
||||||
|
RAIN("rain"),
|
||||||
|
STORM("storm,thunderstorm");
|
||||||
|
//
|
||||||
|
private final List<String> 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<String> 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()
|
public static TFM_AdminWorld getInstance()
|
||||||
{
|
{
|
||||||
return TFM_AdminWorldHolder.INSTANCE;
|
return TFM_AdminWorldHolder.INSTANCE;
|
||||||
|
@ -44,6 +44,17 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||||||
{
|
{
|
||||||
for (World world : server.getWorlds())
|
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)
|
if (world.getWeatherDuration() > 0)
|
||||||
{
|
{
|
||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
|
@ -109,6 +109,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
world.setStorm(false);
|
world.setStorm(false);
|
||||||
world.setThunderDuration(0);
|
world.setThunderDuration(0);
|
||||||
|
world.setWeatherDuration(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user