Fix /wg flushstates not doing anything.

This commit is contained in:
sk89q 2015-01-19 19:04:49 -08:00
parent 6b5a12105e
commit 83cad75916
3 changed files with 11 additions and 6 deletions

View File

@ -34,6 +34,7 @@
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.google.common.base.Preconditions.checkNotNull;
@ -46,6 +47,7 @@ public class Session {
private final HashMap<Class<?>, Handler> handlers = Maps.newLinkedHashMap();
private Location lastValid;
private Set<ProtectedRegion> lastRegionSet;
private final AtomicBoolean needRefresh = new AtomicBoolean(false);
/**
* Create a new session.
@ -137,6 +139,7 @@ void tick(Player player) {
*/
void resetState(Player player) {
initialize(player);
needRefresh.set(true);
}
/**
@ -194,6 +197,10 @@ public Location testMoveTo(Player player, Location to, MoveType moveType) {
public Location testMoveTo(Player player, Location to, MoveType moveType, boolean forced) {
RegionQuery query = getManager().getPlugin().getRegionContainer().createQuery();
if (!forced && needRefresh.getAndSet(false)) {
forced = true;
}
if (forced || Locations.isDifferentBlock(lastValid, to)) {
ApplicableRegionSet toSet = query.getApplicableRegions(to);
@ -206,7 +213,7 @@ public Location testMoveTo(Player player, Location to, MoveType moveType, boolea
Set<ProtectedRegion> entered = Sets.difference(toSet.getRegions(), lastRegionSet);
Set<ProtectedRegion> exited = Sets.difference(lastRegionSet, toSet.getRegions());
if (!entered.isEmpty() || !exited.isEmpty()) {
if (!entered.isEmpty() || !exited.isEmpty() || forced) {
for (Handler handler : handlers.values()) {
if (!handler.onCrossBoundary(player, lastValid, to, toSet, entered, exited, moveType) && moveType.isCancellable()) {
return lastValid;

View File

@ -108,7 +108,7 @@ public boolean hasBypass(Player player, World world) {
public void resetAllStates() {
Collection<? extends Player> players = BukkitUtil.getOnlinePlayers();
for (Player player : players) {
Session session = sessions.getIfPresent(player);
Session session = sessions.getIfPresent(new CacheKey(player));
if (session != null) {
session.resetState(player);
}
@ -123,7 +123,7 @@ public void resetAllStates() {
*/
public void resetState(Player player) {
checkNotNull(player, "player");
@Nullable Session session = sessions.getIfPresent(player);
@Nullable Session session = sessions.getIfPresent(new CacheKey(player));
if (session != null) {
session.resetState(player);
}

View File

@ -42,9 +42,7 @@ protected FlagValueChangeHandler(Session session, Flag<T> flag) {
@Override
public final void initialize(Player player, Location current, ApplicableRegionSet set) {
lastValue = set.queryValue(getPlugin().wrapPlayer(player), flag);
if (lastValue != null) {
onInitialValue(player, set, lastValue);
}
onInitialValue(player, set, lastValue);
}
@Override