From 34301b446a9622d1129d6a58a79647cfca3befaf Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 18 Sep 2021 17:08:03 +0100 Subject: [PATCH] Allow scatter command brush to use FAWE commands. Best for scatter sphere, etc. --- .../core/command/tool/brush/ScatterBrush.java | 1 + .../command/tool/brush/ScatterCommand.java | 6 ++- .../wrappers/LocationMaskedPlayerWrapper.java | 8 ++++ .../extension/platform/PlayerProxy.java | 45 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterBrush.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterBrush.java index f834bc26c..7ea15e421 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterBrush.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterBrush.java @@ -65,6 +65,7 @@ public class ScatterBrush implements Brush { visited.add(position); } LocalBlockVectorSet placed = new LocalBlockVectorSet(); + placed.setOffset(position.getX(), position.getZ()); int maxFails = 1000; for (int i = 0; i < count; i++) { int index = ThreadLocalRandom.current().nextInt(length); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterCommand.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterCommand.java index 2a4e2a5b1..70c5c7598 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterCommand.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterCommand.java @@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.command.tool.brush; import com.fastasyncworldedit.core.math.LocalBlockVectorSet; import com.fastasyncworldedit.core.util.StringMan; +import com.fastasyncworldedit.core.wrappers.LocationMaskedPlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; @@ -41,7 +42,10 @@ public class ScatterCommand extends ScatterBrush { player.setSelection(selector); List cmds = StringMan.split(replaced, ';'); for (String cmd : cmds) { - CommandEvent event = new CommandEvent(player, cmd); + CommandEvent event = new CommandEvent( + new LocationMaskedPlayerWrapper(player, player.getLocation().setPosition(position.toVector3()), false), + cmd + ); PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java index 984eb9db7..a92f7514c 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java @@ -24,6 +24,14 @@ public class LocationMaskedPlayerWrapper extends AsyncPlayer { return position; } + @Override + public void setPosition(final Vector3 pos) { + if (allowTeleport) { + super.setPosition(pos); + update(); + } + } + private void update() { this.position = super.getLocation(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index d540f062a..960c8b8d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -206,6 +206,51 @@ public class PlayerProxy extends AbstractPlayerActor { basePlayer.sendFakeBlock(pos, block); } + @Override + public void findFreePosition(final Location searchPos) { + basePlayer.findFreePosition(searchPos); + } + + @Override + public void setOnGround(final Location searchPos) { + basePlayer.setOnGround(searchPos); + } + + @Override + public void findFreePosition() { + basePlayer.findFreePosition(); + } + + @Override + public boolean ascendLevel() { + return basePlayer.ascendLevel(); + } + + @Override + public boolean descendLevel() { + return basePlayer.descendLevel(); + } + + @Override + public boolean ascendToCeiling(final int clearance) { + return basePlayer.ascendToCeiling(clearance); + } + + @Override + public boolean ascendToCeiling(final int clearance, final boolean alwaysGlass) { + return basePlayer.ascendToCeiling(clearance, alwaysGlass); + } + + @Override + public boolean ascendUpwards(final int distance) { + return basePlayer.ascendUpwards(distance); + } + + @Override + public boolean ascendUpwards(final int distance, final boolean alwaysGlass) { + return basePlayer.ascendUpwards(distance, alwaysGlass); + } + @Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { basePlayer.floatAt(x, y, z, alwaysGlass);