Skip to content

Commit

Permalink
Better enforce the Request lifetime.
Browse files Browse the repository at this point in the history
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 20, 2019
1 parent 6b7cb69 commit 8ff56e5
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 175 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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();

Expand Down
Expand Up @@ -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();
Expand All @@ -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.");
}
Expand Down
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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.");
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit 8ff56e5

Please sign in to comment.