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 16, 2024
1 parent a37edaa commit 2d28085
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ 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::executeRemoveRegionsHere))
))
.then(literal("at")
.then(argument("pos", BlockPosArgumentType.blockPos())
.executes(MapMetadataCommand::removeRegionAt)
.executes(context -> {
final var pos = BlockPosArgumentType.getBlockPos(context, "pos");
return removeRegions(context, region -> region.bounds().contains(pos));
})
))
.then(literal("all")
.then(argument("marker", StringArgumentType.word()).suggests(regionSuggestions())
Expand Down Expand Up @@ -299,13 +303,9 @@ private static boolean executeRegionDataRemove(CommandContext<ServerCommandSourc
return path.remove(region.data()) > 0;
}

private static int removeRegionHere(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final var playerBounds = getPlayerBounds(context.getSource().getPlayerOrThrow());
return removeRegions(context, region -> region.bounds().intersects(playerBounds));
}

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

private static int removeRegions(CommandContext<ServerCommandSource> context, Predicate<WorkspaceRegion> predicate) throws CommandSyntaxException {
Expand Down

0 comments on commit 2d28085

Please sign in to comment.