Add MC|ItemName plugin message.
This commit is contained in:
parent
3c102870f6
commit
6ac332cd06
@ -633,6 +633,10 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString
|
|||||||
// Client <-> Server branding exchange
|
// Client <-> Server branding exchange
|
||||||
SendPluginMessage("MC|Brand", "MCServer");
|
SendPluginMessage("MC|Brand", "MCServer");
|
||||||
}
|
}
|
||||||
|
else if (a_Channel == "MC|ItemName")
|
||||||
|
{
|
||||||
|
HandleAnvilItemName(a_Message.c_str(), a_Message.size());
|
||||||
|
}
|
||||||
else if (a_Channel == "REGISTER")
|
else if (a_Channel == "REGISTER")
|
||||||
{
|
{
|
||||||
if (HasPluginChannel(a_Channel))
|
if (HasPluginChannel(a_Channel))
|
||||||
@ -774,6 +778,34 @@ void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Leng
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cClientHandle::HandleAnvilItemName(const char * a_Data, unsigned int a_Length)
|
||||||
|
{
|
||||||
|
if (a_Length < 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m_Player->GetWindow() == NULL) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cByteBuffer Buffer(a_Length);
|
||||||
|
Buffer.Write(a_Data, a_Length);
|
||||||
|
|
||||||
|
AString Name;
|
||||||
|
Buffer.ReadAll(Name);
|
||||||
|
|
||||||
|
if (Name.length() <= 30)
|
||||||
|
{
|
||||||
|
((cAnvilWindow&)*m_Player->GetWindow()).SetRepairedItemName(Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status)
|
void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status)
|
||||||
{
|
{
|
||||||
LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i",
|
LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i",
|
||||||
|
@ -386,6 +386,9 @@ private:
|
|||||||
/** Handles the "MC|AdvCdm" plugin message */
|
/** Handles the "MC|AdvCdm" plugin message */
|
||||||
void HandleCommandBlockMessage(const char * a_Data, size_t a_Length);
|
void HandleCommandBlockMessage(const char * a_Data, size_t a_Length);
|
||||||
|
|
||||||
|
/** Handles the "MC|ItemName" plugin message */
|
||||||
|
void HandleAnvilItemName(const char * a_Data, size_t a_Length);
|
||||||
|
|
||||||
// cSocketThreads::cCallback overrides:
|
// cSocketThreads::cCallback overrides:
|
||||||
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
|
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
|
||||||
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
||||||
|
@ -600,8 +600,7 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player)
|
|||||||
|
|
||||||
cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) :
|
cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) :
|
||||||
cSlotAreaTemporary(3, a_ParentWindow),
|
cSlotAreaTemporary(3, a_ParentWindow),
|
||||||
m_MaximumCost(0),
|
m_MaximumCost(0)
|
||||||
m_RepairedItemName("")
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,7 +704,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int NameChangeExp = 0;
|
int NameChangeExp = 0;
|
||||||
if (m_RepairedItemName.empty())
|
const AString & RepairedItemName = ((cAnvilWindow*)&m_ParentWindow)->GetRepairedItemName();
|
||||||
|
if (RepairedItemName.empty())
|
||||||
{
|
{
|
||||||
// Remove custom name
|
// Remove custom name
|
||||||
if (!Input.m_CustomName.empty())
|
if (!Input.m_CustomName.empty())
|
||||||
@ -715,7 +715,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
Input.m_CustomName = "";
|
Input.m_CustomName = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_RepairedItemName != Input.m_CustomName)
|
else if (RepairedItemName != Input.m_CustomName)
|
||||||
{
|
{
|
||||||
// Change custom name
|
// Change custom name
|
||||||
NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5);
|
NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5);
|
||||||
@ -726,7 +726,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
RepairCost += NameChangeExp / 2;
|
RepairCost += NameChangeExp / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Input.m_CustomName = m_RepairedItemName;
|
Input.m_CustomName = RepairedItemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add enchantment exp cost.
|
// TODO: Add enchantment exp cost.
|
||||||
|
@ -280,8 +280,6 @@ protected:
|
|||||||
|
|
||||||
/** The maximum cost of repairing/renaming in the anvil. */
|
/** The maximum cost of repairing/renaming in the anvil. */
|
||||||
int m_MaximumCost;
|
int m_MaximumCost;
|
||||||
|
|
||||||
AString m_RepairedItemName;
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -808,7 +808,8 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
|||||||
// cAnvilWindow:
|
// cAnvilWindow:
|
||||||
|
|
||||||
cAnvilWindow::cAnvilWindow() :
|
cAnvilWindow::cAnvilWindow() :
|
||||||
cWindow(wtAnvil, "Repair")
|
cWindow(wtAnvil, "Repair"),
|
||||||
|
m_RepairedItemName("")
|
||||||
{
|
{
|
||||||
m_SlotAreas.push_back(new cSlotAreaAnvil(*this));
|
m_SlotAreas.push_back(new cSlotAreaAnvil(*this));
|
||||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||||
|
@ -237,6 +237,15 @@ class cAnvilWindow :
|
|||||||
typedef cWindow super;
|
typedef cWindow super;
|
||||||
public:
|
public:
|
||||||
cAnvilWindow();
|
cAnvilWindow();
|
||||||
|
|
||||||
|
/** Gets the repaired item name. */
|
||||||
|
AString GetRepairedItemName(void) const { return m_RepairedItemName; }
|
||||||
|
|
||||||
|
/** Set the repaired item name. */
|
||||||
|
void SetRepairedItemName(const AString & a_Name) { m_RepairedItemName = a_Name; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AString m_RepairedItemName;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user