mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-24 19:41:08 +01:00
Move is_fake_player to mcl_util, incorporate checks from 7e3064ef93
This commit is contained in:
parent
b5025330b9
commit
4a72b92385
5 changed files with 26 additions and 20 deletions
|
@ -1131,3 +1131,17 @@ if not vector.in_area then
|
||||||
(pos.z >= min.z) and (pos.z <= max.z)
|
(pos.z >= min.z) and (pos.z <= max.z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mcl_util.is_fake_player(player)
|
||||||
|
-- Simple checks
|
||||||
|
if not player then return true end
|
||||||
|
if player:is_player() == false then return true end
|
||||||
|
if not player.get_player_name then return true end
|
||||||
|
|
||||||
|
-- Check if the player is logged in
|
||||||
|
local objref = minetest.get_player_by_name( player:get_player_name() )
|
||||||
|
if not objref then return true end
|
||||||
|
if objref ~= player then return true end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
|
@ -6,4 +6,4 @@ license = LGPL 2.1 or later
|
||||||
forum = https://forum.minetest.net/viewtopic.php?t=4870
|
forum = https://forum.minetest.net/viewtopic.php?t=4870
|
||||||
version = 2.3.0
|
version = 2.3.0
|
||||||
optional_depends = sfinv, unified_inventory
|
optional_depends = sfinv, unified_inventory
|
||||||
depends = mcl_colors
|
depends = mcl_colors, mcl_util
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
--
|
--
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
local is_fake_player = mcl_util.is_fake_player
|
||||||
|
|
||||||
awards.register_trigger("dig", function(def)
|
awards.register_trigger("dig", function(def)
|
||||||
local tmp = {
|
local tmp = {
|
||||||
|
@ -236,7 +237,7 @@ awards.register_onCraft = awards.register_on_craft
|
||||||
|
|
||||||
-- Trigger Handles
|
-- Trigger Handles
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
if not digger or not pos or not oldnode then
|
if is_fake_player(digger) or not pos or not oldnode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_placenode(function(pos, node, digger)
|
minetest.register_on_placenode(function(pos, node, digger)
|
||||||
if not digger or not pos or not node or not digger:get_player_name() or digger:get_player_name()=="" then
|
if is_fake_player(digger) or not pos or not node or not digger:get_player_name() or digger:get_player_name()=="" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local data = awards.players[digger:get_player_name()]
|
local data = awards.players[digger:get_player_name()]
|
||||||
|
@ -286,6 +287,7 @@ minetest.register_on_placenode(function(pos, node, digger)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
|
if is_fake_player(user) then return end
|
||||||
if not user or not itemstack or not user:get_player_name() or user:get_player_name()=="" then
|
if not user or not itemstack or not user:get_player_name() or user:get_player_name()=="" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -310,7 +312,7 @@ minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack,
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||||
if not player or not itemstack then
|
if is_fake_player(player) or not itemstack then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -338,7 +340,7 @@ end)
|
||||||
minetest.register_on_dieplayer(function(player)
|
minetest.register_on_dieplayer(function(player)
|
||||||
-- Run checks
|
-- Run checks
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if not player or not name or name=="" then
|
if is_fake_player(player) or not name or name=="" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -359,8 +361,9 @@ end)
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
-- Run checks
|
-- Run checks
|
||||||
|
if is_fake_player(player) then return end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if not player or not name or name=="" then
|
if not name or name=="" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -390,6 +393,7 @@ minetest.register_on_chat_message(function(name, message)
|
||||||
awards.assertPlayer(name)
|
awards.assertPlayer(name)
|
||||||
local data = awards.players[name]
|
local data = awards.players[name]
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
|
if is_fake_player(player) then return end
|
||||||
|
|
||||||
-- Increment counter
|
-- Increment counter
|
||||||
data.chats = data.chats + 1
|
data.chats = data.chats + 1
|
||||||
|
|
|
@ -1,18 +1,6 @@
|
||||||
--local S = minetest.get_translator(minetest.get_current_modname())
|
--local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
local function is_fake_player(player)
|
local is_fake_player = mcl_util.is_fake_player
|
||||||
-- Simple checks
|
|
||||||
if not player then return true end
|
|
||||||
if player:is_player() == false then return true end
|
|
||||||
if not player.get_player_name then return true end
|
|
||||||
|
|
||||||
-- Check if the player is logged in
|
|
||||||
local objref = minetest.get_player_by_name( player:get_player_name() )
|
|
||||||
if not objref then return true end
|
|
||||||
if objref ~= player then return true end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- wrapper for minetest.item_eat (this way we make sure other mods can't break this one)
|
-- wrapper for minetest.item_eat (this way we make sure other mods can't break this one)
|
||||||
function minetest.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
function minetest.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_hunger
|
name = mcl_hunger
|
||||||
author = BlockMen
|
author = BlockMen
|
||||||
description = Adds a simple hunger meachanic with satiation, food poisoning and different healing.
|
description = Adds a simple hunger meachanic with satiation, food poisoning and different healing.
|
||||||
depends = hudbars
|
depends = hudbars, mcl_util
|
||||||
|
|
Loading…
Reference in a new issue