From 30f788b52aa3b8438bfc927f945e60403c8f4248 Mon Sep 17 00:00:00 2001 From: octacian Date: Thu, 29 Jun 2017 20:11:00 -0700 Subject: [PATCH] Add chat3 compatibility --- API.md | 32 +++++++++++++++++++------------- README.md | 2 +- depends.txt | 1 + init.lua | 38 ++++++++++++++++++++++++-------------- 4 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 depends.txt diff --git a/API.md b/API.md index 6651f78..58d5467 100644 --- a/API.md +++ b/API.md @@ -53,20 +53,26 @@ The ranks API allows you to register, unregister, and manage ranks. * Removes all ranking information from a player * `player`: PlayerRef or string +`ranks.chat_send(name, message)` + +* Simulates a chat message being sent to all players from a ranked player +* `name`: Sender player name +* `message`: Message to send + #### Rank definition ```lua { - prefix = "Moderator", -- Prefix to be shown on nametag and chat - colour = {a = 255, r = 255, g = 83, b = 37}, -- A table of RGBA values or a single base colour (e.g. "red") - strict_privs = false, -- Whether the rank should have a strict set of privileges (prevents privileges from being granted/revoked) - grant_missing = true, -- Whether missing privileges should be automatically granted - revoke_extra = false, -- Whether extra privileges should be automatically revoked - privs = { -- Default privileges (usage modified by above items) - interact = true, - shout = true, - fly = true, - fast = true, - ... - } + prefix = "Moderator", -- Prefix to be shown on nametag and chat + colour = {a = 255, r = 255, g = 83, b = 37}, -- A table of RGBA values, a single base colour (e.g. "red"), or a hex string + strict_privs = false, -- Whether the rank should have a strict set of privileges (prevents privileges from being granted/revoked) + grant_missing = true, -- Whether missing privileges should be automatically granted + revoke_extra = false, -- Whether extra privileges should be automatically revoked + privs = { -- Default privileges (usage modified by above items) + interact = true, + shout = true, + fly = true, + fast = true, + ... + } } -``` \ No newline at end of file +``` diff --git a/README.md b/README.md index 88ebe97..e34145e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Ranks is an advanced ranks mod geared towards larger servers helps to both disti This mod was made in an effort to solve two problems. One of these is new players getting confused when they see moderators or administrators doing things that normal players cannot, resulting in repeated accusations of hacking. Ranks allows there to be no confusion between what a player should or should not be able to do, as their rank is displayed in both their nametag and as a prefix to chat messages sent by them. -Displaying the rank prefix on a player's nametag can be disabled by setting `ranks.prefix_nametag = false` in `minetest.conf`, while prefixes before chat messages can be disabled with `ranks.prefix_chat = false`. +Displaying the rank prefix on a player's nametag can be disabled by setting `ranks.prefix_nametag = false` in `minetest.conf`, while prefixes before chat messages can be disabled with `ranks.prefix_chat = false`. Ranks message prefixes are also supported even when used alongside my other chat-related mods, for example, [chat3](https://forum.minetest.net/viewtopic.php?t=17163). Ranks also attempts to make privilege updates easier by allowing you to assign a set of privileges to each rank allowing a strict set of privileges for that rank, automatically granting missing privileges, and automatically revoking extra privileges (configurable per-rank). This means that when a player is given a rank with privilege definitions, they will automatically inherit the privileges specified. Whenever `/grant`, `/grantme`, or `/revoke` is called on a player, their privileges are updated according to rank and a warning is sent to the player who called the chatcommand if privileges are modified further. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..e0d343b --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +chat3? diff --git a/init.lua b/init.lua index 19487f6..63a26c2 100644 --- a/init.lua +++ b/init.lua @@ -2,7 +2,8 @@ ranks = {} -local registered = {} +local chat3_exists = minetest.get_modpath("chat3") +local registered = {} local default --- @@ -214,6 +215,27 @@ function ranks.remove_rank(player) end end +-- [function] Send prefixed message (if enabled) +function ranks.chat_send(name, message) + if minetest.settings:get("ranks.prefix_chat") ~= "false" then + local rank = ranks.get_rank(name) + if rank then + local def = ranks.get_def(rank) + if def.prefix then + local colour = get_colour(def.colour) + local prefix = minetest.colorize(colour, def.prefix) + if chat3_exists then + chat3.send(name, message, prefix.." ", "ranks") + else + minetest.chat_send_all(prefix.." <"..name.."> "..message) + minetest.log("action", "CHAT: ".."<"..name.."> "..message) + end + return true + end + end + end +end + --- --- Registrations --- @@ -240,19 +262,7 @@ end) -- Prefix messages if enabled minetest.register_on_chat_message(function(name, message) - if minetest.settings:get("ranks.prefix_chat") ~= "false" then - local rank = ranks.get_rank(name) - if rank then - local def = ranks.get_def(rank) - if def.prefix then - local colour = get_colour(def.colour) - minetest.chat_send_all(minetest.colorize(colour, def.prefix).. - " <"..name.."> "..message) - minetest.log("action", "CHAT: ".."<"..name.."> "..message) - return true - end - end - end + return ranks.chat_send(name, message) end) -- [chatcommand] /rank