Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Private Attributes | List of all members
BlockTypeRegistry Class Reference

Stores information on all known block types. More...

#include <BlockTypeRegistry.h>

Collaboration diagram for BlockTypeRegistry:
Collaboration graph
[legend]

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< BlockInfoblockInfo (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ BlockTypeRegistry()

BlockTypeRegistry::BlockTypeRegistry ( )
default

Creates an empty new instance of the block type registry.

Member Function Documentation

◆ blockInfo()

std::shared_ptr< BlockInfo > BlockTypeRegistry::blockInfo ( const AString aBlockTypeName)

Returns the registration information for the specified BlockTypeName.

Returns nullptr if BlockTypeName not found.

Definition at line 120 of file BlockTypeRegistry.cpp.

◆ registerBlockType()

void BlockTypeRegistry::registerBlockType ( const AString aPluginName,
const AString aBlockTypeName,
std::shared_ptr< cBlockHandler aHandler,
const std::map< AString, AString > &  aHints = std::map<AStringAString>(),
const std::map< AString, BlockInfo::HintCallback > &  aHintCallbacks = std::map<AStringBlockInfo::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.

◆ removeAllByPlugin()

void BlockTypeRegistry::removeAllByPlugin ( const AString aPluginName)

Removes all registrations done by the specified plugin.

Definition at line 135 of file BlockTypeRegistry.cpp.

◆ removeBlockTypeHint()

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.

◆ setBlockTypeHint()

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.

Member Data Documentation

◆ m_CSRegistry

cCriticalSection BlockTypeRegistry::m_CSRegistry
private

The CS that protects m_Registry against multithreaded access.

Definition at line 150 of file BlockTypeRegistry.h.

◆ m_Registry

std::map<AString, std::shared_ptr<BlockInfo> > BlockTypeRegistry::m_Registry
private

The actual block type registry.

Maps the BlockTypeName to the BlockInfo instance.

Definition at line 147 of file BlockTypeRegistry.h.


The documentation for this class was generated from the following files: