summaryrefslogtreecommitdiffstats
path: root/src/BlockTypeRegistry.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-01-24 09:48:30 +0100
committerMattes D <github@xoft.cz>2019-08-05 21:42:54 +0200
commitf48ac9f0c3fae1e5ea04768183e07823879a7d79 (patch)
treeddb7b405100ce3486136f85ac97c409ab600b373 /src/BlockTypeRegistry.cpp
parentBlockTypeRegistry: Initial skeleton (diff)
downloadcuberite-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 'src/BlockTypeRegistry.cpp')
-rw-r--r--src/BlockTypeRegistry.cpp85
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()
+ ))
+{
+}