Only store existing per-player time/weather in handlers.

Fixes WORLDGUARD-4124.

This will fix various issues with logging in to regions with these flags
set and then moving out of them, or when moving between two adjacent
regions with the flags set and then moving out.
This commit is contained in:
wizjany 2019-08-18 11:33:04 -04:00
parent 120d2e223d
commit 96d15d6dbf
3 changed files with 16 additions and 12 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}