Update code to use new API functions
This commit is contained in:
parent
a4f09c7d8e
commit
4d53e4cc40
@ -54,7 +54,7 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
local argtype = self.format[i]
|
local argtype = self.format[i]
|
||||||
local arg = argv[i]
|
local arg = argv[i]
|
||||||
if argtype == "faction" then
|
if argtype == "faction" then
|
||||||
local fac = factions.factions[arg]
|
local fac = factions.get_faction(arg)
|
||||||
if not fac then
|
if not fac then
|
||||||
send_error(player, "Specified faction "..arg.." does not exist")
|
send_error(player, "Specified faction "..arg.." does not exist")
|
||||||
return false
|
return false
|
||||||
@ -63,9 +63,8 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
end
|
end
|
||||||
elseif argtype == "player" then
|
elseif argtype == "player" then
|
||||||
local pl = minetest.get_player_by_name(arg)
|
local pl = minetest.get_player_by_name(arg)
|
||||||
if not pl then
|
if not pl or not factions.player[arg] then
|
||||||
send_error(player, "Player is not online.")
|
send_error(player, "Player is not online.")
|
||||||
--TODO: track existing players for offsync invites and the like
|
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
table.insert(args.players, pl)
|
table.insert(args.players, pl)
|
||||||
@ -83,12 +82,11 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- checks permissions
|
-- checks permissions
|
||||||
local player_faction = factions.players[player]
|
local player_faction = factions.get_player_faction(player)
|
||||||
if self.infaction and not player_faction then
|
if self.infaction and not player_faction then
|
||||||
minetest.chat_send_player(player, "This command is only available within a faction.")
|
minetest.chat_send_player(player, "This command is only available within a faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
player_faction = factions.factions[player_faction]
|
|
||||||
if self.faction_permissions then
|
if self.faction_permissions then
|
||||||
for i in ipairs(self.faction_permissions) do
|
for i in ipairs(self.faction_permissions) do
|
||||||
if not player_faction:has_permission(player, self.faction_permissions[i]) then
|
if not player_faction:has_permission(player, self.faction_permissions[i]) then
|
||||||
@ -166,11 +164,11 @@ factions.register_command ("claim", {
|
|||||||
faction:claim_parcel(parcelpos)
|
faction:claim_parcel(parcelpos)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
local parcel = factions.parcels[parcelpos]
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||||
if not parcel then
|
if not parcel_faction then
|
||||||
send_error(player, "You faction cannot claim any (more) parcel(s).")
|
send_error(player, "You faction cannot claim any (more) parcel(s).")
|
||||||
return false
|
return false
|
||||||
elseif parcel == faction.name then
|
elseif parcel_faction.name == faction.name then
|
||||||
send_error(player, "This parcel already belongs to your faction.")
|
send_error(player, "This parcel already belongs to your faction.")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@ -185,8 +183,8 @@ factions.register_command("unclaim", {
|
|||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Unclaim the plot of land you're on.",
|
description = "Unclaim the plot of land you're on.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local parcel = factions.parcels[parcelpos]
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||||
if parcel ~= faction.name then
|
if parcel_faction.name ~= faction.name then
|
||||||
send_error(player, "This parcel does not belong to you.")
|
send_error(player, "This parcel does not belong to you.")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@ -250,12 +248,15 @@ factions.register_command("kick", {
|
|||||||
description = "Kick a player from your faction.",
|
description = "Kick a player from your faction.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local victim = args.players[1]
|
local victim = args.players[1]
|
||||||
if factions.players[victim:get_player_name()] == faction.name
|
local victim_faction = factions.get_player_faction(victim:get_player_name())
|
||||||
and victim:get_player_name() ~= faction.leader then -- can't kick da king
|
if victim_faction and victim:get_player_name() ~= faction.leader then -- can't kick da king
|
||||||
faction:remove_player(player)
|
faction:remove_player(player)
|
||||||
return true
|
return true
|
||||||
|
elseif not victim_faction then
|
||||||
|
send_error(player, victim:get_player_name().." is not in your faction.")
|
||||||
|
return false
|
||||||
else
|
else
|
||||||
send_error(player, "Cannot kick player "..victim:get_player_name())
|
send_error(player, victim:get_player_name().." cannot be kicked from your faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -344,7 +345,6 @@ factions.register_command("invite", {
|
|||||||
description = "Invite a player to your faction.",
|
description = "Invite a player to your faction.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:invite_player(args.players[1]:get_player_name())
|
faction:invite_player(args.players[1]:get_player_name())
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -355,7 +355,6 @@ factions.register_command("uninvite", {
|
|||||||
description = "Revoke a player's invite.",
|
description = "Revoke a player's invite.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:revoke_invite(args.players[1]:get_player_name())
|
faction:revoke_invite(args.players[1]:get_player_name())
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -367,7 +366,6 @@ factions.register_command("delete", {
|
|||||||
description = "Delete a faction.",
|
description = "Delete a faction.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
args.factions[1]:disband()
|
args.factions[1]:disband()
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -445,8 +443,9 @@ factions.register_command("where", {
|
|||||||
description = "See whose parcel you stand on.",
|
description = "See whose parcel you stand on.",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local parcel = factions.parcels[parcelpos]
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||||
minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..(parcel or "Wilderness"))
|
local place_name = (parcel_faction and parcel_faction.name) or "Wilderness"
|
||||||
|
minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..place_name)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -531,13 +530,14 @@ factions.register_command("free", {
|
|||||||
infaction = false,
|
infaction = false,
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local fac = factions.parcels[parcelpos]
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||||
if not fac then
|
if not parcel_faction then
|
||||||
send_error(player, "No claim at this position")
|
send_error(player, "No claim at this position")
|
||||||
return false
|
return false
|
||||||
|
else
|
||||||
|
parcel_faction:unclaim_parcel(parcelpos)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
faction:unclaim_parcel(parcelpos)
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -571,12 +571,12 @@ factions_chat.cmdhandler = function (playername,parameter)
|
|||||||
|
|
||||||
local player = minetest.env:get_player_by_name(playername)
|
local player = minetest.env:get_player_by_name(playername)
|
||||||
local params = parameter:split(" ")
|
local params = parameter:split(" ")
|
||||||
local player_faction = factions.players[playername]
|
local player_faction = factions.get_player_faction(playername)
|
||||||
|
|
||||||
if parameter == nil or
|
if parameter == nil or
|
||||||
parameter == "" then
|
parameter == "" then
|
||||||
if player_faction then
|
if player_faction then
|
||||||
minetest.chat_send_player(playername, "You are in faction "..player_faction..". Type /f help for a list of commands.")
|
minetest.chat_send_player(playername, "You are in faction "..player_faction.name..". Type /f help for a list of commands.")
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(playername, "You are part of no faction")
|
minetest.chat_send_player(playername, "You are part of no faction")
|
||||||
end
|
end
|
||||||
|
@ -710,7 +710,7 @@ factions.faction_tick = function()
|
|||||||
if faction:is_online() then
|
if faction:is_online() then
|
||||||
faction:increase_power(factions.power_per_tick)
|
faction:increase_power(factions.power_per_tick)
|
||||||
end
|
end
|
||||||
if faction.last_logon > factions.maximum_faction_inactivity then
|
if faction.last_logon - now > factions.maximum_faction_inactivity then
|
||||||
faction:disband()
|
faction:disband()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user