mirror of
https://github.com/mt-mods/playerfactions.git
synced 2024-11-29 10:43:50 +01:00
kick: cleanup
- simplify and reduce calls of core.get_player_privs() - update help text to standard syntax - streamline duplicate code - remove unnecessary param count checks - remove explicit nil check where not needed - don't call get_owner if is admin (until needed)
This commit is contained in:
parent
6efb00ec69
commit
c68ccd6f44
39
init.lua
39
init.lua
@ -93,16 +93,14 @@ function factions.get_owned_factions(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function factions.get_administered_factions(name)
|
function factions.get_administered_factions(name)
|
||||||
local adm_factions = nil
|
local is_admin = minetest.get_player_privs(name)[factions.priv]
|
||||||
|
local adm_factions = {}
|
||||||
for fname, fact in pairs(facts) do
|
for fname, fact in pairs(facts) do
|
||||||
if minetest.get_player_privs(name)[factions.priv] or fact.owner == name then
|
if is_admin or fact.owner == name then
|
||||||
if not adm_factions then
|
|
||||||
adm_factions = {}
|
|
||||||
end
|
|
||||||
table.insert(adm_factions, fname)
|
table.insert(adm_factions, fname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return adm_factions
|
return 0 < table.getn(adm_factions) and adm_factions or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.get_owner(fname)
|
function factions.get_owner(fname)
|
||||||
@ -371,34 +369,31 @@ local function handle_command(name, param)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif action == "kick" then
|
elseif action == "kick" then
|
||||||
local target = nil
|
local target = params[2]
|
||||||
local faction_name = nil
|
local faction_name = params[3]
|
||||||
local own_factions = factions.get_administered_factions(name)
|
local own_factions = factions.get_administered_factions(name)
|
||||||
local number_factions = own_factions and table.getn(own_factions) or 0
|
local number_factions = own_factions and table.getn(own_factions) or 0
|
||||||
if number_factions == 0 then
|
if number_factions == 0 then
|
||||||
return false, S("You don't own any factions, you can't use this command.")
|
return false, S("You don't own any factions, you can't use this command.")
|
||||||
elseif #params == 2 and number_factions == 1 then
|
elseif not faction_name and number_factions == 1 then
|
||||||
target = params[2]
|
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
elseif #params >= 3 then
|
else
|
||||||
faction_name = params[3]
|
|
||||||
target = params[2]
|
|
||||||
end
|
|
||||||
if faction_name == nil then
|
|
||||||
return false, S(
|
return false, S(
|
||||||
"You are the owner of multiple factions, you have to choose one of them: @1.",
|
"You are the owner of multiple factions, you have to choose one of them: @1.",
|
||||||
table.concat(own_factions, ", ")
|
table.concat(own_factions, ", ")
|
||||||
)
|
)
|
||||||
elseif target == nil then
|
end
|
||||||
|
if not target then
|
||||||
return false, S("Missing player name.")
|
return false, S("Missing player name.")
|
||||||
elseif factions.get_owner(faction_name) ~= name and not minetest.get_player_privs(name)[factions.priv] then
|
elseif not is_admin and factions.get_owner(faction_name) ~= name then
|
||||||
return false, S("Permission denied: You are not the owner of that faction, " ..
|
return false, S("Permission denied: You are not the owner of that faction, "
|
||||||
"and don't have the @1 privilege.", factions.priv)
|
.. "and don't have the @1 privilege.", factions.priv)
|
||||||
elseif not facts[faction_name].members[target] then
|
elseif not facts[faction_name].members[target] then
|
||||||
return false, S("@1 is not in the specified faction.", target)
|
return false, S("@1 is not in the specified faction.", target)
|
||||||
elseif target == factions.get_owner(faction_name) then
|
elseif target == factions.get_owner(faction_name) then
|
||||||
return false, S("You cannot kick the owner of a faction, " ..
|
return false, S("You cannot kick the owner of a faction, "
|
||||||
"use '/factions chown <player> [faction]' to change the ownership.")
|
.. "use '/factions chown <player> <password> [<faction>]' "
|
||||||
|
.. "to change the ownership.")
|
||||||
else
|
else
|
||||||
if factions.leave_faction(faction_name, target) then
|
if factions.leave_faction(faction_name, target) then
|
||||||
return true, S("Kicked @1 from faction.", target)
|
return true, S("Kicked @1 from faction.", target)
|
||||||
@ -521,10 +516,10 @@ minetest.register_chatcommand("factions", {
|
|||||||
.."info [<faction>]: "..S("See information about a faction").."\n"
|
.."info [<faction>]: "..S("See information about a faction").."\n"
|
||||||
.."player_info [<player>]: "..S("See information about a player").."\n"
|
.."player_info [<player>]: "..S("See information about a player").."\n"
|
||||||
.."join <faction> <password>: "..S("Join an existing faction").."\n"
|
.."join <faction> <password>: "..S("Join an existing faction").."\n"
|
||||||
.."kick <player> [faction]: "..S("Kick someone from your faction or from the given faction").."\n"
|
|
||||||
.."passwd <password> [faction]: "..S("Change your faction's password or the password of the given faction").."\n"
|
.."passwd <password> [faction]: "..S("Change your faction's password or the password of the given faction").."\n"
|
||||||
.."chown <player> <password> [faction]: "..S("Transfer ownership of your faction").."\n"
|
.."chown <player> <password> [faction]: "..S("Transfer ownership of your faction").."\n"
|
||||||
.."leave [<faction>]: "..S("Leave your faction").."\n"
|
.."leave [<faction>]: "..S("Leave your faction").."\n"
|
||||||
|
.."kick <player> [<faction>]: "..S("Kick someone from your faction or from the given faction").."\n"
|
||||||
.."disband <password> [<faction>]: "..S("Disband your faction or the given faction").."\n"
|
.."disband <password> [<faction>]: "..S("Disband your faction or the given faction").."\n"
|
||||||
.."invite <player> <faction>: "..S("Add player to a faction, you need @1 priv", factions.priv).."\n",
|
.."invite <player> <faction>: "..S("Add player to a faction, you need @1 priv", factions.priv).."\n",
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ You are the owner of multiple factions, you have to choose one of them: @1.=Vous
|
|||||||
You don't own any factions, you can't use this command.=Vous n’êtes propriétaire d’aucune faction, vous ne pouvez pas utiliser cette commande.
|
You don't own any factions, you can't use this command.=Vous n’êtes propriétaire d’aucune faction, vous ne pouvez pas utiliser cette commande.
|
||||||
You don't own any factions.=Vous n’êtes propriétaire d’aucune faction.
|
You don't own any factions.=Vous n’êtes propriétaire d’aucune faction.
|
||||||
|
|
||||||
You cannot kick the owner of a faction, use '/factions chown <player> [faction]' to change the ownership.=Vous ne pouvez pas virer le propriétaire de sa faction, utilisez '/factions chown <player> [faction]' pour changer le propriétaire.
|
You cannot kick the owner of a faction, use '/factions chown <player> <password> [<faction>]' to change the ownership.=Vous ne pouvez pas virer le propriétaire de sa faction, utilisez '/factions chown <joueur> <mot de passe> [<faction>]' pour changer le propriétaire.
|
||||||
|
|
||||||
You cannot leave your own faction, change owner or disband it.=Vous ne pouvez pas quitter votre propre faction, changez le propriétaire ou dissolvez la.
|
You cannot leave your own faction, change owner or disband it.=Vous ne pouvez pas quitter votre propre faction, changez le propriétaire ou dissolvez la.
|
||||||
No factions found.=
|
No factions found.=
|
||||||
|
@ -70,7 +70,7 @@ You are the owner of multiple factions, you have to choose one of them: @1.=
|
|||||||
You don't own any factions, you can't use this command.=
|
You don't own any factions, you can't use this command.=
|
||||||
You don't own any factions.=
|
You don't own any factions.=
|
||||||
|
|
||||||
You cannot kick the owner of a faction, use '/factions chown <player> [faction]' to change the ownership.=
|
You cannot kick the owner of a faction, use '/factions chown <player> <password> [<faction>]' to change the ownership.=
|
||||||
|
|
||||||
You cannot leave your own faction, change owner or disband it.=
|
You cannot leave your own faction, change owner or disband it.=
|
||||||
No factions found.=
|
No factions found.=
|
||||||
|
Loading…
Reference in New Issue
Block a user