Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Stores information on all known block types. More...
#include <BlockTypeRegistry.h>
Classes | |
class | AlreadyRegisteredException |
The exception thrown from BlockTypeRegistry::registerBlockType() if the same block type is being registered from a different plugin. More... | |
class | NotRegisteredException |
The exception thrown from BlockTypeRegistry::setBlockTypeHint() if the block type has not been registered before. More... | |
Public Member Functions | |
std::shared_ptr< BlockInfo > | blockInfo (const AString &aBlockTypeName) |
Returns the registration information for the specified BlockTypeName. More... | |
BlockTypeRegistry ()=default | |
Creates an empty new instance of the block type registry. More... | |
void | registerBlockType (const AString &aPluginName, const AString &aBlockTypeName, std::shared_ptr< cBlockHandler > aHandler, const std::map< AString, AString > &aHints=std::map< AString, AString >(), const std::map< AString, BlockInfo::HintCallback > &aHintCallbacks=std::map< AString, BlockInfo::HintCallback >()) |
Registers the specified block type. More... | |
void | removeAllByPlugin (const AString &aPluginName) |
Removes all registrations done by the specified plugin. More... | |
void | removeBlockTypeHint (const AString &aBlockTypeName, const AString &aHintKey) |
Removes a previously registered single Hint value for a BlockType. More... | |
void | setBlockTypeHint (const AString &aBlockTypeName, const AString &aHintKey, const AString &aHintValue) |
Sets (adds or overwrites) a single Hint value for a BlockType. More... | |
Private Attributes | |
cCriticalSection | m_CSRegistry |
The CS that protects m_Registry against multithreaded access. More... | |
std::map< AString, std::shared_ptr< BlockInfo > > | m_Registry |
The actual block type registry. More... | |
Stores information on all known block types.
Can dynamically add and remove block types. Block types are identified using BlockTypeName. Supports unregistering and re-registering the same type by the same plugin. Stores the name of the plugin that registered the type, for better plugin error messages ("already registered in X") and so that we can unload and reload plugins.
Definition at line 97 of file BlockTypeRegistry.h.
|
default |
Creates an empty new instance of the block type registry.
Returns the registration information for the specified BlockTypeName.
Returns nullptr if BlockTypeName not found.
Definition at line 120 of file BlockTypeRegistry.cpp.
void BlockTypeRegistry::registerBlockType | ( | const AString & | aPluginName, |
const AString & | aBlockTypeName, | ||
std::shared_ptr< cBlockHandler > | aHandler, | ||
const std::map< AString, AString > & | aHints = std::map<AString, AString>() , |
||
const std::map< AString, BlockInfo::HintCallback > & | aHintCallbacks = std::map<AString, BlockInfo::HintCallback>() |
||
) |
Registers the specified block type.
If the block type already exists and the plugin is the same, updates the registration. If the block type already exists and the plugin is different, throws an AlreadyRegisteredException.
Definition at line 89 of file BlockTypeRegistry.cpp.
void BlockTypeRegistry::removeAllByPlugin | ( | const AString & | aPluginName | ) |
Removes all registrations done by the specified plugin.
Definition at line 135 of file BlockTypeRegistry.cpp.
void BlockTypeRegistry::removeBlockTypeHint | ( | const AString & | aBlockTypeName, |
const AString & | aHintKey | ||
) |
Removes a previously registered single Hint value for a BlockType.
Throws NotRegisteredException if the BlockTypeName is not registered. Silently ignored if the Hint hasn't been previously set.
Definition at line 174 of file BlockTypeRegistry.cpp.
void BlockTypeRegistry::setBlockTypeHint | ( | const AString & | aBlockTypeName, |
const AString & | aHintKey, | ||
const AString & | aHintValue | ||
) |
Sets (adds or overwrites) a single Hint value for a BlockType.
Throws NotRegisteredException if the BlockTypeName is not registered.
Definition at line 155 of file BlockTypeRegistry.cpp.
|
private |
The CS that protects m_Registry against multithreaded access.
Definition at line 150 of file BlockTypeRegistry.h.
The actual block type registry.
Maps the BlockTypeName to the BlockInfo instance.
Definition at line 147 of file BlockTypeRegistry.h.