Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for area_pos1 and area_pos2 chatcommands to accept coordinates separated by commas AND spaces #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ Commands
* `/area_pos {set,set1,set2,get}` -- Sets the area positions by punching
nodes or shows the current area positions.

* `/area_pos1 [X,Y,Z|X Y Z]` -- Sets area position one to your position or
* `/area_pos1 [X Y Z|X,Y,Z|X, Y, Z]` -- Sets area position one to your position or
the one supplied.

* `/area_pos2 [X,Y,Z|X Y Z]` -- Sets area position two to your position or
* `/area_pos2 [X Y Z|X,Y,Z|X, Y, Z]` -- Sets area position two to your position or
the one supplied.

* `/areas_cleanup` -- Removes all ownerless areas.
Expand Down
8 changes: 4 additions & 4 deletions pos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ minetest.register_chatcommand("select_area", {
})

minetest.register_chatcommand("area_pos1", {
params = "[X Y Z|X,Y,Z]",
params = "[X Y Z|X,Y,Z|X, Y, Z]",
description = S("Set area protection region position @1 to your"
.." location or the one specified", "1"),
privs = {},
func = function(name, param)
local pos
local found, _, x, y, z = param:find(
local found, _, x, y, z = param:gsub(", ", ","):find(
"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$")
Comment on lines +50 to 51
Copy link
Member

@SmallJoker SmallJoker Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: instead of additional processing, fix the regular expression.
This here works: "^(-?%d+)[, ] *(-?%d+)[, ] *(-?%d+)$"

FYI: The Minetest builtin commands parse it like this: https://github.com/minetest/minetest/blob/master/builtin/game/chat.lua#L584
Those also support relative positions, which however is not a feature we need in this case (player position is too unrealiable).

if found then
pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
Expand All @@ -69,12 +69,12 @@ minetest.register_chatcommand("area_pos1", {
})

minetest.register_chatcommand("area_pos2", {
params = "[X Y Z|X,Y,Z]",
params = "[X Y Z|X,Y,Z|X, Y, Z]",
description = S("Set area protection region position @1 to your"
.." location or the one specified", "2"),
func = function(name, param)
local pos
local found, _, x, y, z = param:find(
local found, _, x, y, z = param:gsub(", ", ","):find(
"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$")
if found then
pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
Expand Down
Loading