From cc34898e45113df8ad7ae4b58debd2fe000f9622 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 23 Feb 2014 20:02:44 +0100 Subject: [PATCH 1/2] No Sword Block Destroying in Creative Mode --- src/ClientHandle.cpp | 10 ++++++++++ src/Items/ItemSword.h | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3711262b6..38301b86f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -32,6 +32,7 @@ #include "Protocol/ProtocolRecognizer.h" #include "CompositeChat.h" +#include "Items/ItemSword.h" @@ -794,6 +795,15 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc return; } + if ( + m_Player->IsGameModeCreative() && + cItemSwordHandler::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) + ) + { + // Players can't destroy blocks with a Sword in the hand. + return; + } + if (cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta)) { // A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows: diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index a7c1d2432..07d121d5c 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,6 +23,25 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } + + inline static bool IsSword(int id) + { + switch (id) + { + case E_ITEM_WOODEN_SWORD: + case E_ITEM_STONE_SWORD: + case E_ITEM_IRON_SWORD: + case E_ITEM_GOLD_SWORD: + case E_ITEM_DIAMOND_SWORD: + { + return true; + } + default: + { + return false; + } + } + } } ; From 084971424fcc258e6958c464ada3263f5b85a870 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 23 Feb 2014 20:31:58 +0100 Subject: [PATCH 2/2] Use the ItemCategorie::IsSword() Method. --- src/ClientHandle.cpp | 2 +- src/Items/ItemSword.h | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 38301b86f..4715eb100 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -797,7 +797,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc if ( m_Player->IsGameModeCreative() && - cItemSwordHandler::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) + ItemCategory::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) ) { // Players can't destroy blocks with a Sword in the hand. diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 07d121d5c..a7c1d2432 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,25 +23,6 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } - - inline static bool IsSword(int id) - { - switch (id) - { - case E_ITEM_WOODEN_SWORD: - case E_ITEM_STONE_SWORD: - case E_ITEM_IRON_SWORD: - case E_ITEM_GOLD_SWORD: - case E_ITEM_DIAMOND_SWORD: - { - return true; - } - default: - { - return false; - } - } - } } ;