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