From abd6a4c7097f4086e662b5faaf0e4d0f5ec112c0 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 30 May 2014 17:41:41 -0400 Subject: [PATCH] Centralize position getting and sorting --- chatcommands.lua | 18 ++++++------------ pos.lua | 12 ++++++------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index dc929f9..3a05a0a 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -7,10 +7,8 @@ minetest.register_chatcommand("protect", { if param == "" then return false, "Invalid usage, see /help protect." end - local pos1, pos2 = areas:getPos1(name), areas:getPos2(name) - if pos1 and pos2 then - pos1, pos2 = areas:sortPos(pos1, pos2) - else + local pos1, pos2 = areas:getPos(name) + if not (pos1 and pos2) then return false, "You need to select an area first." end @@ -45,10 +43,8 @@ minetest.register_chatcommand("set_owner", { return false, "Incorrect usage, see /help set_owner." end - local pos1, pos2 = areas:getPos1(name), areas:getPos2(name) - if pos1 and pos2 then - pos1, pos2 = areas:sortPos(pos1, pos2) - else + local pos1, pos2 = areas:getPos(name) + if not (pos1 and pos2) then return false, "You need to select an area first." end @@ -87,10 +83,8 @@ minetest.register_chatcommand("add_owner", { return end - local pos1, pos2 = areas:getPos1(name), areas:getPos2(name) - if pos1 and pos2 then - pos1, pos2 = areas:sortPos(pos1, pos2) - else + local pos1, pos2 = areas:getPos(name) + if not (pos1 and pos2) then return false, "You need to select an area first." end diff --git a/pos.lua b/pos.lua index 3dbf07c..e4f2d25 100644 --- a/pos.lua +++ b/pos.lua @@ -118,12 +118,12 @@ minetest.register_chatcommand("area_pos", { end, }) -function areas:getPos1(playerName) - return areas.pos1[playerName] -end - -function areas:getPos2(playerName) - return areas.pos2[playerName] +function areas:getPos(playerName) + local pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName] + if not (pos1 and pos2) then + return nil + end + return areas:sortPos(pos1, pos2) end function areas:setPos1(playerName, pos)