1
0

Prevent player from being destroyed by plugins (#4584)

* Prevent player from being destroyed by plugins

Add manual binding, bails out with error message if attempted
entity to destroy is player.

* Improve warnings and documentation, remove automatic binding

* Remove old and unnecessary deprecated function
This commit is contained in:
Alexander Harkness 2020-03-31 11:39:23 +00:00 committed by GitHub
parent b4060be3a4
commit 9210501af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 8 deletions

View File

@ -3138,12 +3138,12 @@ local Hash = cCryptoHash.sha1HexString("DataToHash")
Params =
{
{
Name = "ShouldBroadcast",
Name = "ShouldBroadcast <b>(DEPRECATED)</b>",
Type = "boolean",
IsOptional = true,
},
},
Notes = "Schedules the entity to be destroyed; if ShouldBroadcast is not present or set to true, broadcasts the DestroyEntity packet",
Notes = "Schedules the entity to be destroyed; broadcasts the DestroyEntity packet",
},
DoesPreventBlockPlacement =
{

View File

@ -4081,6 +4081,37 @@ static int tolua_cCuboid_Move(lua_State * tolua_S)
static int tolua_cEntity_Destroy(lua_State * tolua_S)
{
// Check the params:
cLuaState L(tolua_S);
if (!L.CheckParamSelf("cEntity"))
{
return 0;
}
// Get the params:
cEntity * self = nullptr;
L.GetStackValue(1, self);
if (lua_gettop(L) == 2)
{
LOGWARNING("cEntity:Destroy(bool) is deprecated, use cEntity:Destroy() instead.");
}
if (self->IsPlayer())
{
return L.ApiParamError("Cannot call cEntity:Destroy() on a cPlayer, use cClientHandle:Kick() instead.");
}
self->Destroy();
return 0;
}
static int tolua_cEntity_IsSubmerged(lua_State * tolua_S)
{
// Check the params:
@ -4256,6 +4287,7 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cEntity");
tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID);
tolua_function(tolua_S, "Destroy", tolua_cEntity_Destroy);
tolua_function(tolua_S, "IsSubmerged", tolua_cEntity_IsSubmerged);
tolua_function(tolua_S, "IsSwimming", tolua_cEntity_IsSwimming);
tolua_function(tolua_S, "GetPosition", tolua_cEntity_GetPosition);

View File

@ -289,14 +289,10 @@ public:
If this returns false, you must stop using the cEntity pointer you have. */
bool IsTicking(void) const;
// tolua_end
/** Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet */
virtual void Destroy();
OBSOLETE void Destroy(bool a_ShouldBroadcast)
{
LOGWARNING("cEntity:Destory(bool) is deprecated, use cEntity:Destroy() instead.");
Destroy();
}
// tolua_begin
/** Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called */
void TakeDamage(cEntity & a_Attacker);