Fixed a null pointer. Merged in a bunch of CLI stuff.

This commit is contained in:
MattBDev
2019-09-02 15:22:43 -04:00
parent aa4c443358
commit c20f4c6b7f
28 changed files with 240 additions and 352 deletions

View File

@ -72,6 +72,27 @@ public class ApplyBrushCommands {
.ofTypes(ImmutableList.of(Key.of(double.class)))
.build();
public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) {
commandManager.register("apply", builder -> {
builder.description(TextComponent.of("Apply brush, apply a function to every block"));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
CommandManager manager = service.newCommandManager();
registration.register(
manager,
ApplyBrushCommandsRegistration.builder(),
new ApplyBrushCommands()
);
builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.apply")));
builder.addParts(REGION_FACTORY, RADIUS);
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use"))
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
}
private void setApplyBrush(CommandParameters parameters, Player player, LocalSession localSession,
Contextual<? extends RegionFunction> generatorFactory) throws WorldEditException {
double radius = requireNonNull(RADIUS.value(parameters).asSingle(double.class));

View File

@ -30,6 +30,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
@ -39,6 +40,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
@ -51,8 +53,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.ArgFlag;
@ -94,10 +96,11 @@ public class ChunkCommands {
@CommandPermissions("worldedit.listchunks")
public void listChunks(Actor actor, World world, LocalSession session,
@ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException {
Set<BlockVector2> chunks = session.getSelection(world).getChunks();
final Region region = session.getSelection(world);
PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%", chunks);
actor.print(paginationBox.create(page));
WorldEditAsyncCommandBuilder.createAndSendMessage(actor,
() -> new ChunkListPaginationBox(region).create(page),
"Listing chunks for " + actor.getName());
}
@Command(
@ -168,4 +171,27 @@ public class ChunkCommands {
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop"))));
}
private static class ChunkListPaginationBox extends PaginationBox {
//private final Region region;
private final List<BlockVector2> chunks;
ChunkListPaginationBox(Region region) {
super("Selected Chunks", "/listchunks -p %page%");
// TODO make efficient/streamable/calculable implementations of this
// for most region types, so we can just store the region and random-access get one page of chunks
// (this is non-trivial for some types of selections...)
//this.region = region.clone();
this.chunks = new ArrayList<>(region.getChunks());
}
@Override
public Component getComponent(int number) {
return TextComponent.of(chunks.get(number).toString());
}
@Override
public int getComponentsSize() {
return chunks.size();
}
}
}

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.MultiDirection;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
@ -37,6 +38,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.util.List;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
@ -119,7 +121,7 @@ public class ExpandCommands {
desc = "Expand the selection area"
)
@Logging(REGION)
public void expand(Player player, LocalSession session,
public void expand(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to expand the selection by, can be `vert` to expand to the whole vertical column")
int amount,
@Arg(desc = "Amount to expand the selection by in the other direction", def = "0")
@ -127,7 +129,7 @@ public class ExpandCommands {
@Arg(desc = "Direction to expand", def = Direction.AIM)
@MultiDirection
List<BlockVector3> direction) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
Region region = session.getSelection(world);
int oldSize = region.getArea();
if (reverseAmount == 0) {
@ -140,12 +142,12 @@ public class ExpandCommands {
}
}
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(world).learnChanges();
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
session.getRegionSelector(world).explainRegionAdjust(actor, session);
player.print("Region expanded " + (newSize - oldSize) + " block(s).");
actor.print("Region expanded " + (newSize - oldSize) + " block(s).");
}
}

View File

@ -85,23 +85,23 @@ public class GeneralCommands {
desc = "Modify block change limit"
)
@CommandPermissions("worldedit.limit")
public void limit(Player player, LocalSession session,
public void limit(Actor actor, LocalSession session,
@Arg(desc = "The limit to set", def = "")
Integer limit) {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
boolean mayDisable = actor.hasPermission("worldedit.limit.unrestricted");
limit = limit == null ? config.defaultChangeLimit : Math.max(-1, limit);
if (!mayDisable && config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) {
player.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
actor.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
return;
}
}
session.setBlockChangeLimit(limit);
player.print("Block change limit set to " + limit + "."
actor.print("Block change limit set to " + limit + "."
+ (limit == config.defaultChangeLimit ? "" : " (Use //limit to go back to the default.)"));
}
@ -110,22 +110,22 @@ public class GeneralCommands {
desc = "Modify evaluation timeout time."
)
@CommandPermissions("worldedit.timeout")
public void timeout(Player player, LocalSession session,
public void timeout(Actor actor, LocalSession session,
@Arg(desc = "The timeout time to set", def = "")
Integer limit) {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted");
boolean mayDisable = actor.hasPermission("worldedit.timeout.unrestricted");
limit = limit == null ? config.calculationTimeout : Math.max(-1, limit);
if (!mayDisable && config.maxCalculationTimeout > -1) {
if (limit > config.maxCalculationTimeout) {
player.printError("Your maximum allowable timeout is " + config.maxCalculationTimeout + " ms.");
actor.printError("Your maximum allowable timeout is " + config.maxCalculationTimeout + " ms.");
return;
}
}
session.setTimeout(limit);
player.print("Timeout time set to " + limit + " ms."
actor.print("Timeout time set to " + limit + " ms."
+ (limit == config.calculationTimeout ? "" : " (Use //timeout to go back to the default.)"));
}
@ -134,18 +134,20 @@ public class GeneralCommands {
desc = "Toggle fast mode"
)
@CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, @Arg(desc = "The new fast mode state", def = "") Boolean fastMode) {
public void fast(Actor actor, LocalSession session,
@Arg(desc = "The new fast mode state", def = "")
Boolean fastMode) {
boolean hasFastMode = session.hasFastMode();
if (fastMode != null && fastMode == hasFastMode) {
player.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + ".");
actor.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + ".");
return;
}
if (hasFastMode) {
session.setFastMode(false);
BBC.FAST_DISABLED.send(player);
BBC.FAST_DISABLED.send(actor);
} else {
session.setFastMode(true);
BBC.FAST_ENABLED.send(player);
BBC.FAST_ENABLED.send(actor);
}
}
@ -154,14 +156,14 @@ public class GeneralCommands {
desc = "Sets the reorder mode of WorldEdit"
)
@CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session,
public void reorderMode(Actor actor, LocalSession session,
@Arg(desc = "The reorder mode", def = "")
EditSession.ReorderMode reorderMode) {
if (reorderMode == null) {
player.print("The reorder mode is " + session.getReorderMode().getDisplayName());
actor.print("The reorder mode is " + session.getReorderMode().getDisplayName());
} else {
session.setReorderMode(reorderMode);
player.print("The reorder mode is now " + session.getReorderMode().getDisplayName());
actor.print("The reorder mode is now " + session.getReorderMode().getDisplayName());
}
}
@ -193,18 +195,33 @@ public class GeneralCommands {
}
@Command(
name = "/gmask",
aliases = {"gmask", "globalmask", "/globalmask"},
name = "/world",
desc = "Sets the world override"
)
@CommandPermissions("worldedit.world")
public void world(Actor actor, LocalSession session,
@Arg(desc = "The world override", def = "") World world) {
session.setWorldOverride(world);
if (world == null) {
actor.print("Removed world override.");
} else {
actor.print("Set the world override to " + world.getId() + ". (Use //world to go back to default)");
}
}
@Command(
name = "gmask",
aliases = {"/gmask"},
descFooter = "The global destination mask applies to all edits you do and masks based on the destination blocks (i.e. the blocks in the world).",
desc = "Set the global mask"
)
@CommandPermissions({"worldedit.global-mask", "worldedit.mask.global"})
public void gmask(Player player, LocalSession session, @Arg(desc = "The mask to set", def = "") Mask maskOpt) {
session.setMask(maskOpt);
if (maskOpt == null) {
BBC.MASK_DISABLED.send(player);
public void gmask(Actor actor, LocalSession session, @Arg(desc = "The mask to set", def = "") Mask mask) {
session.setMask(mask);
if (mask == null) {
BBC.MASK_DISABLED.send(actor);
} else {
BBC.MASK.send(player);
BBC.MASK.send(actor);
}
}

View File

@ -54,7 +54,7 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
@SuppressWarnings("unchecked")
public static void register(CommandManager commandManager) {
ImmutableList.of(
BlockTypes.class,
BlockType.class,
BlockCategory.class,
ItemType.class,
ItemCategory.class,

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location;
@ -91,8 +92,13 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
}
private Location getTargetFace(Player player) {
Location target = player.getBlockTraceFace(getRange(), true);
target = player.getBlockTrace(getRange(), true);
Location target;
Mask mask = getTraceMask();
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true, mask);
} else {
target = player.getBlockTrace(MAX_RANGE, false, mask);
}
if (target == null) {
BBC.NO_BLOCK.send(player);
return null;

View File

@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
pattern = BlockTypes.COBBLESTONE.getDefaultState();
}
editSession.makeCylinder(position, pattern, size, size, height, false);
}

View File

@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
pattern = BlockTypes.COBBLESTONE.getDefaultState();
}
editSession.makeSphere(position, pattern, size, size, size, false);
}