Skip to content

Commit

Permalink
feat!: delete region by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Jun 11, 2024
1 parent a60df65 commit 95b2ba4
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import xyz.nucleoid.map_templates.BlockBounds;

import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
Expand Down Expand Up @@ -114,11 +114,12 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
))
.then(literal("remove")
.then(literal("here")
.executes(MapMetadataCommand::removeRegionHere)
)
.then(argument("marker", StringArgumentType.word()).suggests(localRegionSuggestions())
.executes(executeInRegions("Removed %d regions.", MapMetadataCommand::executeRemoveNamedRegionsHere))
))
.then(literal("at")
.then(argument("pos", BlockPosArgumentType.blockPos())
.executes(MapMetadataCommand::removeRegionAt)
.executes(MapMetadataCommand::removeAllRegionsAt)
))
)
.then(literal("commit")
Expand Down Expand Up @@ -283,15 +284,15 @@ private static boolean executeRegionDataRemove(CommandContext<ServerCommandSourc
return path.remove(region.data()) > 0;
}

private static int removeRegionHere(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return removeRegion(context, context.getSource().getPlayer().getBlockPos());
private static int removeAllRegionsAt(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return removeAllRegions(context, BlockPosArgumentType.getBlockPos(context, "pos"));
}

private static int removeRegionAt(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return removeRegion(context, BlockPosArgumentType.getBlockPos(context, "pos"));
private static boolean executeRemoveNamedRegionsHere(CommandContext<ServerCommandSource> context, MapWorkspace map, WorkspaceRegion region) {
return map.removeRegion(region);
}

private static int removeRegion(CommandContext<ServerCommandSource> context, BlockPos pos) throws CommandSyntaxException {
private static int removeAllRegions(CommandContext<ServerCommandSource> context, BlockPos pos) throws CommandSyntaxException {
var source = context.getSource();
var map = getWorkspaceForSource(source);

Expand Down

0 comments on commit 95b2ba4

Please sign in to comment.