diff options
author | Mattes D <github@xoft.cz> | 2019-01-24 09:48:30 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-08-05 21:42:54 +0200 |
commit | f48ac9f0c3fae1e5ea04768183e07823879a7d79 (patch) | |
tree | ddb7b405100ce3486136f85ac97c409ab600b373 /src/BlockTypeRegistry.cpp | |
parent | BlockTypeRegistry: Initial skeleton (diff) | |
download | cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.gz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.bz2 cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.lz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.xz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.zst cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockTypeRegistry.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/BlockTypeRegistry.cpp b/src/BlockTypeRegistry.cpp index 45ad20082..cc6945e27 100644 --- a/src/BlockTypeRegistry.cpp +++ b/src/BlockTypeRegistry.cpp @@ -56,6 +56,33 @@ AString BlockInfo::hintValue( +void BlockInfo::setHint(const AString & aHintKey, const AString & aHintValue) +{ + mHints[aHintKey] = aHintValue; + + // Warn if the hint is already provided by a callback (aHintValue will be ignored when evaluating the hint): + auto itrC = mHintCallbacks.find(aHintKey); + if (itrC != mHintCallbacks.end()) + { + LOGINFO("Setting a static hint %s for block type %s, but there's already a callback for that hint. The static hint will be ignored.", + aHintKey.c_str(), mBlockTypeName.c_str() + ); + } +} + + + + + +void BlockInfo::removeHint(const AString & aHintKey) +{ + mHints.erase(aHintKey); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // BlockTypeRegistry: @@ -123,6 +150,43 @@ void BlockTypeRegistry::removeAllByPlugin(const AString & aPluginName) +void BlockTypeRegistry::setBlockTypeHint( + const AString & aBlockTypeName, + const AString & aHintKey, + const AString & aHintValue +) +{ + cCSLock lock(mCSRegistry); + auto blockInfo = mRegistry.find(aBlockTypeName); + if (blockInfo == mRegistry.end()) + { + throw NotRegisteredException(aBlockTypeName, aHintKey, aHintValue); + } + blockInfo->second->setHint(aHintKey, aHintValue); +} + + + + + +void BlockTypeRegistry::removeBlockTypeHint( + const AString & aBlockTypeName, + const AString & aHintKey +) +{ + cCSLock lock(mCSRegistry); + auto blockInfo = mRegistry.find(aBlockTypeName); + if (blockInfo == mRegistry.end()) + { + return; + } + blockInfo->second->removeHint(aHintKey); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // BlockTypeRegistry::AlreadyRegisteredException: @@ -151,3 +215,24 @@ AString BlockTypeRegistry::AlreadyRegisteredException::message( aPreviousRegistration->pluginName().c_str() ); } + + + + + +//////////////////////////////////////////////////////////////////////////////// +// BlockTypeRegistry::NotRegisteredException: + +BlockTypeRegistry::NotRegisteredException::NotRegisteredException( + const AString & aBlockTypeName, + const AString & aHintKey, + const AString & aHintValue +): + Super(Printf( + "Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s", + aBlockTypeName.c_str(), + aHintKey.c_str(), + aHintValue.c_str() + )) +{ +} |