Revert "i hope this fixes it now"

This reverts commit e0e4100f62.
master
crazyginger72 2014-06-23 15:49:02 -04:00
parent 7d3c9b1417
commit b63c90003c
6 changed files with 32 additions and 32 deletions

View File

@ -1,6 +1,6 @@
-- Returns a list of areas that include the provided position
function default:getAreasAtPos(pos)
function areas:getAreasAtPos(pos)
local a = {}
local px, py, pz = pos.x, pos.y, pos.z
for id, area in pairs(self.areas) do
@ -15,7 +15,7 @@ function default:getAreasAtPos(pos)
end
-- Checks if the area is unprotected or owned by you
function default:canInteract(pos, name)
function areas:canInteract(pos, name)
if minetest.check_player_privs(name, {areas=true}) then
return true
end
@ -33,7 +33,7 @@ function default:canInteract(pos, name)
end
-- Returns a table (list) of all players that own an area
function default:getNodeOwners(pos)
function areas:getNodeOwners(pos)
local owners = {}
for _, area in pairs(self:getAreasAtPos(pos)) do
table.insert(owners, area.owner)

View File

@ -21,7 +21,7 @@ minetest.register_chatcommand("protect", {
" startpos="..minetest.pos_to_string(pos1)..
" endpos=" ..minetest.pos_to_string(pos2))
local canAdd, errMsg = default:canPlayerAddArea(pos1, pos2, name)
local canAdd, errMsg = areas:canPlayerAddArea(pos1, pos2, name)
if not canAdd then
minetest.chat_send_player(name,
"You can't protect that area: "
@ -29,8 +29,8 @@ minetest.register_chatcommand("protect", {
return
end
local id = default:add(name, param, pos1, pos2, nil)
default:save()
local id = areas:add(name, param, pos1, pos2, nil)
areas:save()
minetest.chat_send_player(name, "Area protected. ID: "..id)
end})

View File

@ -6,10 +6,10 @@ minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
local a = default:getAreasAtPos(pos)
local a = areas:getAreasAtPos(pos)
local areaString = ""
local first = true
for id, area in pairs(default:getAreasAtPos(pos)) do
for id, area in pairs(areas:getAreasAtPos(pos)) do
if not first then
areaString = areaString..", "
else
@ -30,7 +30,7 @@ minetest.register_globalstep(function(dtime)
position = {x=0, y=1},
offset = {x=5, y=-60},
direction = 0,
text = "default: "..areaString,
text = "Areas: "..areaString,
scale = {x=200, y=60},
alignment = {x=1, y=1},
})
@ -38,7 +38,7 @@ minetest.register_globalstep(function(dtime)
return
elseif areas.hud[name].oldAreas ~= areaString then
player:hud_change(areas.hud[name].areasId, "text",
"default: "..areaString)
"Areas: "..areaString)
areas.hud[name].oldAreas = areaString
end
end

View File

@ -1,15 +1,15 @@
local old_is_protected = minetest.is_protected
function minetest.is_protected(pos, name)
if not default:canInteract(pos, name) then
if not areas:canInteract(pos, name) then
return true
end
return old_is_protected(pos, name)
end
minetest.register_on_protection_violation(function(pos, name)
if not adefault:canInteract(pos, name) then
local owners = default:getNodeOwners(pos)
if not areas:canInteract(pos, name) then
local owners = areas:getNodeOwners(pos)
minetest.chat_send_player(name,
("%s is protected by %s."):format(
minetest.pos_to_string(pos),

View File

@ -1,10 +1,10 @@
function default:player_exists(name)
function areas:player_exists(name)
return minetest.auth_table[name] ~= nil
end
-- Save the areas table to a file
function default:save()
function areas:save()
local datastr = minetest.serialize(self.areas)
if not datastr then
minetest.log("error", "[areas] Failed to serialize area data!")
@ -19,7 +19,7 @@ function default:save()
end
-- Load the areas table from the save file
function default:load()
function areas:load()
local file, err = io.open(self.filename, "r")
if err then
self.areas = self.areas or {}
@ -42,7 +42,7 @@ local function findFirstUnusedIndex(t)
end
-- Add a area, returning the new area's id.
function default:add(owner, name, pos1, pos2, parent)
function areas:add(owner, name, pos1, pos2, parent)
local id = findFirstUnusedIndex(self.areas)
self.areas[id] = {name=name, pos1=pos1, pos2=pos2, owner=owner,
parent=parent}
@ -52,7 +52,7 @@ end
-- Remove a area, and optionally it's children recursively.
-- If a area is deleted non-recursively the children will
-- have the removed area's parent as their new parent.
function default:remove(id, recurse, secondrun)
function areas:remove(id, recurse, secondrun)
if recurse then
-- Recursively find child entries and remove them
local cids = self:getChildren(id)
@ -76,7 +76,7 @@ function default:remove(id, recurse, secondrun)
end
-- Checks if a area between two points is entirely contained by another area
function default:isSubarea(pos1, pos2, id)
function areas:isSubarea(pos1, pos2, id)
local area = self.areas[id]
if not area then
return false
@ -93,7 +93,7 @@ function default:isSubarea(pos1, pos2, id)
end
-- Returns a table (list) of children of an area given it's identifier
function default:getChildren(id)
function areas:getChildren(id)
local children = {}
for cid, area in pairs(self.areas) do
if area.parent and area.parent == id then
@ -108,7 +108,7 @@ end
-- if the area intersects other areas that they do not own.
-- Also checks the size of the area and if the user already
-- has more than max_areas.
function default:canPlayerAddArea(pos1, pos2, name)
function areas:canPlayerAddArea(pos1, pos2, name)
if minetest.check_player_privs(name, {areas=true}) then
return true
end
@ -159,14 +159,14 @@ end
-- Given a id returns a string in the format:
-- "name [id]: owner (x1, y1, z1) (x2, y2, z2) -> children"
function default:toString(id)
function areas:toString(id)
local area = self.areas[id]
local message = ("%s [%d]: %s %s %s"):format(
area.name, id, area.owner,
minetest.pos_to_string(area.pos1),
minetest.pos_to_string(area.pos2))
local children = default:getChildren(id)
local children = areas:getChildren(id)
if #children > 0 then
message = message.." -> "..table.concat(children, ", ")
end
@ -174,7 +174,7 @@ function default:toString(id)
end
-- Re-order areas in table by their identifiers
function default:sort()
function areas:sort()
local sa = {}
for k, area in pairs(self.areas) do
if not area.parent then
@ -192,7 +192,7 @@ function default:sort()
end
-- Checks if a player owns an area or a parent of it
function default:isAreaOwner(id, name)
function areas:isAreaOwner(id, name)
local cur = self.areas[id]
if cur and minetest.check_player_privs(name, {areas=true}) then
return true

View File

@ -10,7 +10,7 @@ minetest.register_chatcommand("legacy_load_areas", {
minetest.chat_send_player(name, "Converting areas...")
local version = tonumber(param)
if version == 0 then
err = default:node_ownership_load()
err = areas:node_ownership_load()
if err then
minetest.chat_send_player(name, "Error loading legacy file: "..err)
return
@ -31,7 +31,7 @@ minetest.register_chatcommand("legacy_load_areas", {
nil, nil, nil, nil, nil, nil
-- Area positions sorting
area.pos1, area.pos2 = default:sortPos(area.pos1, area.pos2)
area.pos1, area.pos2 = areas:sortPos(area.pos1, area.pos2)
-- Add name
area.name = "unnamed"
@ -41,11 +41,11 @@ minetest.register_chatcommand("legacy_load_areas", {
end
minetest.chat_send_player(name, "Table format updated.")
default:save()
areas:save()
minetest.chat_send_player(name, "Converted areas saved. Done.")
end})
function default:node_ownership_load()
function areas:node_ownership_load()
local filename = minetest.get_worldpath().."/owners.tbl"
tables, err = loadfile(filename)
if err then
@ -77,7 +77,7 @@ end
-- Returns the name of the first player that owns an area
function areas.getNodeOwnerName(pos)
for id, area in pairs(default:getAreasAtPos(pos)) do
for id, area in pairs(areas:getAreasAtPos(pos)) do
return area.owner
end
return false
@ -88,7 +88,7 @@ function areas.isNodeOwner(pos, name)
if minetest.check_player_privs(name, {areas=true}) then
return true
end
for id, area in pairs(default:getAreasAtPos(pos)) do
for id, area in pairs(areas:getAreasAtPos(pos)) do
if name == area.owner then
return true
end
@ -98,7 +98,7 @@ end
-- Checks if an area has an owner
function areas.hasOwner(pos)
for id, area in pairs(default:getAreasAtPos(pos)) do
for id, area in pairs(areas:getAreasAtPos(pos)) do
return true
end
return false