summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-11-18 08:52:48 +0100
committerMattes D <github@xoft.cz>2014-11-18 08:52:48 +0100
commit9ece37e8f169f56ae670a02b9753cf12823d2df7 (patch)
tree00818f6c27413756b63be957faec29f4334a3ba4 /src
parentFixed a wrong assert in cClientHandle::SetViewDistance(). (diff)
parentUse cLuaState's stack trace. (diff)
downloadcuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar.gz
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar.bz2
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar.lz
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar.xz
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.tar.zst
cuberite-9ece37e8f169f56ae670a02b9753cf12823d2df7.zip
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/DeprecatedBindings.cpp65
-rw-r--r--src/Bindings/ManualBindings.cpp7
-rw-r--r--src/ClientHandle.cpp10
-rw-r--r--src/ClientHandle.h3
-rw-r--r--src/World.cpp12
-rw-r--r--src/World.h5
6 files changed, 83 insertions, 19 deletions
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index ded7a0142..345ab2a07 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -7,6 +7,9 @@
#include "../BlockInfo.h"
+#include "../World.h"
+#include "../Entities/Player.h"
+#include "LuaState.h"
@@ -222,6 +225,64 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
+/** function: cWorld:SetSignLines */
+static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
+{
+ cLuaState LuaState(tolua_S);
+
+ #ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype (LuaState, 1, "cWorld", 0, &tolua_err) ||
+ !tolua_isnumber (LuaState, 2, 0, &tolua_err) ||
+ !tolua_isnumber (LuaState, 3, 0, &tolua_err) ||
+ !tolua_isnumber (LuaState, 4, 0, &tolua_err) ||
+ !tolua_iscppstring(LuaState, 5, 0, &tolua_err) ||
+ !tolua_iscppstring(LuaState, 6, 0, &tolua_err) ||
+ !tolua_iscppstring(LuaState, 7, 0, &tolua_err) ||
+ !tolua_iscppstring(LuaState, 8, 0, &tolua_err) ||
+ !tolua_isusertype (LuaState, 9, "cPlayer", 1, &tolua_err) ||
+ !tolua_isnoobj (LuaState, 10, &tolua_err)
+ )
+ goto tolua_lerror;
+ else
+ #endif
+ {
+ cWorld * self = (cWorld *) tolua_tousertype (LuaState, 1, nullptr);
+ int BlockX = (int) tolua_tonumber (LuaState, 2, 0);
+ int BlockY = (int) tolua_tonumber (LuaState, 3, 0);
+ int BlockZ = (int) tolua_tonumber (LuaState, 4, 0);
+ const AString Line1 = tolua_tocppstring(LuaState, 5, 0);
+ const AString Line2 = tolua_tocppstring(LuaState, 6, 0);
+ const AString Line3 = tolua_tocppstring(LuaState, 7, 0);
+ const AString Line4 = tolua_tocppstring(LuaState, 8, 0);
+ cPlayer * Player = (cPlayer *)tolua_tousertype (LuaState, 9, nullptr);
+ #ifndef TOLUA_RELEASE
+ if (self == nullptr)
+ {
+ tolua_error(LuaState, "invalid 'self' in function 'UpdateSign'", nullptr);
+ }
+ #endif
+ {
+ bool res = self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
+ tolua_pushboolean(LuaState, res ? 1 : 0);
+ }
+ }
+ LOGWARNING("Warning in function call 'UpdateSign': UpdateSign() is deprecated. Please use SetSignLines()");
+ LuaState.LogStackTrace(0);
+ return 1;
+
+ #ifndef TOLUA_RELEASE
+tolua_lerror:
+ tolua_error(LuaState, "#ferror in function 'UpdateSign'.", &tolua_err);
+ return 0;
+ #endif
+}
+
+
+
+
+
void DeprecatedBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, nullptr);
@@ -235,6 +296,10 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, nullptr);
tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, nullptr);
+ tolua_beginmodule(tolua_S, "cWorld");
+ tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines);
+ tolua_endmodule(tolua_S);
+
tolua_endmodule(tolua_S);
}
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 3d10e2abb..750f7c65a 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1034,11 +1034,11 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
#ifndef TOLUA_RELEASE
if (self == nullptr)
{
- tolua_error(tolua_S, "invalid 'self' in function 'SetSignLines' / 'UpdateSign'", nullptr);
+ tolua_error(tolua_S, "invalid 'self' in function 'SetSignLines'", nullptr);
}
#endif
{
- bool res = self->UpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
+ bool res = self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
tolua_pushboolean(tolua_S, res ? 1 : 0);
}
}
@@ -1046,7 +1046,7 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'SetSignLines' / 'UpdateSign'.", &tolua_err);
+ tolua_error(tolua_S, "#ferror in function 'SetSignLines'.", &tolua_err);
return 0;
#endif
}
@@ -3405,7 +3405,6 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "ScheduleTask", tolua_cWorld_ScheduleTask);
tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines);
tolua_function(tolua_S, "TryGetHeight", tolua_cWorld_TryGetHeight);
- tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cMapManager");
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 8b4d6d0cc..c4ce721c3 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -94,6 +94,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_UniqueID(0),
m_HasSentPlayerChunk(false),
m_Locale("en_GB"),
+ m_LastPlacedSign(0, -1, 0),
m_ProtocolVersion(0)
{
m_Protocol = new cProtocolRecognizer(this);
@@ -1501,6 +1502,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
{
m_Player->GetInventory().RemoveOneEquippedItem();
}
+
cChunkInterface ChunkInterface(World->GetChunkMap());
NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
@@ -1678,8 +1680,11 @@ void cClientHandle::HandleUpdateSign(
const AString & a_Line3, const AString & a_Line4
)
{
- cWorld * World = m_Player->GetWorld();
- World->UpdateSign(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player);
+ if (m_LastPlacedSign.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)))
+ {
+ m_LastPlacedSign.Set(0, -1, 0);
+ m_Player->GetWorld()->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player);
+ }
}
@@ -2258,6 +2263,7 @@ void cClientHandle::SendDisconnect(const AString & a_Reason)
void cClientHandle::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
{
+ m_LastPlacedSign.Set(a_BlockX, a_BlockY, a_BlockZ);
m_Protocol->SendEditSign(a_BlockX, a_BlockY, a_BlockZ);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 8d241c1e7..f195b6be7 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -438,6 +438,9 @@ private:
/** Client Settings */
AString m_Locale;
+
+ /** The positions from the last sign that the player placed. It's needed to verify the sign text change. */
+ Vector3i m_LastPlacedSign;
/** The plugin channels that the client has registered. */
cChannels m_PluginChannels;
diff --git a/src/World.cpp b/src/World.cpp
index 288cf0154..df1a97460 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2929,25 +2929,19 @@ bool cWorld::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AStrin
AString Line2(a_Line2);
AString Line3(a_Line3);
AString Line4(a_Line4);
+
if (cRoot::Get()->GetPluginManager()->CallHookUpdatingSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player))
{
return false;
}
+
if (m_ChunkMap->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4))
{
cRoot::Get()->GetPluginManager()->CallHookUpdatedSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player);
return true;
}
- return false;
-}
-
-
-
-
-bool cWorld::UpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player)
-{
- return SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player);
+ return false;
}
diff --git a/src/World.h b/src/World.h
index 03d99c538..fe57b0789 100644
--- a/src/World.h
+++ b/src/World.h
@@ -378,11 +378,8 @@ public:
/** Marks the chunk as failed-to-load: */
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
- /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. Same as UpdateSign() */
+ /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp
-
- /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. Same as SetSignLines() */
- bool UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp
/** Sets the command block command. Returns true if command changed. */
bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export