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:
wizjany 2019-03-16 19:04:24 -04:00
parent 25631af31c
commit 1934006d14
22 changed files with 207 additions and 177 deletions

View File

@ -875,9 +875,10 @@ public class LocalSession {
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;

View File

@ -42,7 +42,6 @@ import com.sk89q.worldedit.scripting.CraftScriptContext;
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 final class WorldEdit {
* @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);

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
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;

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
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 class ChunkCommands {
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 class ChunkCommands {
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 class ChunkCommands {
)
@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();

View File

@ -211,7 +211,7 @@ public class ClipboardCommands {
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 class ClipboardCommands {
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.");
}

View File

@ -63,7 +63,7 @@ public class GeneralCommands {
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 class GeneralCommands {
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 class GeneralCommands {
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 class GeneralCommands {
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 class GeneralCommands {
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 class GeneralCommands {
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.");

View File

@ -55,7 +55,7 @@ public class HistoryCommands {
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 class HistoryCommands {
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 class HistoryCommands {
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.");
}

View File

@ -26,9 +26,7 @@ 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;
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 class NavigationCommands {
)
@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 class NavigationCommands {
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 class NavigationCommands {
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 class NavigationCommands {
)
@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);

View File

@ -26,7 +26,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.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 class ScriptingCommands {
)
@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 class ScriptingCommands {
)
@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();

View File

@ -87,7 +87,7 @@ public class SelectionCommands {
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void pos1(Player player, LocalSession session, CommandContext args) throws WorldEditException {
Location pos;
@ -121,7 +121,7 @@ public class SelectionCommands {
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void pos2(Player player, LocalSession session, CommandContext args) throws WorldEditException {
Location pos;
if (args.argsLength() == 1) {
@ -155,7 +155,7 @@ public class SelectionCommands {
max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void hpos1(Player player, LocalSession session) throws WorldEditException {
Location pos = player.getBlockTrace(300);
@ -180,7 +180,7 @@ public class SelectionCommands {
max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void hpos2(Player player, LocalSession session) throws WorldEditException {
Location pos = player.getBlockTrace(300);
@ -215,7 +215,7 @@ public class SelectionCommands {
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void chunk(Player player, LocalSession session, CommandContext args) throws WorldEditException {
final BlockVector3 min;
final BlockVector3 max;
final World world = player.getWorld();
@ -277,7 +277,7 @@ public class SelectionCommands {
max = 0
)
@CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void wand(Player player) throws WorldEditException {
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
player.print("Left click: select pos #1; Right click: select pos #2");
@ -291,7 +291,7 @@ public class SelectionCommands {
max = 0
)
@CommandPermissions("worldedit.wand.toggle")
public void toggleWand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
session.setToolControl(!session.isToolControlEnabled());
@ -311,7 +311,7 @@ public class SelectionCommands {
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.expand")
public void expand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void expand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
// Special syntax (//expand vert) to expand the selection between
// sky and bedrock.
@ -406,7 +406,7 @@ public class SelectionCommands {
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
public void contract(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void contract(Player player, LocalSession session, CommandContext args) throws WorldEditException {
List<BlockVector3> dirs = new ArrayList<>();
int change = args.getInteger(0);
@ -481,7 +481,7 @@ public class SelectionCommands {
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.shift")
public void shift(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void shift(Player player, LocalSession session, CommandContext args) throws WorldEditException {
List<BlockVector3> dirs = new ArrayList<>();
int change = args.getInteger(0);
@ -529,7 +529,7 @@ public class SelectionCommands {
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.outset")
public void outset(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void outset(Player player, LocalSession session, CommandContext args) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
region.expand(getChangesForEachDir(args));
session.getRegionSelector(player.getWorld()).learnChanges();
@ -552,7 +552,7 @@ public class SelectionCommands {
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.inset")
public void inset(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void inset(Player player, LocalSession session, CommandContext args) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
region.contract(getChangesForEachDir(args));
session.getRegionSelector(player.getWorld()).learnChanges();
@ -588,7 +588,7 @@ public class SelectionCommands {
max = 0
)
@CommandPermissions("worldedit.selection.size")
public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException {
if (args.hasFlag('c')) {
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
@ -706,7 +706,7 @@ public class SelectionCommands {
min = 0,
max = 1
)
public void select(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void select(Player player, LocalSession session, CommandContext args) throws WorldEditException {
final World world = player.getWorld();
if (args.argsLength() == 0) {
session.getRegionSelector(world).clear();

View File

@ -24,7 +24,6 @@ package com.sk89q.worldedit.command;
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;
@ -62,7 +61,7 @@ public class SnapshotCommands {
max = 1
)
@CommandPermissions("worldedit.snapshots.list")
public void list(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void list(Player player, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
@ -112,7 +111,7 @@ public class SnapshotCommands {
max = 1
)
@CommandPermissions("worldedit.snapshots.restore")
public void use(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void use(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
@ -155,7 +154,7 @@ public class SnapshotCommands {
max = 1
)
@CommandPermissions("worldedit.snapshots.restore")
public void sel(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void sel(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) {
@ -202,7 +201,7 @@ public class SnapshotCommands {
max = -1
)
@CommandPermissions("worldedit.snapshots.restore")
public void before(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void before(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
@ -241,7 +240,7 @@ public class SnapshotCommands {
max = -1
)
@CommandPermissions("worldedit.snapshots.restore")
public void after(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void after(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.command;
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;
@ -47,7 +46,7 @@ public class SuperPickaxeCommands {
max = 0
)
@CommandPermissions("worldedit.superpickaxe")
public void single(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void single(Player player, LocalSession session) throws WorldEditException {
session.setSuperPickaxe(new SinglePickaxe());
session.enableSuperPickAxe();
@ -62,7 +61,7 @@ public class SuperPickaxeCommands {
max = 1
)
@CommandPermissions("worldedit.superpickaxe.area")
public void area(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void area(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(0);
@ -85,7 +84,7 @@ public class SuperPickaxeCommands {
max = 1
)
@CommandPermissions("worldedit.superpickaxe.recursive")
public void recursive(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void recursive(Player player, LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
double range = args.getDouble(0);

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.command;
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;
@ -56,7 +55,7 @@ public class ToolCommands {
min = 0,
max = 0
)
public void none(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void none(Player player, LocalSession session) throws WorldEditException {
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
player.print("Tool unbound from your current item.");
@ -70,7 +69,7 @@ public class ToolCommands {
max = 0
)
@CommandPermissions("worldedit.tool.info")
public void info(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void info(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new QueryTool());
@ -86,7 +85,7 @@ public class ToolCommands {
max = 1
)
@CommandPermissions("worldedit.tool.tree")
public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void tree(Player player, LocalSession session, CommandContext args) throws WorldEditException {
TreeGenerator.TreeType type = args.argsLength() > 0
? TreeGenerator.lookup(args.getString(0))
@ -124,7 +123,7 @@ public class ToolCommands {
max = 0
)
@CommandPermissions("worldedit.tool.data-cycler")
public void cycler(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void cycler(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new BlockDataCyler());
@ -161,7 +160,7 @@ public class ToolCommands {
max = 0
)
@CommandPermissions("worldedit.tool.deltree")
public void deltree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void deltree(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new FloatingTreeRemover());
@ -177,7 +176,7 @@ public class ToolCommands {
max = 0
)
@CommandPermissions("worldedit.tool.farwand")
public void farwand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void farwand(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new DistanceWand());

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.command;
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.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
@ -50,7 +49,7 @@ public class ToolUtilCommands {
max = 1
)
@CommandPermissions("worldedit.superpickaxe")
public void togglePickaxe(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void togglePickaxe(Player player, LocalSession session, CommandContext args) throws WorldEditException {
String newState = args.getString(0, null);
if (session.hasSuperPickAxe()) {
@ -80,7 +79,7 @@ public class ToolUtilCommands {
max = -1
)
@CommandPermissions("worldedit.brush.options.mask")
public void mask(Player player, LocalSession session, EditSession editSession, @Optional Mask mask) throws WorldEditException {
public void mask(Player player, LocalSession session, @Optional Mask mask) throws WorldEditException {
if (mask == null) {
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setMask(null);
player.print("Brush mask disabled.");
@ -98,7 +97,7 @@ public class ToolUtilCommands {
max = 1
)
@CommandPermissions("worldedit.brush.options.material")
public void material(Player player, LocalSession session, EditSession editSession, Pattern pattern) throws WorldEditException {
public void material(Player player, LocalSession session, Pattern pattern) throws WorldEditException {
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setFill(pattern);
player.print("Brush material set.");
}
@ -111,7 +110,7 @@ public class ToolUtilCommands {
max = 1
)
@CommandPermissions("worldedit.brush.options.range")
public void range(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void range(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int range = args.getInteger(0);
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setRange(range);
player.print("Brush range set.");
@ -125,7 +124,7 @@ public class ToolUtilCommands {
max = 1
)
@CommandPermissions("worldedit.brush.options.size")
public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int radius = args.getInteger(0);
we.checkMaxBrushRadius(radius);

View File

@ -23,7 +23,6 @@ import com.google.common.io.Files;
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.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
@ -126,7 +125,7 @@ public class WorldEditCommands {
min = 0,
max = 0
)
public void cui(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void cui(Player player, LocalSession session) throws WorldEditException {
session.setCUISupport(true);
session.dispatchCUISetup(player);
}
@ -138,7 +137,7 @@ public class WorldEditCommands {
min = 1,
max = 1
)
public void tz(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
public void tz(Player player, LocalSession session, CommandContext args) throws WorldEditException {
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
session.setTimezone(tz);
player.print("Timezone set for this session to: " + tz.getDisplayName());

View File

@ -173,7 +173,6 @@ public class BrushTool implements TraceTool {
BlockBag bag = session.getBlockBag(player);
try (EditSession editSession = session.createEditSession(player)) {
Request.request().setEditSession(editSession);
if (mask != null) {
Mask existingMask = editSession.getMask();

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt;
import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
@ -54,8 +57,10 @@ import com.sk89q.worldedit.command.composition.DeformCommand;
import com.sk89q.worldedit.command.composition.PaintCommand;
import com.sk89q.worldedit.command.composition.SelectionCommand;
import com.sk89q.worldedit.command.composition.ShapedBrushCommand;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.factory.Deform;
import com.sk89q.worldedit.function.factory.Deform.Mode;
import com.sk89q.worldedit.internal.command.ActorAuthorizer;
@ -76,6 +81,7 @@ import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -85,9 +91,6 @@ import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt;
/**
* Handles the registration and invocation of commands.
*
@ -260,6 +263,13 @@ public final class CommandManager {
}
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.request().setSession(session);
if (actor instanceof Entity) {
Extent extent = ((Entity) actor).getExtent();
if (extent instanceof World) {
Request.request().setWorld(((World) extent));
}
}
LocalConfiguration config = worldEdit.getConfiguration();
CommandLocals locals = new CommandLocals();
@ -335,6 +345,7 @@ public final class CommandManager {
worldEdit.flushBlockBag(actor, editSession);
}
Request.reset();
}
event.setCancelled(true);

View File

@ -38,6 +38,7 @@ import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.Subscribe;
@ -314,70 +315,78 @@ public class PlatformManager {
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
if (event.getType() == Interaction.HIT) {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
if (!session.isToolControlEnabled()) {
return;
}
Request.reset();
Request.request().setSession(session);
Request.request().setWorld(player.getWorld());
if (!actor.hasPermission("worldedit.selection.pos")) {
return;
}
try {
if (event.getType() == Interaction.HIT) {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
if (!session.isToolControlEnabled()) {
return;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (!actor.hasPermission("worldedit.selection.pos")) {
return;
}
BlockVector3 blockPoint = vector.toBlockPoint();
if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(actor, session, blockPoint);
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
event.setCancelled(true);
return;
}
BlockVector3 blockPoint = vector.toBlockPoint();
if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(actor, session, blockPoint);
}
if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) {
event.setCancelled(superPickaxe.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location));
return;
}
}
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof DoubleActionBlockTool) {
if (tool.canUse(player)) {
((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
event.setCancelled(true);
}
}
} else if (event.getType() == Interaction.OPEN) {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
if (!session.isToolControlEnabled()) {
return;
}
if (!actor.hasPermission("worldedit.selection.pos")) {
return;
if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) {
event.setCancelled(superPickaxe.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location));
return;
}
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = vector.toBlockPoint();
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(actor, session, blockPoint);
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof DoubleActionBlockTool) {
if (tool.canUse(player)) {
((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
event.setCancelled(true);
}
}
event.setCancelled(true);
return;
}
} else if (event.getType() == Interaction.OPEN) {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
if (!session.isToolControlEnabled()) {
return;
}
if (!actor.hasPermission("worldedit.selection.pos")) {
return;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = vector.toBlockPoint();
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(actor, session, blockPoint);
}
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof BlockTool) {
if (tool.canUse(player)) {
((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
event.setCancelled(true);
return;
}
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof BlockTool) {
if (tool.canUse(player)) {
((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
event.setCancelled(true);
}
}
}
} finally {
Request.reset();
}
}
}
@ -387,74 +396,78 @@ public class PlatformManager {
// Create a proxy actor with a potentially different world for
// making changes to the world
Player player = createProxyActor(event.getPlayer());
LocalSession session = worldEdit.getSessionManager().get(player);
Request.reset();
Request.request().setSession(session);
Request.request().setWorld(player.getWorld());
switch (event.getInputType()) {
case PRIMARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) {
return;
}
try {
switch (event.getInputType()) {
case PRIMARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) {
return;
}
if (!player.hasPermission("worldedit.navigation.jumpto.tool")) {
return;
}
if (!player.hasPermission("worldedit.navigation.jumpto.tool")) {
return;
}
Location pos = player.getSolidBlockTrace(getConfiguration().navigationWandMaxDistance);
if (pos != null) {
player.findFreePosition(pos);
} else {
player.printError("No block in sight (or too far)!");
}
Location pos = player.getSolidBlockTrace(getConfiguration().navigationWandMaxDistance);
if (pos != null) {
player.findFreePosition(pos);
} else {
player.printError("No block in sight (or too far)!");
}
event.setCancelled(true);
return;
}
LocalSession session = worldEdit.getSessionManager().get(player);
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof DoubleActionTraceTool) {
if (tool.canUse(player)) {
((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
event.setCancelled(true);
return;
}
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof DoubleActionTraceTool) {
if (tool.canUse(player)) {
((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
event.setCancelled(true);
return;
}
}
break;
}
break;
}
case SECONDARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) {
return;
}
case SECONDARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) {
return;
}
if (!player.hasPermission("worldedit.navigation.thru.tool")) {
return;
}
if (!player.hasPermission("worldedit.navigation.thru.tool")) {
return;
}
if (!player.passThroughForwardWall(40)) {
player.printError("Nothing to pass through!");
}
if (!player.passThroughForwardWall(40)) {
player.printError("Nothing to pass through!");
}
event.setCancelled(true);
return;
}
LocalSession session = worldEdit.getSessionManager().get(player);
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof TraceTool) {
if (tool.canUse(player)) {
((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
event.setCancelled(true);
return;
}
}
break;
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool instanceof TraceTool) {
if (tool.canUse(player)) {
((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
event.setCancelled(true);
return;
}
}
break;
}
}
} finally {
Request.reset();
}
}

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.io.file.FilenameException;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -65,6 +66,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player), player);
Request.request().setEditSession(editSession);
editSession.enableStandardMode();
editSessions.add(editSession);
return editSession;

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}
}