mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-10 18:37:39 +01:00
Introduce uninitialize for sessions (#1940)
* Introduce uninitialize for sessions * Add FlagValueChangeHandler#onClearValue
This commit is contained in:
parent
f1f1e8aa7d
commit
bd1d772faa
@ -146,6 +146,7 @@ public void load() {
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
sessionManager.shutdown();
|
||||
configuration.unload();
|
||||
regionContainer.shutdown();
|
||||
}
|
||||
|
@ -148,6 +148,8 @@ public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (loc != null) {
|
||||
player.teleport(BukkitAdapter.adapt(loc));
|
||||
}
|
||||
|
||||
session.uninitialize(localPlayer);
|
||||
}
|
||||
|
||||
private class EntityMountListener implements Listener {
|
||||
|
@ -100,4 +100,11 @@ public boolean isUsingTimings() {
|
||||
public void setUsingTimings(boolean useTimings) {
|
||||
this.useTimings = useTimings;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
get(localPlayer).uninitialize(localPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,21 @@ public void initialize(LocalPlayer player) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninitialize the session.
|
||||
*
|
||||
* @param player The player
|
||||
*/
|
||||
public void uninitialize(LocalPlayer player) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(location);
|
||||
|
||||
for (Handler handler : handlers.values()) {
|
||||
handler.uninitialize(player, location, set);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick the session.
|
||||
*
|
||||
|
@ -45,6 +45,12 @@ public final void initialize(LocalPlayer player, Location current, ApplicableReg
|
||||
onInitialValue(player, set, lastValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void uninitialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
|
||||
onClearValue(player, set);
|
||||
lastValue = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
||||
if (entered.isEmpty() && exited.isEmpty()
|
||||
@ -74,4 +80,8 @@ public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, A
|
||||
|
||||
protected abstract boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, T lastValue, MoveType moveType);
|
||||
|
||||
protected void onClearValue(LocalPlayer player, ApplicableRegionSet set) {
|
||||
Location current = player.getLocation();
|
||||
onAbsentValue(player, current, current, set, lastValue, MoveType.OTHER_NON_CANCELLABLE);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,16 @@ public Session getSession() {
|
||||
public void initialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the session should clear its caches.
|
||||
*
|
||||
* @param player The player
|
||||
* @param current The player's current location
|
||||
* @param set The regions for the current location
|
||||
*/
|
||||
public void uninitialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when {@link Session#testMoveTo(LocalPlayer, Location, MoveType)} is called.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user