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 mCSRegistry
 The CS that protects mRegistry against multithreaded access. More...
 
std::map< AString, std::shared_ptr< BlockInfo > > mRegistry
 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 96 of file BlockTypeRegistry.h.

Constructor & Destructor Documentation

BlockTypeRegistry::BlockTypeRegistry ( )
default

Creates an empty new instance of the block type registry.

Member Function Documentation

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 118 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<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.

void BlockTypeRegistry::removeAllByPlugin ( const AString aPluginName)

Removes all registrations done by the specified plugin.

Definition at line 133 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 172 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 153 of file BlockTypeRegistry.cpp.

Member Data Documentation

cCriticalSection BlockTypeRegistry::mCSRegistry
private

The CS that protects mRegistry against multithreaded access.

Definition at line 149 of file BlockTypeRegistry.h.

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

The actual block type registry.

Maps the BlockTypeName to the BlockInfo instance.

Definition at line 146 of file BlockTypeRegistry.h.


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