mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 04:48:34 +00:00
Better enforce the Request lifetime.
Previously, the current request would just get a new EditSession when one was created. Now, a Request is reset before and after: - a command is used and - an interact is fired with the platform This means each action taken will get a single, non-reusable Request. Note that this only applies to actions taken through the platform. API users will not be using requests anyway, since things like Masks, etc. will be constructed directly instead of being passed through the platform's parsers and so on. (e.g. if a plugin loads a schematic into the world with a mask, they should create the EditSession and mask it directly, and not use that Mask again for another EditSession in another World). Also, get rid of a bunch of (some now-)unnecessary EditSession creation during command dispatching. Note that this also fixed the dynamic selection mask, which apparently has been broken for some unknown amount of time.
This commit is contained in:
@ -28,6 +28,7 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.session.storage.JsonFileSessionStore;
|
||||
import com.sk89q.worldedit.session.storage.SessionStore;
|
||||
import com.sk89q.worldedit.session.storage.VoidStore;
|
||||
@ -151,6 +152,7 @@ public class SessionManager {
|
||||
log.warn("Failed to load saved session", e);
|
||||
session = new LocalSession();
|
||||
}
|
||||
Request.request().setSession(session);
|
||||
|
||||
session.setConfiguration(config);
|
||||
session.setBlockChangeLimit(config.defaultChangeLimit);
|
||||
@ -313,7 +315,7 @@ public class SessionManager {
|
||||
/**
|
||||
* Stores the owner of a session, the session, and the last active time.
|
||||
*/
|
||||
private static class SessionHolder {
|
||||
private static final class SessionHolder {
|
||||
private final SessionKey key;
|
||||
private final LocalSession session;
|
||||
private long lastActive = System.currentTimeMillis();
|
||||
|
@ -35,6 +35,7 @@ public final class Request {
|
||||
private @Nullable World world;
|
||||
private @Nullable LocalSession session;
|
||||
private @Nullable EditSession editSession;
|
||||
private boolean valid;
|
||||
|
||||
private Request() {
|
||||
}
|
||||
@ -106,6 +107,20 @@ public final class Request {
|
||||
* Reset the current request and clear all fields.
|
||||
*/
|
||||
public static void reset() {
|
||||
request().invalidate();
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current request object is still valid. Invalid requests may contain outdated values.
|
||||
*
|
||||
* @return true if the request is valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
@ -39,13 +39,13 @@ import java.util.List;
|
||||
|
||||
public class RequestExtent implements Extent {
|
||||
|
||||
private EditSession extent;
|
||||
private Request request;
|
||||
|
||||
protected Extent getExtent() {
|
||||
if (extent == null) {
|
||||
extent = Request.request().getEditSession();
|
||||
if (request == null || !request.isValid()) {
|
||||
request = Request.request();
|
||||
}
|
||||
return extent;
|
||||
return request.getEditSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,7 +103,7 @@ public class RequestExtent implements Extent {
|
||||
@Nullable
|
||||
public Operation commit() {
|
||||
Operation commit = getExtent().commit();
|
||||
extent = null;
|
||||
request = null;
|
||||
return commit;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user