From fd8680b3f6298566fed7e7a92ccbff26b62c918b Mon Sep 17 00:00:00 2001 From: Supergoat666 <47240900+Supergoat666@users.noreply.github.com> Date: Thu, 20 Aug 2020 03:06:02 +0200 Subject: [PATCH] Change the way to configure : now using minetest.conf --- .gitignore | 1 + README.md | 4 ++-- init.lua | 15 ++++++++++----- settings.txt | 2 -- settingtypes.txt | 2 ++ 5 files changed, 15 insertions(+), 9 deletions(-) delete mode 100644 settings.txt create mode 100644 settingtypes.txt diff --git a/.gitignore b/.gitignore index 6812db9..5689bc2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ !*.md !mod.conf !.gitignore +!settingtypes.txt diff --git a/README.md b/README.md index 1a0f163..17744a7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A simple mod which allows player created factions. Not very useful on its own, i ## Usage We can choose a mode : single or multi factions. -By default players can only be in one faction at a time. If you want to allow players to join multiple factions at once, add `mode_unique_faction = false` to modpath/settings.txt +By default players can only be in one faction at a time. If you want to allow players to join multiple factions at once, add `player_factions.mode_unique_faction = false` to minetest.conf Parameters marked with square brackets ([]) are optional; most of these are only used if mode_unique_faction is false. @@ -15,7 +15,7 @@ These commands can be used by anyone: - `/factions create `: Create a new faction - `/factions list`: List available factions -- `/factions info `: See information on a faction. For faction with lot of member we can choose the length of the member's list that's going to be shown by `adding max_members_list = int` to modpath/settings.txt, default is 50. +- `/factions info `: See information on a faction. For faction with lot of member we can choose the length of the member's list that's going to be shown by adding `player_factions.max_members_list = int` to minetest.conf, default is 50. - `/factions join `: Join an existing faction - `/factions leave [faction]`: Leave your faction diff --git a/init.lua b/init.lua index a2a52a2..5e1d461 100644 --- a/init.lua +++ b/init.lua @@ -20,9 +20,8 @@ for fname, fact in pairs(facts) do end end -settings = Settings(MP.."/settings.txt") -factions.mode_unique_faction = settings:get_bool("mode_unique_faction", true) -factions.max_members_list = tonumber(settings:get("max_members_list")) or 50 +factions.mode_unique_faction = minetest.settings:get_bool("player_factions.mode_unique_faction", true) +factions.max_members_list = tonumber(minetest.settings:get("player_factions.max_members_list")) or 50 @@ -46,6 +45,7 @@ function factions.get_player_faction(name) if not minetest.player_exists(name) then return false end + minetest.log("warning", "Function factions.get_player_faction() is deprecated in favor of factions.get_player_factions(). Please check updates of mods depending on playerfactions.") for fname, fact in pairs(facts) do if fact.members[name] then return fname @@ -223,8 +223,13 @@ local function handle_command(name, param) elseif action == "info" then local faction_name = params[2] if faction_name == nil then - faction_name = factions.get_player_faction(name) - minetest.chat_send_player(name, S("No faction were given, returning information about your oldest faction (e.g. the oldest created faction you are in)")) + local player_factions = factions.get_player_factions(name) + if #player_factions == 1 then + faction_name = player_factions[1] + else + minetest.chat_send_player(name, S("You are in many factions, you have to choose one of them : @1", table.concat(player_factions, ", "))) + return false + end elseif facts[faction_name] == nil then minetest.chat_send_player(name, S("This faction is not registered")) else diff --git a/settings.txt b/settings.txt deleted file mode 100644 index b0ee1c0..0000000 --- a/settings.txt +++ /dev/null @@ -1,2 +0,0 @@ -mode_unique_faction = false -max_members_list = 50 diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..6e18669 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,2 @@ +player_factions.mode_unique_faction (Enable faction mode) bool true +player_factions.max_members_list (The max number of members shown with info command) int 50