fCraft  0.638
Custom Minecraft Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events
fCraft.Config Class Reference

Static class that handles loading/saving configuration, contains config defaults, and various configuration-related utilities. More...

Static Public Member Functions

static void LoadDefaults ()
 Overwrites current settings with defaults.
 
static void LoadDefaults (ConfigSection section)
 Loads defaults for keys in a given ConfigSection.
 
static bool IsDefault (this ConfigKey key)
 Checks whether given ConfigKey still has its default value.
 
static object GetDefault (this ConfigKey key)
 Provides the default value for a given ConfigKey.
 
static void ResetLogOptions ()
 
static void Load (bool skipRankList, bool raiseReloadedEvent)
 Loads configuration from file.
 
static bool Save ()
 
static bool IsBlank (this ConfigKey key)
 Checks whether any value has been set for a given key.
 
static string GetString (this ConfigKey key)
 Returns raw value for the given key.
 
static int GetInt (this ConfigKey key)
 Attempts to parse given key's value as an integer. Throws a FormatException on failure.
 
static bool TryGetInt (this ConfigKey key, out int result)
 Attempts to parse a given key's value as an integer.
 
static TEnum GetEnum< TEnum > (this ConfigKey key)
 Attempts to parse a given key's value as an enumeration. An ArgumentException is thrown if value could not be parsed. Note the parsing is done in a case-insensitive way.
 
static bool Enabled (this ConfigKey key)
 Attempts to parse given key's value as a boolean. Throws a FormatException on failure.
 
static bool TryGetBool (this ConfigKey key, out bool result)
 Attempts to parse a given key's value as a boolean.
 
static Type GetValueType (this ConfigKey key)
 Returns the expected Type of the key's value, as specified in key metadata.
 
static ConfigKeyAttribute GetMetadata (this ConfigKey key)
 Returns the metadata container (ConfigKeyAttribute object) for a given key.
 
static ConfigSection GetSection (this ConfigKey key)
 Returns the ConfigSection that a given key is associated with.
 
static string GetDescription (this ConfigKey key)
 Returns the description text for a given config key.
 
static bool ResetValue (this ConfigKey key)
 Resets key value to its default setting.
 
static bool SetValue (this ConfigKey key, object rawValue)
 Sets value of a given config key. Note that this method may throw exceptions if the given value is not acceptable. Use Config.TrySetValue() if you'd like to suppress exceptions in favor of a boolean return value.
 
static bool TrySetValue (this ConfigKey key, object rawValue)
 Attempts to set the value of a given config key. Check the return value to make sure that the given value was acceptable.
 
static void ResetRanks ()
 Resets the list of ranks to defaults (guest/builder/op/owner). Warning: This method is not thread-safe, and should never be used on a live server.
 
static ConfigKey[] GetKeys (this ConfigSection section)
 Returns a list of all keys in a section.
 

Public Attributes

const int ProtocolVersion = 7
 Supported version of the Minecraft classic protocol.
 
const int CurrentVersion = 164
 Latest version of config.xml available at the time of building this copy of fCraft. Config.xml files saved with this build will have this version number embedded.
 

Events

static EventHandler Reloaded
 Occurs after the entire configuration has been reloaded from file.
 
static EventHandler
< ConfigKeyChangingEventArgs
KeyChanging
 Occurs when a config key is about to be changed (cancelable). The new value may be replaced by the callback.
 
static EventHandler
< ConfigKeyChangedEventArgs
KeyChanged
 Occurs after a config key has been changed.
 

Detailed Description

Static class that handles loading/saving configuration, contains config defaults, and various configuration-related utilities.

Member Function Documentation

static bool fCraft.Config.Enabled ( this ConfigKey  key)
static

Attempts to parse given key's value as a boolean. Throws a FormatException on failure.

static object fCraft.Config.GetDefault ( this ConfigKey  key)
static

Provides the default value for a given ConfigKey.

static string fCraft.Config.GetDescription ( this ConfigKey  key)
static

Returns the description text for a given config key.

static TEnum fCraft.Config.GetEnum< TEnum > ( this ConfigKey  key)
static

Attempts to parse a given key's value as an enumeration. An ArgumentException is thrown if value could not be parsed. Note the parsing is done in a case-insensitive way.

Template Parameters
TEnumEnum to use for parsing. An ArgumentException will be thrown if this is not an enum.
Exceptions
ArgumentExceptionTEnum is not an System.Enum. -or- key value is either an empty string ("") or only contains white space. -or- value is a name, but not one of the named constants defined for the enumeration.
Type Constraints
TEnum :struct 
static int fCraft.Config.GetInt ( this ConfigKey  key)
static

Attempts to parse given key's value as an integer. Throws a FormatException on failure.

static ConfigKey [] fCraft.Config.GetKeys ( this ConfigSection  section)
static

Returns a list of all keys in a section.

static ConfigKeyAttribute fCraft.Config.GetMetadata ( this ConfigKey  key)
static

Returns the metadata container (ConfigKeyAttribute object) for a given key.

static ConfigSection fCraft.Config.GetSection ( this ConfigKey  key)
static

Returns the ConfigSection that a given key is associated with.

static string fCraft.Config.GetString ( this ConfigKey  key)
static

Returns raw value for the given key.

static Type fCraft.Config.GetValueType ( this ConfigKey  key)
static

Returns the expected Type of the key's value, as specified in key metadata.

static bool fCraft.Config.IsBlank ( this ConfigKey  key)
static

Checks whether any value has been set for a given key.

static bool fCraft.Config.IsDefault ( this ConfigKey  key)
static

Checks whether given ConfigKey still has its default value.

static void fCraft.Config.Load ( bool  skipRankList,
bool  raiseReloadedEvent 
)
static

Loads configuration from file.

Parameters
skipRankListIf true, skips over rank definitions.
raiseReloadedEventWhether ConfigReloaded event should be raised.
static void fCraft.Config.LoadDefaults ( )
static

Overwrites current settings with defaults.

static void fCraft.Config.LoadDefaults ( ConfigSection  section)
static

Loads defaults for keys in a given ConfigSection.

static void fCraft.Config.ResetLogOptions ( )
static
static void fCraft.Config.ResetRanks ( )
static

Resets the list of ranks to defaults (guest/builder/op/owner). Warning: This method is not thread-safe, and should never be used on a live server.

static bool fCraft.Config.ResetValue ( this ConfigKey  key)
static

Resets key value to its default setting.

Parameters
keyConfig key to reset.
Returns
True if value was reset. False if resetting was cancelled by an event handler/plugin.
static bool fCraft.Config.Save ( )
static
static bool fCraft.Config.SetValue ( this ConfigKey  key,
object  rawValue 
)
static

Sets value of a given config key. Note that this method may throw exceptions if the given value is not acceptable. Use Config.TrySetValue() if you'd like to suppress exceptions in favor of a boolean return value.

Parameters
keyConfig key to set.
rawValueValue to assign to the key. If passed object is not a string, rawValue.ToString() is used.
Exceptions
ArgumentNullExceptionrawValue is null.
NullReferenceExceptionrawValue.ToString() is null.
FormatExceptionGiven value did not satisfy key's requirements.
Returns
True if value is valid and has been assigned. False if value is valid, but assignment was cancelled by an event handler/plugin.
static bool fCraft.Config.TryGetBool ( this ConfigKey  key,
out bool  result 
)
static

Attempts to parse a given key's value as a boolean.

Parameters
keyConfigKey to get value from.
resultWill be set to the value on success, or to false on failure.
Returns
Whether parsing succeeded.
static bool fCraft.Config.TryGetInt ( this ConfigKey  key,
out int  result 
)
static

Attempts to parse a given key's value as an integer.

Parameters
keyConfigKey to get value from.
resultWill be set to the value on success, or to 0 on failure.
Returns
Whether parsing succeeded.
static bool fCraft.Config.TrySetValue ( this ConfigKey  key,
object  rawValue 
)
static

Attempts to set the value of a given config key. Check the return value to make sure that the given value was acceptable.

Parameters
keyConfig key to set.
rawValueValue to assign to the key. If passed object is not a string, rawValue.ToString() is used.
Exceptions
T:System.ArgumentNullException
Returns
True if value is valid and has been assigned. False if value was invalid, or if assignment was cancelled by an event handler/plugin.

Member Data Documentation

const int fCraft.Config.CurrentVersion = 164

Latest version of config.xml available at the time of building this copy of fCraft. Config.xml files saved with this build will have this version number embedded.

const int fCraft.Config.ProtocolVersion = 7

Supported version of the Minecraft classic protocol.

Event Documentation

EventHandler<ConfigKeyChangedEventArgs> fCraft.Config.KeyChanged
static

Occurs after a config key has been changed.

EventHandler<ConfigKeyChangingEventArgs> fCraft.Config.KeyChanging
static

Occurs when a config key is about to be changed (cancelable). The new value may be replaced by the callback.

EventHandler fCraft.Config.Reloaded
static

Occurs after the entire configuration has been reloaded from file.


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