From 0e15accada59737c415a0920e93b65a39e5aa2ae Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 19 Sep 2021 11:15:19 +0000 Subject: [PATCH 1/7] Enable fly in creative mode --- mods/MISC/mcl_privs/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index 63694ab11..5a23c00fb 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -3,3 +3,14 @@ local S = minetest.get_translator(minetest.get_current_modname()) minetest.register_privilege("maphack", { description = S("Can place and use advanced blocks like mob spawners, command blocks and barriers."), }) + +minetest.register_on_joinplayer(function(player) + local name = user:get_player_name() + local fly = false + if minetest.is_creative_enabled(name) then + fly = true + end + minetest.set_player_privs(name, { + fly = fly, + }) +end) From 18a83fa5d725c51563a2f35bf818b7c9b9041680 Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 19 Sep 2021 11:18:09 +0000 Subject: [PATCH 2/7] Fix typo --- mods/MISC/mcl_privs/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index 5a23c00fb..091ddb65e 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -5,7 +5,7 @@ minetest.register_privilege("maphack", { }) minetest.register_on_joinplayer(function(player) - local name = user:get_player_name() + local name = player:get_player_name() local fly = false if minetest.is_creative_enabled(name) then fly = true From fed43586f202cd71fe374560f90b42bef18361ec Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 19 Sep 2021 11:28:07 +0000 Subject: [PATCH 3/7] fix typo --- mods/MISC/mcl_privs/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index 091ddb65e..1d1465676 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -6,7 +6,7 @@ minetest.register_privilege("maphack", { minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - local fly = false + local fly = nil if minetest.is_creative_enabled(name) then fly = true end From f10d579d9c45bdddb7f2ae1935d74821b9c6a8b3 Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 19 Sep 2021 12:07:21 +0000 Subject: [PATCH 4/7] Only change fly priv on join if it wasn't revoked or granted --- mods/MISC/mcl_privs/init.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index 1d1465676..c63f7c5c5 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -6,6 +6,10 @@ minetest.register_privilege("maphack", { minetest.register_on_joinplayer(function(player) local name = player:get_player_name() + + local meta = player:get_meta() + if meta:get_int("fly_changed") == 1 then return end + local fly = nil if minetest.is_creative_enabled(name) then fly = true @@ -14,3 +18,13 @@ minetest.register_on_joinplayer(function(player) fly = fly, }) end) + +for _, action in pairs({ "grant", "revoke" }) do + minetest["register_on_priv_" .. action](function(name, _, priv) + if priv == "fly" then + local player = minetest.get_player_by_name(name) + local meta = player:get_meta() + meta:set_int("fly_changed", 1) + end + end) +end \ No newline at end of file From 89e90b13eb53085a801c37c639a796a0a917cac0 Mon Sep 17 00:00:00 2001 From: NO11 Date: Mon, 20 Sep 2021 14:16:59 +0000 Subject: [PATCH 5/7] Use on_newplayer --- mods/MISC/mcl_privs/init.lua | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index c63f7c5c5..302557f86 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -4,12 +4,9 @@ minetest.register_privilege("maphack", { description = S("Can place and use advanced blocks like mob spawners, command blocks and barriers."), }) -minetest.register_on_joinplayer(function(player) +minetest.register_on_newplayer(function(player) local name = player:get_player_name() - local meta = player:get_meta() - if meta:get_int("fly_changed") == 1 then return end - local fly = nil if minetest.is_creative_enabled(name) then fly = true @@ -18,13 +15,3 @@ minetest.register_on_joinplayer(function(player) fly = fly, }) end) - -for _, action in pairs({ "grant", "revoke" }) do - minetest["register_on_priv_" .. action](function(name, _, priv) - if priv == "fly" then - local player = minetest.get_player_by_name(name) - local meta = player:get_meta() - meta:set_int("fly_changed", 1) - end - end) -end \ No newline at end of file From 8697b38d60325f289eb75fd19b83e86e877946bc Mon Sep 17 00:00:00 2001 From: NO11 Date: Mon, 27 Sep 2021 20:00:11 +0000 Subject: [PATCH 6/7] Remove on_newplayer ... --- mods/MISC/mcl_privs/init.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index 302557f86..c63f7c5c5 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -4,9 +4,12 @@ minetest.register_privilege("maphack", { description = S("Can place and use advanced blocks like mob spawners, command blocks and barriers."), }) -minetest.register_on_newplayer(function(player) +minetest.register_on_joinplayer(function(player) local name = player:get_player_name() + local meta = player:get_meta() + if meta:get_int("fly_changed") == 1 then return end + local fly = nil if minetest.is_creative_enabled(name) then fly = true @@ -15,3 +18,13 @@ minetest.register_on_newplayer(function(player) fly = fly, }) end) + +for _, action in pairs({ "grant", "revoke" }) do + minetest["register_on_priv_" .. action](function(name, _, priv) + if priv == "fly" then + local player = minetest.get_player_by_name(name) + local meta = player:get_meta() + meta:set_int("fly_changed", 1) + end + end) +end \ No newline at end of file From a410d173069baf3d38f5fe5a704e4db562e5dd8a Mon Sep 17 00:00:00 2001 From: NO11 Date: Thu, 30 Sep 2021 20:14:13 +0000 Subject: [PATCH 7/7] Fix that all of new players' default_privs are removed --- mods/MISC/mcl_privs/init.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index c63f7c5c5..f06ff3582 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -6,7 +6,6 @@ minetest.register_privilege("maphack", { minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - local meta = player:get_meta() if meta:get_int("fly_changed") == 1 then return end @@ -14,12 +13,12 @@ minetest.register_on_joinplayer(function(player) if minetest.is_creative_enabled(name) then fly = true end - minetest.set_player_privs(name, { - fly = fly, - }) + local player_privs = minetest.get_player_privs(name) + player_privs.fly = fly + minetest.set_player_privs(name, player_privs) end) -for _, action in pairs({ "grant", "revoke" }) do +for _, action in pairs({"grant", "revoke"}) do minetest["register_on_priv_" .. action](function(name, _, priv) if priv == "fly" then local player = minetest.get_player_by_name(name)