mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-12 11:21:34 +01:00
Fix /wg flushstates not doing anything.
This commit is contained in:
parent
6b5a12105e
commit
83cad75916
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -42,10 +42,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
||||
|
Loading…
Reference in New Issue
Block a user