diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java index df0ca8e3..6e1144b5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java @@ -120,7 +120,8 @@ public void setExhaustion(float exhaustion) { @Override public WeatherType getPlayerWeather() { - return null; + org.bukkit.WeatherType playerWeather = getPlayer().getPlayerWeather(); + return playerWeather == null ? null : playerWeather == org.bukkit.WeatherType.CLEAR ? WeatherTypes.CLEAR : WeatherTypes.RAIN; } @Override diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/TimeLockFlag.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/TimeLockFlag.java index 33c2e098..3090a9c7 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/TimeLockFlag.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/TimeLockFlag.java @@ -39,7 +39,7 @@ public TimeLockFlag create(Session session) { } } - private Long initialTime; + private long initialTime; private boolean initialRelative; private static Pattern timePattern = Pattern.compile("([+\\-])?\\d+"); @@ -54,10 +54,7 @@ private void updatePlayerTime(LocalPlayer player, @Nullable String value) { return; } boolean relative = value.startsWith("+") || value.startsWith("-"); - Long time = Long.valueOf(value); -// if (!relative && (time < 0L || time > 24000L)) { // invalid time, reset to 0 -// time = 0L; -// } + long time = Long.parseLong(value); player.setPlayerTime(time, relative); } @@ -70,15 +67,20 @@ protected void onInitialValue(LocalPlayer player, ApplicableRegionSet set, Strin @Override protected boolean onSetValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, String currentValue, String lastValue, MoveType moveType) { + if (lastValue == null) { + initialRelative = player.isPlayerTimeRelative(); + initialTime = player.getPlayerTimeOffset(); + } updatePlayerTime(player, currentValue); return true; } @Override protected boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, String lastValue, MoveType moveType) { + // in the case that time = 0 and relative = true, this is the same as resetPlayerTime player.setPlayerTime(initialTime, initialRelative); - initialRelative = true; initialTime = 0L; + initialRelative = true; return true; } diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java index d75bf903..1e1eb56a 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java @@ -45,16 +45,17 @@ public WeatherLockFlag(Session session) { @Override protected void onInitialValue(LocalPlayer player, ApplicableRegionSet set, WeatherType value) { - if (value == null) { - initialWeather = null; - return; + initialWeather = player.getPlayerWeather(); + if (value != null) { + player.setPlayerWeather(value); } - initialWeather = value; - player.setPlayerWeather(value); } @Override protected boolean onSetValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, WeatherType currentValue, WeatherType lastValue, MoveType moveType) { + if (lastValue == null) { + initialWeather = player.getPlayerWeather(); + } player.setPlayerWeather(currentValue); return true; }