Add cmd brush

This commit is contained in:
Jesse Boyd 2016-06-21 23:47:40 +10:00
parent 2e0a37c1de
commit 27d5e9e1aa
9 changed files with 159 additions and 7 deletions

View File

@ -83,6 +83,7 @@ public enum BBC {
BRUSH_GRAVITY("Gravity brush equipped (%s0)", "WorldEdit.Brush"),
BRUSH_HEIGHT("Height brush equipped (%s0)", "WorldEdit.Brush"),
BRUSH_COPY("Copy brush equipped (%s0)", "WorldEdit.Brush"),
BRUSH_COMMAND("Command brush equipped (%s0)", "WorldEdit.Brush"),
BRUSH_HEIGHT_INVALID("Invalid height map file (%s0)", "WorldEdit.Brush"),
BRUSH_SMOOTH("Smooth brush equipped (%s0 x %s1 using %s2).", "WorldEdit.Brush"),
BRUSH_SPHERE("Sphere brush shape equipped (%s0).", "WorldEdit.Brush"),

View File

@ -296,6 +296,10 @@ public abstract class FawePlayer<T> {
this.getSession().setRegionSelector(player.getWorld(), selector);
}
public void setSelection(final RegionSelector selector) {
this.getSession().setRegionSelector(getPlayer().getWorld(), selector);
}
/**
* Get the largest region in the player's allowed WorldEdit region
* @return

View File

@ -0,0 +1,56 @@
package com.boydti.fawe.object.brush;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.boydti.fawe.wrappers.SilentPlayerWrapper;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVectorFace;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
public class CommandBrush implements Brush {
private final String command;
private final Player player;
private final int radius;
public CommandBrush(Player player, String command, double radius) {
this.player = player;
this.command = command;
this.radius = (int) radius;
}
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
String replaced = command.replace("{x}", position.getBlockX() + "")
.replace("{y}", position.getBlockY() + "")
.replace("{z}", position.getBlockZ() + "")
.replace("{world}", editSession.getWorld().getName() + "")
.replace("{size}", radius + "");
WorldVectorFace face = player.getBlockTraceFace(256, true);
if (face == null) {
position = position.add(0, 1, 1);
} else {
position = face;
}
FawePlayer<Object> fp = FawePlayer.wrap(player);
fp.deleteMeta("fawe_action");
fp.setSelection(selector);
PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, position));
String[] cmds = replaced.split(";");
for (String cmd : cmds) {
CommandEvent event = new CommandEvent(wePlayer, cmd);
CommandManager.getInstance().handleCommand(event);
}
FawePlayer.wrap(player).setMeta("fawe_action", true);
}
}

View File

@ -0,0 +1,42 @@
package com.boydti.fawe.wrappers;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Location;
public class LocationMaskedPlayerWrapper extends PlayerWrapper {
private Vector position;
public LocationMaskedPlayerWrapper(Player parent, Vector position) {
super(parent);
this.position = position;
}
@Override
public WorldVector getBlockIn() {
return new WorldVector((LocalWorld) getWorld(), position);
}
@Override
public WorldVector getBlockOn() {
return new WorldVector((LocalWorld) getWorld(), position.subtract(0, 1, 0));
}
@Override
public WorldVector getPosition() {
return new WorldVector((LocalWorld) getWorld(), position);
}
@Override
public Location getLocation() {
return new Location(getWorld(), position);
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
System.out.println("SET POSITION");
this.position = pos;
}
}

View File

@ -0,0 +1,22 @@
package com.boydti.fawe.wrappers;
import com.sk89q.worldedit.entity.Player;
/**
* Still prints error messages
*/
public class SilentPlayerWrapper extends PlayerWrapper {
public SilentPlayerWrapper(Player parent) {
super(parent);
}
@Override
public void print(String msg) {}
@Override
public void printDebug(String msg) {
}
@Override
public void printRaw(String msg) {}
}

View File

@ -1,14 +1,15 @@
package com.boydti.fawe.wrappers;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.object.extent.FaweRegionExtent;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
@ -33,7 +34,7 @@ import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
public class WorldWrapper extends AbstractWorld {
public class WorldWrapper extends LocalWorld {
private final AbstractWorld parent;

View File

@ -24,6 +24,7 @@ import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.brush.CommandBrush;
import com.boydti.fawe.object.brush.CopyBrush;
import com.boydti.fawe.object.brush.HeightBrush;
import com.sk89q.minecraft.util.commands.Command;
@ -136,7 +137,7 @@ public class BrushCommands {
}
@Command(
aliases = { "clipboard", "paste" },
aliases = { "clipboard"},
usage = "",
desc = "Choose the clipboard brush",
help =
@ -274,6 +275,24 @@ public class BrushCommands {
BBC.BRUSH_COPY.send(player, radius);
}
@Command(
aliases = { "command", "cmd" },
usage = "<radius> [cmd1;cmd2...]",
desc = "Command brush",
help =
"Right click executes the command at the position.\n",
min = 2,
max = 99
)
@CommandPermissions("worldedit.brush.copy")
public void command(Player player, LocalSession session, EditSession editSession, @Optional("5") double radius, CommandContext args) throws WorldEditException {
BrushTool tool = session.getBrushTool(player.getItemInHand());
String cmd = args.getJoinedStrings(1);
System.out.println(cmd);
tool.setBrush(new CommandBrush(player, cmd, radius), "worldedit.brush.copy");
BBC.BRUSH_COMMAND.send(player, cmd);
}
@Command(
aliases = { "butcher", "kill" },
usage = "[radius]",

View File

@ -309,8 +309,7 @@ public class SelectionCommands {
// Special syntax (//expand vert) to expand the selection between
// sky and bedrock.
if (args.getString(0).equalsIgnoreCase("vert")
|| args.getString(0).equalsIgnoreCase("vertical")) {
if (args.getString(0).equalsIgnoreCase("vert") || args.getString(0).equalsIgnoreCase("vertical")) {
Region region = session.getSelection(player.getWorld());
try {
int oldSize = region.getArea();

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.platform;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
@ -114,6 +115,8 @@ public final class CommandManager {
private final DynamicStreamHandler dynamicHandler = new DynamicStreamHandler();
private final ExceptionConverter exceptionConverter;
private static CommandManager INSTANCE;
/**
* Create a new instance.
*
@ -122,6 +125,7 @@ public final class CommandManager {
public CommandManager(final WorldEdit worldEdit, PlatformManager platformManager) {
checkNotNull(worldEdit);
checkNotNull(platformManager);
INSTANCE = this;
this.worldEdit = worldEdit;
this.platformManager = platformManager;
this.exceptionConverter = new WorldEditExceptionConverter(worldEdit);
@ -161,6 +165,10 @@ public final class CommandManager {
.describeAs("Bind functions to held items").registerMethods(new ToolCommands(worldEdit)).parent().graph().getDispatcher();
}
public static CommandManager getInstance() {
return INSTANCE;
}
public ExceptionConverter getExceptionConverter() {
return exceptionConverter;
}
@ -223,7 +231,7 @@ public final class CommandManager {
@Subscribe
public void handleCommand(final CommandEvent event) {
Request.reset();
TaskManager.IMP.async(new Runnable() {
TaskManager.IMP.taskNow(new Runnable() {
@Override
public void run() {
final Actor actor = platformManager.createProxyActor(event.getActor());
@ -309,7 +317,7 @@ public final class CommandManager {
}
}
}
});
}, Fawe.get().isMainThread());
event.setCancelled(true);
}