Skip to content
Permalink
Browse files

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.
  • Loading branch information...
wizjany committed Aug 18, 2019
1 parent 120d2e2 commit 96d15d6dbf77ed159c4e2b1564e9536285d65630
@@ -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
@@ -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;
}

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

0 comments on commit 96d15d6

Please sign in to comment.
You can’t perform that action at this time.