Added y bounds checking for cPlayer::PlaceBlock (#5194)
This commit is contained in:
parent
179d6da490
commit
36a97d441b
@ -10879,16 +10879,8 @@ a_Player:OpenWindow(Window);
|
|||||||
Params =
|
Params =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Name = "BlockX",
|
Name = "BlockPos",
|
||||||
Type = "number",
|
Type = "Vector3i",
|
||||||
},
|
|
||||||
{
|
|
||||||
Name = "BlockY",
|
|
||||||
Type = "number",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name = "BlockZ",
|
|
||||||
Type = "number",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name = "BlockType",
|
Name = "BlockType",
|
||||||
@ -10905,7 +10897,7 @@ a_Player:OpenWindow(Window);
|
|||||||
Type = "boolean",
|
Type = "boolean",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Notes = "Places a block while impersonating the player. The {{OnPlayerPlacingBlock|HOOK_PLAYER_PLACING_BLOCK}} hook is called before the placement, and if it succeeds, the block is placed and the {{OnPlayerPlacedBlock|HOOK_PLAYER_PLACED_BLOCK}} hook is called. Returns true iff the block is successfully placed. Assumes that the block is in a currently loaded chunk.",
|
Notes = "Places a block while impersonating the player. The {{OnPlayerPlacingBlock|HOOK_PLAYER_PLACING_BLOCK}} hook is called before the placement, and if it succeeds, the block is placed and the {{OnPlayerPlacedBlock|HOOK_PLAYER_PLACED_BLOCK}} hook is called. Returns true iff the block is successfully placed.",
|
||||||
},
|
},
|
||||||
ReplaceOneEquippedItemTossRest =
|
ReplaceOneEquippedItemTossRest =
|
||||||
{
|
{
|
||||||
|
@ -1595,6 +1595,63 @@ static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int tolua_cPlayer_GetUUID(lua_State * tolua_S)
|
||||||
|
{
|
||||||
|
// Check the params:
|
||||||
|
cLuaState L(tolua_S);
|
||||||
|
if (!L.CheckParamSelf("cPlayer"))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the params:
|
||||||
|
cPlayer * Self = nullptr;
|
||||||
|
L.GetStackValue(1, Self);
|
||||||
|
|
||||||
|
// Return the UUID as a string
|
||||||
|
L.Push(Self->GetUUID().ToShortString());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int tolua_cPlayer_PlaceBlock(lua_State * tolua_S)
|
||||||
|
{
|
||||||
|
// Check the params:
|
||||||
|
cLuaState L(tolua_S);
|
||||||
|
if (
|
||||||
|
!L.CheckParamSelf("cPlayer") ||
|
||||||
|
!L.CheckParamUserType(2, "Vector3<int>") ||
|
||||||
|
!L.CheckParamNumber(3, 4) ||
|
||||||
|
!L.CheckParamEnd(5)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the params:
|
||||||
|
cPlayer * Self;
|
||||||
|
Vector3i Position;
|
||||||
|
BLOCKTYPE BlockType;
|
||||||
|
NIBBLETYPE BlockMeta;
|
||||||
|
L.GetStackValues(1, Self, Position, BlockType, BlockMeta);
|
||||||
|
|
||||||
|
if (!cChunkDef::IsValidHeight(Position.y))
|
||||||
|
{
|
||||||
|
return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'position'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result of placement:
|
||||||
|
L.Push(Self->PlaceBlock(Position, BlockType, BlockMeta));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
|
static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
|
||||||
{
|
{
|
||||||
// Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool
|
// Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool
|
||||||
@ -1623,28 +1680,6 @@ static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int tolua_cPlayer_GetUUID(lua_State * tolua_S)
|
|
||||||
{
|
|
||||||
// Check the params:
|
|
||||||
cLuaState L(tolua_S);
|
|
||||||
if (!L.CheckParamSelf("cPlayer"))
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the params:
|
|
||||||
cPlayer * Self = nullptr;
|
|
||||||
L.GetStackValue(1, Self);
|
|
||||||
|
|
||||||
// Return the UUID as a string
|
|
||||||
L.Push(Self->GetUUID().ToShortString());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class OBJTYPE,
|
class OBJTYPE,
|
||||||
void (OBJTYPE::*SetCallback)(cLuaState::cCallbackPtr && a_CallbackFn)
|
void (OBJTYPE::*SetCallback)(cLuaState::cCallbackPtr && a_CallbackFn)
|
||||||
@ -4601,8 +4636,9 @@ void cManualBindings::Bind(lua_State * tolua_S)
|
|||||||
tolua_beginmodule(tolua_S, "cPlayer");
|
tolua_beginmodule(tolua_S, "cPlayer");
|
||||||
tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
|
tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
|
||||||
tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions);
|
tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions);
|
||||||
tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
|
|
||||||
tolua_function(tolua_S, "GetUUID", tolua_cPlayer_GetUUID);
|
tolua_function(tolua_S, "GetUUID", tolua_cPlayer_GetUUID);
|
||||||
|
tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
|
||||||
|
tolua_function(tolua_S, "PlaceBlock", tolua_cPlayer_PlaceBlock);
|
||||||
tolua_endmodule(tolua_S);
|
tolua_endmodule(tolua_S);
|
||||||
|
|
||||||
tolua_beginmodule(tolua_S, "cPlugin");
|
tolua_beginmodule(tolua_S, "cPlugin");
|
||||||
|
@ -2333,15 +2333,6 @@ void cPlayer::LoadRank(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlayer::PlaceBlock(const Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
||||||
{
|
|
||||||
return PlaceBlocks({ { a_Position, a_BlockType, a_BlockMeta } });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::SendBlocksAround(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Range)
|
void cPlayer::SendBlocksAround(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Range)
|
||||||
{
|
{
|
||||||
// Collect the coords of all the blocks to send:
|
// Collect the coords of all the blocks to send:
|
||||||
@ -2457,6 +2448,15 @@ const cUUID & cPlayer::GetUUID(void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPlayer::PlaceBlock(const Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||||
|
{
|
||||||
|
return PlaceBlocks({ { a_Position, a_BlockType, a_BlockMeta } });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlayer::PlaceBlocks(const std::initializer_list<sSetBlock> a_Blocks)
|
bool cPlayer::PlaceBlocks(const std::initializer_list<sSetBlock> a_Blocks)
|
||||||
{
|
{
|
||||||
if (DoesPlacingBlocksIntersectEntity(a_Blocks))
|
if (DoesPlacingBlocksIntersectEntity(a_Blocks))
|
||||||
|
@ -548,12 +548,6 @@ public:
|
|||||||
Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */
|
Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */
|
||||||
void LoadRank(void);
|
void LoadRank(void);
|
||||||
|
|
||||||
/** Calls the block-placement hook and places the block in the world, unless refused by the hook.
|
|
||||||
If the hook prevents the placement, sends the current block at the specified coords back to the client.
|
|
||||||
Assumes that the block is in a currently loaded chunk.
|
|
||||||
Returns true if the block is successfully placed. */
|
|
||||||
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
|
||||||
|
|
||||||
/** Sends the block in the specified range around the specified coord to the client
|
/** Sends the block in the specified range around the specified coord to the client
|
||||||
as a block change packet.
|
as a block change packet.
|
||||||
The blocks in range (a_BlockX - a_Range, a_BlockX + a_Range) are sent (NY-metric). */
|
The blocks in range (a_BlockX - a_Range, a_BlockX + a_Range) are sent (NY-metric). */
|
||||||
@ -565,12 +559,13 @@ public:
|
|||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
|
/** Attempts to place the block in the world with a call to PlaceBlocks. */
|
||||||
|
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||||
|
|
||||||
/** Calls the block placement hooks and places the blocks in the world.
|
/** Calls the block placement hooks and places the blocks in the world.
|
||||||
First the "placing" hooks for all the blocks are called, then the blocks are placed, and finally
|
First the "placing" hooks for all the blocks are called, then the blocks are placed, and finally the "placed" hooks are called.
|
||||||
the "placed" hooks are called.
|
|
||||||
If the any of the "placing" hooks aborts, none of the blocks are placed and the function returns false.
|
If the any of the "placing" hooks aborts, none of the blocks are placed and the function returns false.
|
||||||
Returns true if all the blocks are placed.
|
Returns true if all the blocks are placed. */
|
||||||
Assumes that all the blocks are in currently loaded chunks. */
|
|
||||||
bool PlaceBlocks(std::initializer_list<sSetBlock> a_Blocks);
|
bool PlaceBlocks(std::initializer_list<sSetBlock> a_Blocks);
|
||||||
|
|
||||||
/** Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an entity
|
/** Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an entity
|
||||||
|
Loading…
Reference in New Issue
Block a user