3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-13 22:50:06 +01:00

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

Dieser Commit ist enthalten in:
dordsor21 2021-09-18 17:42:40 +01:00
Ursprung 34301b446a
Commit 7d032ba69f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
5 geänderte Dateien mit 88 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -11,20 +11,29 @@ import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.util.formatting.text.Component;
import java.util.List;
public class ScatterCommand extends ScatterBrush {
private final String command;
private final boolean print;
public ScatterCommand(int count, int distance, String command) {
public ScatterCommand(int count, int distance, String command, boolean print) {
super(count, distance);
this.command = command;
this.print = print;
}
@Override
public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 position, Pattern p, double size) throws
public void apply(
EditSession editSession,
LocalBlockVectorSet placed,
BlockVector3 position,
Pattern pattern,
double size
) throws
MaxChangedBlocksException {
int radius = getDistance();
CuboidRegionSelector selector = new CuboidRegionSelector(
@ -42,12 +51,40 @@ public class ScatterCommand extends ScatterBrush {
player.setSelection(selector);
List<String> cmds = StringMan.split(replaced, ';');
for (String cmd : cmds) {
CommandEvent event = new CommandEvent(
new LocationMaskedPlayerWrapper(player, player.getLocation().setPosition(position.toVector3()), false),
cmd
);
Player p = print ?
new LocationMaskedPlayerWrapper(player, player.getLocation().setPosition(position.toVector3()), false) :
new ScatterCommandPlayerWrapper(player, position);
CommandEvent event = new CommandEvent(p, cmd, editSession);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
}
}
private static final class ScatterCommandPlayerWrapper extends LocationMaskedPlayerWrapper {
ScatterCommandPlayerWrapper(Player player, BlockVector3 position) {
super(player, player.getLocation().setPosition(position.toVector3()), false);
}
@Override
public void print(String msg) {
}
@Override
public void print(Component component) {
}
@Override
public void printDebug(String msg) {
}
@Override
public void printError(String msg) {
}
@Override
public void printRaw(String msg) {
}
}
}

Datei anzeigen

@ -21,7 +21,6 @@ public class SilentPlayerWrapper extends AsyncPlayer {
@Override
public void print(Component component) {
super.print(component);
}
@Override

Datei anzeigen

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

Datei anzeigen

@ -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.
*

Datei anzeigen

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