From 89d3211a224f0e4bfc22de1b143641aeff4961a4 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 28 Feb 2021 18:43:31 +0100 Subject: [PATCH] Add playerlist --- mods/elidragon_playerlist/init.lua | 41 ++++++++++++++++++++++++++ mods/elidragon_playerlist/mod.conf | 4 +++ mods/elidragon_ranks/init.lua | 46 +++++++++++++++++++++++++++--- worlds/creative/world.mt | 1 + worlds/lobby/world.mt | 1 + worlds/skyblock/world.mt | 1 + worlds/survival/world.mt | 1 + 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 mods/elidragon_playerlist/init.lua create mode 100644 mods/elidragon_playerlist/mod.conf diff --git a/mods/elidragon_playerlist/init.lua b/mods/elidragon_playerlist/init.lua new file mode 100644 index 0000000..2d55ebd --- /dev/null +++ b/mods/elidragon_playerlist/init.lua @@ -0,0 +1,41 @@ +local ranks = elidragon.ranks + +local player_huds = {} + +controls.register_on_press(function(player, key) + if key == "sneak" then + local name = player:get_player_name() + local huds = {} + for i, n, _, rank, rank_def in ranks.iterate_players() do + table.insert(huds, player:hud_add({ + hud_elem_type = "text", + position = {x = 0.5, y = 0}, + offset = {x = 20, y = 53 + (i - 1) * 18}, + text = n, + alignment = {x = 1, y = 1}, + scale = {x = 100, y = 100}, + number = tonumber(rank_def.color, 16), + })) + table.insert(huds, player:hud_add({ + hud_elem_type = "image", + position = {x = 0.5, y = 0}, + offset = {x = 0, y = 50 + (i - 1) * 18}, + text = "server_ping_" .. math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4)) .. ".png", + alignment = {x = -1, y = 1}, + scale = {x = 1.5, y = 1.5}, + number = 0xFFFFFF, + })) + end + player_huds[name] = huds + end +end) + +controls.register_on_release(function(player, key) + if key == "sneak" and player then + for _, id in ipairs(player_huds[player:get_player_name()] or {}) do + player:hud_remove(id) + end + end +end) + +elidragon.playerlist = {} diff --git a/mods/elidragon_playerlist/mod.conf b/mods/elidragon_playerlist/mod.conf new file mode 100644 index 0000000..5bf4473 --- /dev/null +++ b/mods/elidragon_playerlist/mod.conf @@ -0,0 +1,4 @@ +name = elidragon_playerlist +author = Fleckenstein +description = Show a playerlist similar to minecraft when the sneak key is pressed, people with the highest ranks are shown first +depends = elidragon, elidragon_ranks, controls diff --git a/mods/elidragon_ranks/init.lua b/mods/elidragon_ranks/init.lua index a5831bd..8a97da3 100644 --- a/mods/elidragon_ranks/init.lua +++ b/mods/elidragon_ranks/init.lua @@ -23,16 +23,16 @@ function ranks.get(name) end function ranks.get_player_name(name, brackets) - local _, def = ranks.get(name) + local _, rank_def = ranks.get(name) brackets = brackets or {"", ""} - return minetest.colorize("#" .. def.color, def.tag) .. brackets[1] .. name .. brackets[2] + return minetest.colorize("#" .. rank_def.color, rank_def.tag) .. brackets[1] .. name .. brackets[2] end function ranks.reload(player) local name = player:get_player_name() - local rank, def = ranks.get(name) + local rank, rank_def = ranks.get(name) player:set_nametag_attributes({text = rank == "system" and "" or ranks.get_player_name(name)}) - minetest.set_player_privs(name, assert(def.privs)) + minetest.set_player_privs(name, assert(rank_def.privs)) end function ranks.set(name, rank) @@ -53,6 +53,34 @@ function ranks.set(name, rank) ranks.reload(player) end +function ranks.iterate_players(list) + local players = {} + for _, player in ipairs(list or minetest.get_connected_players()) do + local name = player:get_player_name() + if name ~= "rpc" then + local rank, rank_def = ranks.get(name) + table.insert(players, { + name = name, + ref = player, + rank = rank, + rank_def = rank_def, + value = rank_def.value + }) + end + end + table.sort(players, function(a, b) + return a.value > b.value + end) + local i = 0 + return function() + i = i + 1 + local player = players[i] + if player then + return i, player.name, player.ref, player.rank, player.rank_def + end + end +end + minetest.register_on_joinplayer(ranks.reload) function minetest.send_join_message(name) @@ -110,48 +138,56 @@ minetest.register_on_mods_loaded(function() color = "900A00", description = "The Developer rank is for the admins who maintain the server software.", privs = all_privs, + value = 7, }, admin = { tag = "[Admin]", color = "FF2D8D", description = "The Admin rank is for people with ssh access to the server, they have all privileges. They are members of the Elidragon group.", privs = all_privs, + value = 6, }, moderator = { tag = "[Moderator]", color = "006BFF", description = "People who moderate the server.", privs = moderator_privs, + value = 5, }, contributor = { tag = "[Contributor]", color = "9D00FF", description = "The Contributor rank is for people that contribute to the server software. It has the same privs as the MVP rank.", privs = mvp_privs, + value = 4, }, builder = { tag = "[Builder]", color = "FF9C00", description = "The Builder rank is for people that have helped constructing the buildings in the lobby etc. It has the same privs as the MVP rank.", privs = mvp_privs, + value = 3, }, mvp = { tag = "[MVP]", color = "0CDCD8", description = "The MVP rank can be purchased in out store (upcoming). It is purely cosmetic.", privs = mvp_privs, + value = 2, }, vip = { tag = "[VIP]", color = "2BEC37", description = "The VIP rank can be purchased in out store (upcoming). It is purely cosmetic.", privs = vip_privs, + value = 1, }, player = { tag = "", color = "FFFFFF", description = "This is the rank for normal players.", privs = default_privs, + value = 0, }, console = { tag = "[Console]", @@ -174,3 +210,5 @@ minetest.register_on_mods_loaded(function() }, } end) + +elidragon.ranks = ranks diff --git a/worlds/creative/world.mt b/worlds/creative/world.mt index 791ebf6..80b5d26 100644 --- a/worlds/creative/world.mt +++ b/worlds/creative/world.mt @@ -12,6 +12,7 @@ load_mod_elidragon_db = true load_mod_elidragon_grouplist = false load_mod_elidragon_luckyblock = false load_mod_elidragon_playerdb = true +load_mod_elidragon_playerlist = true load_mod_elidragon_plot = true load_mod_elidragon_plotmg = true load_mod_elidragon_random = false diff --git a/worlds/lobby/world.mt b/worlds/lobby/world.mt index 957910e..7c01342 100644 --- a/worlds/lobby/world.mt +++ b/worlds/lobby/world.mt @@ -12,6 +12,7 @@ load_mod_elidragon_db = true load_mod_elidragon_grouplist = false load_mod_elidragon_luckyblock = false load_mod_elidragon_playerdb = true +load_mod_elidragon_playerlist = true load_mod_elidragon_plot = false load_mod_elidragon_plotmg = false load_mod_elidragon_random = false diff --git a/worlds/skyblock/world.mt b/worlds/skyblock/world.mt index 1677631..a45260f 100644 --- a/worlds/skyblock/world.mt +++ b/worlds/skyblock/world.mt @@ -12,6 +12,7 @@ load_mod_elidragon_db = true load_mod_elidragon_grouplist = true load_mod_elidragon_luckyblock = true load_mod_elidragon_playerdb = true +load_mod_elidragon_playerlist = true load_mod_elidragon_plot = true load_mod_elidragon_plotmg = true load_mod_elidragon_random = false diff --git a/worlds/survival/world.mt b/worlds/survival/world.mt index 24efdc2..4ee9e64 100644 --- a/worlds/survival/world.mt +++ b/worlds/survival/world.mt @@ -12,6 +12,7 @@ load_mod_elidragon_db = true load_mod_elidragon_grouplist = false load_mod_elidragon_luckyblock = false load_mod_elidragon_playerdb = true +load_mod_elidragon_playerlist = true load_mod_elidragon_plot = false load_mod_elidragon_plotmg = false load_mod_elidragon_random = false -- 2.44.0