diff --git a/locale/areas.fr.tr b/locale/areas.fr.tr index bbbc089..b60726c 100644 --- a/locale/areas.fr.tr +++ b/locale/areas.fr.tr @@ -133,3 +133,5 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.=La zone @1 n’existe pas. Unable to get position.=Impossible d’obtenir la position. Unknown subcommand: @1=Sous-commande inconnue : @1 + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.= diff --git a/locale/areas.it.tr b/locale/areas.it.tr index 006b04d..7fe77da 100644 --- a/locale/areas.it.tr +++ b/locale/areas.it.tr @@ -133,3 +133,5 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.=L'area @1 non esiste. Unable to get position.=Impossibile ottenere la posizione. Unknown subcommand: @1=Sotto-comando sconosciuto: @1 + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.= diff --git a/locale/areas.ru.tr b/locale/areas.ru.tr index 43d8634..11e8c74 100644 --- a/locale/areas.ru.tr +++ b/locale/areas.ru.tr @@ -133,3 +133,5 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.=Территория @1 не существует. Unable to get position.=Не удалось получить позицию. Unknown subcommand: @1=Неизвестная под-команда/аргумент. + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.= diff --git a/locale/areas.zh_CN.tr b/locale/areas.zh_CN.tr index 57f021b..2ac2be1 100644 --- a/locale/areas.zh_CN.tr +++ b/locale/areas.zh_CN.tr @@ -132,4 +132,6 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.=保护区 @1 不存在。 Unable to get position.=无法获得座标。 -Unknown subcommand: @1=子指令不明:@1 \ No newline at end of file +Unknown subcommand: @1=子指令不明:@1 + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.=此服务器不支援相对座标。请更新Minetest至5.7.0或之后的版本。 \ No newline at end of file diff --git a/locale/areas.zh_TW.tr b/locale/areas.zh_TW.tr index e53ecbb..4a2c33f 100644 --- a/locale/areas.zh_TW.tr +++ b/locale/areas.zh_TW.tr @@ -133,3 +133,5 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.=保護區 @1 不存在。 Unable to get position.=無法獲得座標。 Unknown subcommand: @1=子指令不明:@1 + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.=此伺服器不支援相對座標。請更新Minetest至5.7.0或之後的版本。 diff --git a/locale/template.txt b/locale/template.txt index 2026c5e..3508101 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -133,3 +133,5 @@ Set area protection region, position 1, or position 2 by punching nodes, or disp The area @1 does not exist.= Unable to get position.= Unknown subcommand: @1= + +Relative coordinates is not supported on this server. Please upgrade Minetest to 5.7.0 or newer versions.= diff --git a/pos.lua b/pos.lua index 7a9cbd2..f512eac 100644 --- a/pos.lua +++ b/pos.lua @@ -22,6 +22,37 @@ local function posLimit(pos) } end +local parse_relative_pos + +if minetest.parse_relative_number then + parse_relative_pos = function(x_str, y_str, z_str, pos) + + local x = pos and minetest.parse_relative_number(x_str, pos.x) + or tonumber(x_str) + local y = pos and minetest.parse_relative_number(y_str, pos.y) + or tonumber(y_str) + local z = pos and minetest.parse_relative_number(z_str, pos.z) + or tonumber(z_str) + if x and y and z then + return vector.new(x, y, z) + end + end +else + parse_relative_pos = function(x_str, y_str, z_str, pos) + local x = tonumber(x_str) + local y = tonumber(y_str) + local z = tonumber(z_str) + if x and y and z then + return vector.new(x, y, z) + elseif string.sub(x_str, 1, 1) == "~" + or string.sub(y_str, 1, 1) == "~" + or string.sub(z_str, 1, 1) == "~" then + return nil, S("Relative coordinates is not supported on this server. " .. + "Please upgrade Minetest to 5.7.0 or newer versions.") + end + end +end + minetest.register_chatcommand("select_area", { params = S(""), description = S("Select an area by ID."), @@ -47,20 +78,25 @@ minetest.register_chatcommand("area_pos1", { privs = {}, func = function(name, param) local pos - local found, _, x, y, z = param:find( - "^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") + local player = minetest.get_player_by_name(name) + if player then + pos = vector.round(player:get_pos()) + end + local found, _, x_str, y_str, z_str = param:find( + "^(~?-?%d*)[, ](~?-?%d*)[, ](~?-?%d*)$") if found then - pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)} - elseif param == "" then - local player = minetest.get_player_by_name(name) - if player then - pos = player:get_pos() - else - return false, S("Unable to get position.") + local get_pos, reason = parse_relative_pos(x_str, y_str, z_str, pos) + if get_pos then + pos = get_pos + elseif not get_pos and reason then + return false, reason end - else + elseif param ~= "" then return false, S("Invalid usage, see /help @1.", "area_pos1") end + if not pos then + return false, S("Unable to get position.") + end pos = posLimit(vector.round(pos)) areas:setPos1(name, pos) return true, S("Area position @1 set to @2", "1", @@ -74,20 +110,25 @@ minetest.register_chatcommand("area_pos2", { .." location or the one specified", "2"), func = function(name, param) local pos - local found, _, x, y, z = param:find( - "^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") + local player = minetest.get_player_by_name(name) + if player then + pos = vector.round(player:get_pos()) + end + local found, _, x_str, y_str, z_str = param:find( + "^(~?-?%d*)[, ](~?-?%d*)[, ](~?-?%d*)$") if found then - pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)} - elseif param == "" then - local player = minetest.get_player_by_name(name) - if player then - pos = player:get_pos() - else - return false, S("Unable to get position.") + local get_pos, reason = parse_relative_pos(x_str, y_str, z_str, pos) + if get_pos then + pos = get_pos + elseif not get_pos and reason then + return false, reason end - else + elseif param ~= "" then return false, S("Invalid usage, see /help @1.", "area_pos2") end + if not pos then + return false, S("Unable to get position.") + end pos = posLimit(vector.round(pos)) areas:setPos2(name, pos) return true, S("Area position @1 set to @2", "2",