Scattercommand should use the same editsession for all commands, make it "silent" by default and allow players to see output if wanted.

This commit is contained in:
dordsor21
2021-09-18 17:42:40 +01:00
parent 34301b446a
commit 7d032ba69f
5 changed files with 88 additions and 10 deletions

View File

@ -694,13 +694,15 @@ public class BrushCommands {
@Arg(desc = "double", def = "1")
double distance,
@Arg(desc = "List of comma-separated commands")
List<String> commandStr
List<String> commandStr,
@Switch(name = 'p', desc = "Show any printed output")
boolean print
)
throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
set(
context,
new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " ")),
new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " "), print),
"worldedit.brush.scattercommand"
)
.setSize(radius);

View File

@ -19,10 +19,13 @@
package com.sk89q.worldedit.event.platform;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.event.AbstractCancellable;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
@ -32,6 +35,10 @@ public class CommandEvent extends AbstractCancellable {
private final Actor actor;
private final String arguments;
//FAWE start
@Nullable
private final EditSession session;
//FAWE end
/**
* Create a new instance.
@ -45,8 +52,32 @@ public class CommandEvent extends AbstractCancellable {
this.actor = actor;
this.arguments = arguments;
//FAWE start
this.session = null;
}
/**
* Create a new instance.
*
* @param actor the player
* @param arguments the arguments
* @param editSession the editsession
*/
public CommandEvent(Actor actor, String arguments, @Nullable EditSession editSession) {
checkNotNull(actor);
checkNotNull(arguments);
this.actor = actor;
this.arguments = arguments;
this.session = editSession;
}
@Nullable
public EditSession getSession() {
return session;
}
//FAWE end
/**
* Get the actor that issued the command.
*

View File

@ -795,7 +795,8 @@ public final class PlatformCommandManager {
}
Optional<EditSession> editSessionOpt = context.injectedValue(Key.of(EditSession.class));
if (editSessionOpt.isPresent()) {
// Require null CommandEvent#getSession as it means the editsession is being handled somewhere else.
if (editSessionOpt.isPresent() && event.getSession() == null) {
EditSession editSession = editSessionOpt.get();
editSession.flushQueue();
session.remember(editSession);
@ -866,6 +867,14 @@ public final class PlatformCommandManager {
store.injectValue(Key.of(boolean.class), context -> Optional.of(isSuggestions));
store.injectValue(Key.of(InjectedValueStore.class), ValueProvider.constant(store));
store.injectValue(Key.of(Event.class), ValueProvider.constant(event));
//FAWE start - allow giving editsessions
if (event instanceof CommandEvent) {
EditSession session = ((CommandEvent) event).getSession();
if (session != null) {
store.injectValue(Key.of(EditSession.class), context -> Optional.of(session));
}
}
//FAWE end
return MemoizingValueAccess.wrap(
MergedValueAccess.of(store, globalInjectedValues)
);