Skip to content
Permalink
Browse files

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.
  • Loading branch information...
wizjany committed Mar 16, 2019
1 parent 6b7cb69 commit 8ff56e5fb78e2e4541ded815080edf99f097b68f
Showing with 205 additions and 175 deletions.
  1. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java
  2. +0 −3 worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java
  3. +0 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java
  4. +3 −4 worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java
  5. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java
  6. +6 −6 worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java
  7. +3 −3 worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java
  8. +4 −6 worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java
  9. +2 −3 worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java
  10. +14 −14 worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java
  11. +5 −6 worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java
  12. +3 −4 worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java
  13. +6 −7 worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java
  14. +5 −6 worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java
  15. +2 −3 worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java
  16. +0 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java
  17. +14 −3 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java
  18. +109 −96 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java
  19. +2 −0 worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java
  20. +3 −1 worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java
  21. +15 −0 worldedit-core/src/main/java/com/sk89q/worldedit/session/request/Request.java
  22. +5 −5 worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestExtent.java
@@ -875,9 +875,10 @@ public EditSession createEditSession(Player player) {
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(player.isPlayer() ? player.getWorld() : null,
getBlockChangeLimit(), blockBag, player);
Request.request().setEditSession(editSession);

editSession.setFastMode(fastMode);
editSession.setReorderMode(reorderMode);
Request.request().setEditSession(editSession);
editSession.setMask(mask);

return editSession;
@@ -42,7 +42,6 @@
import com.sk89q.worldedit.scripting.CraftScriptEngine;
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.EventBus;
@@ -595,8 +594,6 @@ public boolean handleBlockLeftClick(Player player, Location clicked) {
* @throws WorldEditException
*/
public void runScript(Player player, File f, String[] args) throws WorldEditException {
Request.reset();

String filename = f.getPath();
int index = filename.lastIndexOf('.');
String ext = filename.substring(index + 1);
@@ -24,7 +24,6 @@
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@@ -23,7 +23,6 @@
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;

import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;
@@ -63,7 +62,7 @@ public ChunkCommands(WorldEdit worldEdit) {
max = 0
)
@CommandPermissions("worldedit.chunkinfo")
public void chunkInfo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void chunkInfo(Player player) throws WorldEditException {
Location pos = player.getBlockIn();
int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);
@@ -87,7 +86,7 @@ public void chunkInfo(Player player, LocalSession session, EditSession editSessi
max = 0
)
@CommandPermissions("worldedit.listchunks")
public void listChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void listChunks(Player player, LocalSession session) throws WorldEditException {
Set<BlockVector2> chunks = session.getSelection(player.getWorld()).getChunks();

for (BlockVector2 chunk : chunks) {
@@ -104,7 +103,7 @@ public void listChunks(Player player, LocalSession session, EditSession editSess
)
@CommandPermissions("worldedit.delchunks")
@Logging(REGION)
public void deleteChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void deleteChunks(Player player, LocalSession session) throws WorldEditException {
player.print("Note that this command does not yet support the mcregion format.");
LocalConfiguration config = worldEdit.getConfiguration();

@@ -211,7 +211,7 @@ public void rotate(Player player, LocalSession session, Double yRotate, @Optiona
max = 1
)
@CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session, EditSession editSession,
public void flip(Player player, LocalSession session,
@Optional(Direction.AIM) @Direction BlockVector3 direction) throws WorldEditException {
ClipboardHolder holder = session.getClipboard();
AffineTransform transform = new AffineTransform();
@@ -228,7 +228,7 @@ public void flip(Player player, LocalSession session, EditSession editSession,
max = 0
)
@CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
public void clearClipboard(Player player, LocalSession session) throws WorldEditException {
session.setClipboard(null);
player.print("Clipboard cleared.");
}
@@ -63,7 +63,7 @@ public GeneralCommands(WorldEdit worldEdit) {
max = 1
)
@CommandPermissions("worldedit.limit")
public void limit(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void limit(Player player, LocalSession session, CommandContext args) throws WorldEditException {

LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
@@ -93,7 +93,7 @@ public void limit(Player player, LocalSession session, EditSession editSession,
max = 1
)
@CommandPermissions("worldedit.timeout")
public void timeout(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void timeout(Player player, LocalSession session, CommandContext args) throws WorldEditException {

LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted");
@@ -123,7 +123,7 @@ public void timeout(Player player, LocalSession session, EditSession editSession
max = 1
)
@CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void fast(Player player, LocalSession session, CommandContext args) throws WorldEditException {

String newState = args.getString(0, null);
if (session.hasFastMode()) {
@@ -153,7 +153,7 @@ public void fast(Player player, LocalSession session, EditSession editSession, C
max = 1
)
@CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void reorderMode(Player player, LocalSession session, CommandContext args) throws WorldEditException {
String newState = args.getString(0, null);
if (newState == null) {
player.print("The reorder mode is " + session.getReorderMode().getDisplayName());
@@ -213,7 +213,7 @@ public void drawSelection(Player player, LocalSession session, CommandContext ar
max = -1
)
@CommandPermissions("worldedit.global-mask")
public void gmask(Player player, LocalSession session, EditSession editSession, @Optional Mask mask) throws WorldEditException {
public void gmask(Player player, LocalSession session, @Optional Mask mask) throws WorldEditException {
if (mask == null) {
session.setMask((Mask) null);
player.print("Global mask disabled.");
@@ -230,7 +230,7 @@ public void gmask(Player player, LocalSession session, EditSession editSession,
min = 0,
max = 0
)
public void togglePlace(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void togglePlace(Player player, LocalSession session) throws WorldEditException {

if (session.togglePlacementPosition()) {
player.print("Now placing at pos #1.");
@@ -55,7 +55,7 @@ public HistoryCommands(WorldEdit worldEdit) {
max = 2
)
@CommandPermissions("worldedit.history.undo")
public void undo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1));
for (int i = 0; i < times; ++i) {
EditSession undone;
@@ -88,7 +88,7 @@ public void undo(Player player, LocalSession session, EditSession editSession, C
max = 2
)
@CommandPermissions("worldedit.history.redo")
public void redo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException {

int times = Math.max(1, args.getInteger(0, 1));

@@ -122,7 +122,7 @@ public void redo(Player player, LocalSession session, EditSession editSession, C
max = 0
)
@CommandPermissions("worldedit.history.clear")
public void clearHistory(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
public void clearHistory(Player player, LocalSession session) throws WorldEditException {
session.clearHistory();
player.print("History cleared.");
}
@@ -26,9 +26,7 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
@@ -121,7 +119,7 @@ public void descend(Player player, @Optional("1") int levelsToDescend) throws Wo
)
@CommandPermissions("worldedit.navigation.ceiling")
@Logging(POSITION)
public void ceiling(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void ceiling(Player player, CommandContext args) throws WorldEditException {

final int clearance = args.argsLength() > 0 ?
Math.max(0, args.getInteger(0)) : 0;
@@ -142,7 +140,7 @@ public void ceiling(Player player, LocalSession session, EditSession editSession
max = 0
)
@CommandPermissions("worldedit.navigation.thru.command")
public void thru(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void thru(Player player) throws WorldEditException {
if (player.passThroughForwardWall(6)) {
player.print("Whoosh!");
} else {
@@ -158,7 +156,7 @@ public void thru(Player player, LocalSession session, EditSession editSession, C
max = 0
)
@CommandPermissions("worldedit.navigation.jumpto.command")
public void jumpTo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void jumpTo(Player player) throws WorldEditException {

Location pos = player.getSolidBlockTrace(300);
if (pos != null) {
@@ -179,7 +177,7 @@ public void jumpTo(Player player, LocalSession session, EditSession editSession,
)
@CommandPermissions("worldedit.navigation.up")
@Logging(POSITION)
public void up(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void up(Player player, CommandContext args) throws WorldEditException {
final int distance = args.getInteger(0);

final boolean alwaysGlass = getAlwaysGlass(args);
@@ -26,7 +26,6 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
@@ -60,7 +59,7 @@ public ScriptingCommands(WorldEdit worldEdit) {
)
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void execute(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void execute(Player player, LocalSession session, CommandContext args) throws WorldEditException {

String[] scriptArgs = args.getSlice(1);
String name = args.getString(0);
@@ -87,7 +86,7 @@ public void execute(Player player, LocalSession session, EditSession editSession
)
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void executeLast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void executeLast(Player player, LocalSession session, CommandContext args) throws WorldEditException {

String lastScript = session.getLastScript();

Oops, something went wrong.

0 comments on commit 8ff56e5

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