forked from mtcontrib/factions
Fixed protection to use newer API
This commit is contained in:
parent
4c72e388e8
commit
565608876b
133
factions.lua
133
factions.lua
|
@ -498,11 +498,9 @@ end
|
|||
function factions.get_player_faction(playername)
|
||||
local facname = factions.players[playername]
|
||||
if facname then
|
||||
minetest.chat_send_all(facname)
|
||||
local faction = factions.factions[facname]
|
||||
return faction
|
||||
end
|
||||
minetest.chat_send_all(playername)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
@ -557,13 +555,13 @@ end
|
|||
-------------------------------------------------------------------------------
|
||||
function factions.get_faction_list()
|
||||
|
||||
local retval = {}
|
||||
|
||||
for key,value in pairs(factions.factions) do
|
||||
table.insert(retval,key)
|
||||
end
|
||||
|
||||
return retval
|
||||
local retval = {}
|
||||
|
||||
for key,value in pairs(factions.factions) do
|
||||
table.insert(retval,key)
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -575,20 +573,20 @@ end
|
|||
-------------------------------------------------------------------------------
|
||||
function factions.save()
|
||||
|
||||
--saving is done much more often than reading data to avoid delay
|
||||
--due to figuring out which data to save and which is temporary only
|
||||
--all data is saved here
|
||||
--this implies data needs to be cleant up on load
|
||||
|
||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
|
||||
|
||||
if file ~= nil then
|
||||
file:write(minetest.serialize(factions.factions))
|
||||
file:close()
|
||||
else
|
||||
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
||||
end
|
||||
|
||||
--saving is done much more often than reading data to avoid delay
|
||||
--due to figuring out which data to save and which is temporary only
|
||||
--all data is saved here
|
||||
--this implies data needs to be cleant up on load
|
||||
|
||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
|
||||
|
||||
if file ~= nil then
|
||||
file:write(minetest.serialize(factions.factions))
|
||||
file:close()
|
||||
else
|
||||
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -601,11 +599,11 @@ end
|
|||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function factions.load()
|
||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
|
||||
|
||||
if file ~= nil then
|
||||
local raw_data = file:read("*a")
|
||||
factions.factions = minetest.deserialize(raw_data)
|
||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
|
||||
|
||||
if file ~= nil then
|
||||
local raw_data = file:read("*a")
|
||||
factions.factions = minetest.deserialize(raw_data)
|
||||
for facname, faction in pairs(factions.factions) do
|
||||
minetest.log("action", facname..","..faction.name)
|
||||
for player, rank in pairs(faction.players) do
|
||||
|
@ -630,7 +628,7 @@ function factions.load()
|
|||
faction.usedpower = faction:count_land() * factions.power_per_parcel
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -669,16 +667,16 @@ function factions.convert(filename)
|
|||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_dieplayer(
|
||||
function(player)
|
||||
local faction = factions.get_player_faction(player:get_player_name())
|
||||
if not faction then
|
||||
return true
|
||||
end
|
||||
faction:decrease_power(factions.power_per_death)
|
||||
function(player)
|
||||
local faction = factions.get_player_faction(player:get_player_name())
|
||||
if not faction then
|
||||
return true
|
||||
end
|
||||
faction:decrease_power(factions.power_per_death)
|
||||
return true
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
@ -695,45 +693,43 @@ local factionUpdate = 0.
|
|||
|
||||
|
||||
minetest.register_globalstep(
|
||||
function(dtime)
|
||||
hudUpdate = hudUpdate + dtime
|
||||
factionUpdate = factionUpdate + dtime
|
||||
if hudUpdate > .5 then
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local faction = factions.get_faction_at(player:getpos())
|
||||
player:hud_remove("factionLand")
|
||||
player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "factionLand",
|
||||
number = 0xFFFFFF,
|
||||
position = {x=0.1, y = .98},
|
||||
text = (faction and faction.name) or "Wilderness",
|
||||
scale = {x=1, y=1},
|
||||
alignment = {x=0, y=0},
|
||||
})
|
||||
end
|
||||
hudUpdate = 0.
|
||||
end
|
||||
if factionUpdate > factions.tick_time then
|
||||
factions.faction_tick()
|
||||
factionUpdate = 0.
|
||||
function(dtime)
|
||||
hudUpdate = hudUpdate + dtime
|
||||
factionUpdate = factionUpdate + dtime
|
||||
if hudUpdate > .5 then
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local faction = factions.get_faction_at(player:getpos())
|
||||
player:hud_remove("factionLand")
|
||||
player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "factionLand",
|
||||
number = 0xFFFFFF,
|
||||
position = {x=0.1, y = .98},
|
||||
text = (faction and faction.name) or "Wilderness",
|
||||
scale = {x=1, y=1},
|
||||
alignment = {x=0, y=0},
|
||||
})
|
||||
end
|
||||
hudUpdate = 0.
|
||||
end
|
||||
if factionUpdate > factions.tick_time then
|
||||
factions.faction_tick()
|
||||
factionUpdate = 0.
|
||||
end
|
||||
end
|
||||
)
|
||||
minetest.register_on_joinplayer(
|
||||
function(player)
|
||||
end
|
||||
function(player)
|
||||
end
|
||||
)
|
||||
minetest.register_on_respawnplayer(
|
||||
function(player)
|
||||
local playername = player:get_player_name()
|
||||
local faction = factions.players[playername]
|
||||
local faction = factions.get_player_faction(player:get_player_name())
|
||||
if not faction then
|
||||
return false
|
||||
else
|
||||
faction = factions.factions[faction]
|
||||
if not faction.spawn then
|
||||
return false
|
||||
else
|
||||
|
@ -756,8 +752,8 @@ minetest.is_protected = function(pos, player)
|
|||
end
|
||||
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
local parcel_faction = factions.parcels[parcelpos]
|
||||
local player_faction = factions.players[player]
|
||||
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||
local player_faction = factions.get_player_faction(player)
|
||||
-- check if wielding death banner
|
||||
local player_info = minetest.get_player_by_name(player)
|
||||
if not player_info then
|
||||
|
@ -769,15 +765,12 @@ minetest.is_protected = function(pos, player)
|
|||
end
|
||||
local player_wield = player_info:get_wielded_item()
|
||||
if player_wield:get_name() == "banners:death_banner" and player_faction then --todo: check for allies, maybe for permissions
|
||||
player_faction = factions.factions[player_faction]
|
||||
parcel_faction = factions.factions[parcel_faction]
|
||||
return not player_faction:has_permission(player, "claim") and player_faction.power > 0. and not parcel_faction.is_admin
|
||||
end
|
||||
-- no faction
|
||||
if not parcel_faction then
|
||||
return default_is_protected(pos, player)
|
||||
else
|
||||
parcel_faction = factions.factions[parcel_faction]
|
||||
if parcel_faction.name == player_faction then
|
||||
return not parcel_faction:has_permission(player, "build")
|
||||
elseif parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked
|
||||
|
|
Loading…
Reference in New Issue
Block a user