Kick town from nation
This commit is contained in:
parent
a58783bf67
commit
9ebb7bc788
@ -16,7 +16,7 @@ minetest.register_privilege("towny_admin", {
|
||||
-- Send message to all town members who are online
|
||||
function towny.chat.announce_to_members(town,message)
|
||||
local tdata = towny.towns[town]
|
||||
if tdata then return end
|
||||
if not tdata then return end
|
||||
for member in pairs(tdata.members) do
|
||||
if minetest.get_player_by_name(member) then
|
||||
minetest.chat_send_player(member,message)
|
||||
|
@ -312,7 +312,21 @@ function towny.delete_town(pos,player)
|
||||
return err_msg(player, "You do not have permission to delete this town.")
|
||||
end
|
||||
|
||||
local name = data.name .. ""
|
||||
local name = towny.get_full_name(town) .. ""
|
||||
|
||||
if towny.nations then
|
||||
local nat = towny.nations.get_town_nation(town)
|
||||
if nat then
|
||||
local ndata = towny.nations.nations[nat]
|
||||
if ndata.flags.capital == town then
|
||||
return err_msg(player, "You must delete or transfer ownership of your nation first.")
|
||||
else
|
||||
-- Leave nation
|
||||
ndata.members[town] = nil
|
||||
ndata.dirty = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Wipe the town
|
||||
towny.towns[t] = nil
|
||||
@ -320,7 +334,7 @@ function towny.delete_town(pos,player)
|
||||
towny.storage.delete_all_meta(t)
|
||||
|
||||
minetest.chat_send_player(player, "Successfully deleted the town!")
|
||||
minetest.chat_send_all(("The town '%s' has fell into ruin."):format(name))
|
||||
minetest.chat_send_all(("%s has fell into ruin."):format(name))
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ towny.chat.invites.nation = {}
|
||||
-- Send message to all town members who are online
|
||||
function towny.nations.announce_to_members(nation,message)
|
||||
local ndata = towny.nations.nations[nation]
|
||||
if ndata then return end
|
||||
if not ndata then return end
|
||||
for town in pairs(ndata.members) do
|
||||
towny.chat.announce_to_members(town,message)
|
||||
end
|
||||
@ -19,7 +19,7 @@ local function join_nation(nation,player,from_invite)
|
||||
if towny.nations.get_town_nation(town) then return false, "Your town is already part of a nation." end
|
||||
if tdata.flags.mayor ~= player then return false, "Only the mayor can join their town into a nation." end
|
||||
if (not from_invite and not ndata.flags['joinable']) then return false, "You cannot join this nation." end
|
||||
towny.nations.announce_to_members(town, minetest.colorize("#02aacc", ("%s has joined the nation!"):format(towny.get_full_name(town))))
|
||||
towny.nations.announce_to_members(nation, minetest.colorize("#02aacc", ("%s has joined the nation!"):format(towny.get_full_name(town))))
|
||||
minetest.chat_send_player(player, ("Your town has successfully joined %s!"):format(towny.nations.get_full_name(nation)))
|
||||
ndata.members[town] = {}
|
||||
ndata.dirty = true
|
||||
@ -77,7 +77,7 @@ local function invite_town(player,town)
|
||||
return false, "You can only invite towns to your nation if you own said nation!"
|
||||
end
|
||||
|
||||
if not towny.get_town_by_name(town) then
|
||||
if not town then
|
||||
return false, "Invalid town name."
|
||||
end
|
||||
|
||||
@ -99,8 +99,8 @@ local function invite_town(player,town)
|
||||
minetest.chat_send_player(target, ("Your town has been invited to join %s by %s"):format(towny.nations.get_full_name(nation), player))
|
||||
minetest.chat_send_player(target, "You can accept this invite by typing '/nation invite accept' or deny '/nation invite deny'")
|
||||
|
||||
towny.chat.invites[town.."-"..nation] = { rejected = false, nation = nation, town = town, invited = player }
|
||||
return true, ("Town %s has been invited to join your nation."):format(town)
|
||||
towny.chat.invites.nation[town.."-"..nation] = { rejected = false, nation = nation, town = town, invited = player, player = target }
|
||||
return true, ("%s has been invited to join your nation."):format(towny.get_full_name(town))
|
||||
end
|
||||
|
||||
local function nation_command(name, param)
|
||||
@ -125,7 +125,7 @@ local function nation_command(name, param)
|
||||
elseif (pr1 == "invite" and not towny.get_town_by_name(pr2)) then
|
||||
return invite_respond(name, (pr2:lower() == "accept" or minetest.is_yes(pr2)))
|
||||
elseif pr1 == "join" and towny.nations.get_nation_by_name(pr2) and not nation then
|
||||
return join_nation(pr2,name,false)
|
||||
return join_nation(towny.nations.get_nation_by_name(pr2),name,false)
|
||||
elseif pr1 == "show" or pr1 == "info" then
|
||||
if not towny.get_town_by_name(pr2) then
|
||||
return false, "No such nation."
|
||||
@ -159,11 +159,13 @@ local function nation_command(name, param)
|
||||
if flags then
|
||||
return towny.chat.send_flags(flags,"Flags of your nation")
|
||||
end
|
||||
elseif pl1 == "set" and pl2 then
|
||||
local flag, value = string.match(pl2, "^([%a%d_-]+) (.+)$")
|
||||
elseif pr1 == "set" and pr2 then
|
||||
local flag, value = string.match(pr2, "^([%a%d_-]+) (.+)$")
|
||||
return towny.nations.set_nation_flags(name,flag,value)
|
||||
elseif pr1 == "invite" and towny.get_town_by_name(pr2) then
|
||||
return invite_town(name,towny.get_town_by_name(pr2))
|
||||
elseif pr1 == "kick" and towny.get_town_by_name(pr2) then
|
||||
return towny.nations.kick_town(towny.get_town_by_name(pr2),player)
|
||||
end
|
||||
|
||||
return false, "Invalid command usage."
|
||||
|
@ -63,6 +63,8 @@ function towny.nations.create_nation(name,player)
|
||||
name = name,
|
||||
members = {[town] = {}},
|
||||
flags = {capital = town},
|
||||
allies = {},
|
||||
enemies = {},
|
||||
}
|
||||
|
||||
mark_dirty(nid)
|
||||
@ -96,15 +98,16 @@ function towny.nations.leave_nation(player)
|
||||
|
||||
if ndata.flags['capital'] == town and count(ndata.members) <= 1 then
|
||||
-- Single member town, delete nation
|
||||
local name = towny.nations.get_full_name(nation)
|
||||
towny.storage.delete_all_meta(nation)
|
||||
towny.nations.nations[nation] = nil
|
||||
minetest.chat_send_player(player, "Successfully deleted the nation!")
|
||||
minetest.chat_send_all(("The nation '%s' has fallen."):format(ndata.name))
|
||||
minetest.chat_send_all(("%s has fallen."):format(name))
|
||||
else
|
||||
-- Simply leave
|
||||
minetest.chat_send_player(player, "Successfully left the nation!")
|
||||
towny.nations.nations[nation].members[town] = nil
|
||||
towny.nations.announce_to_members(nation, ("Town '%s' has left the nation."):format(tdata.name))
|
||||
towny.nations.announce_to_members(nation, ("%s has left the nation."):format(towny.get_full_name(town)))
|
||||
mark_dirty(nation)
|
||||
end
|
||||
|
||||
@ -119,15 +122,14 @@ function towny.nations.set_nation_flags(player,flag,value)
|
||||
return err_msg(player, "You're not currently in a town!")
|
||||
end
|
||||
|
||||
local nation = towny.nations.get_nation_by_name(name)
|
||||
local ndata = towny.nations.nations[name]
|
||||
local nation = towny.nations.get_town_nation(town)
|
||||
local ndata = towny.nations.nations[nation]
|
||||
local tdata = towny.towns[town]
|
||||
if not nation or not ndata then
|
||||
return err_msg(player, "Your town is currently not part of any nation!")
|
||||
end
|
||||
|
||||
local ndata = towny.nations.nations[t]
|
||||
if tdata.flags.capital ~= ndata.name or tdata.flags.mayor ~= player then
|
||||
if ndata.flags.capital ~= town or tdata.flags.mayor ~= player then
|
||||
return err_msg(player, "You do not have permission to modify this nation.")
|
||||
end
|
||||
|
||||
@ -151,6 +153,42 @@ function towny.nations.set_nation_flags(player,flag,value)
|
||||
mark_dirty(nation)
|
||||
end
|
||||
|
||||
function towny.nations.kick_town(town,player)
|
||||
local mytown = towny.get_player_town(player)
|
||||
if not mytown then
|
||||
return err_msg(player, "You're not currently in a town!")
|
||||
end
|
||||
|
||||
local nation = towny.nations.get_town_nation(mytown)
|
||||
local ndata = towny.nations.nations[nation]
|
||||
local tdata = towny.towns[mytown]
|
||||
if not nation or not ndata then
|
||||
return err_msg(player, "Your town is currently not part of any nation!")
|
||||
end
|
||||
|
||||
if ndata.flags.capital ~= mytown or tdata.flags.mayor ~= player then
|
||||
return err_msg(player, "You do not have permission to modify this nation.")
|
||||
end
|
||||
|
||||
if not ndata.members[town] then
|
||||
return err_msg(player, "There is no such town in your nation.")
|
||||
end
|
||||
|
||||
if town == ndata.flags['capital'] then
|
||||
return err_msg(player, "You cannot kick your own town from your own nation.")
|
||||
end
|
||||
|
||||
ndata.members[town] = nil
|
||||
|
||||
minetest.chat_send_player(player, "Successfully kicked the town from the nation!")
|
||||
towny.nations.announce_to_members(nation, ("%s has been kicked from the nation."):format(towny.get_full_name(town)))
|
||||
towny.chat.announce_to_members(town, "Your town was kicked from the nation.")
|
||||
|
||||
mark_dirty(nation)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function towny.nations.get_nation_level(nation, update)
|
||||
local ndata = towny.nations.nations[nation]
|
||||
if not ndata then return nil end
|
||||
@ -174,10 +212,10 @@ end
|
||||
|
||||
function towny.nations.get_player_name(nation,player)
|
||||
local ndata = towny.nations.nations[nation]
|
||||
if not ndata then return player end
|
||||
if not ndata.level then return player end
|
||||
if not ndata then return nil end
|
||||
if not ndata.level then return nil end
|
||||
local cap = towny.towns[ndata.flags.capital]
|
||||
if not cap or not cap.members[player] then return player end
|
||||
if not cap or not cap.members[player] then return nil end
|
||||
if cap.flags.mayor ~= player then return nil end
|
||||
return ("%s %s"):format(ndata.level.king_tag, player)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user