Package com.smartfoxserver.extensions
Class BaseSFSExtension
java.lang.Object
com.smartfoxserver.extensions.BaseSFSExtension
- All Implemented Interfaces:
ISFSEventListener,ISFSExtension
- Direct Known Subclasses:
SFSExtension
SFSExtension's base class.
Use
Use
SFSExtension instead-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(SFSEventType eventType, ISFSEventListener listener) Allows to add a listener for a specific server event.getApi()Get a reference to the main SmartFoxServer Server API, which exposes useful methods for interacting with the serverGet a reference to the SmartFoxServer Buddy API, exposing useful methods for working with BuddyListsReturns a reference the Properties object loaded from the specified properties file.Return the relative path to the current extension folder
Typically this will return: extensions/{name-of-extension}/
The path is relative to the Server root folder and it can be used to load external data files that are stored together with the extension jar file(s)Get the extension file nameGet a reference to the SmartFoxServer Game API, exposing useful methods for working with SFSGame classes, invitations and match making.com.smartfoxserver.extensions.ExtensionLevelgetLevel()Return the level of the extension.org.slf4j.LoggerObtain a direct reference to the Extension's loggerGet a reference to the SmartFoxServer MMO API, exposing useful methods for working with MMORoom(s) and MMOItem(s) objects.getName()The extension nameReturn the parent Room of the Extension.Return the parent Zone of the Extension.Get the name of the properties file that was loaded at init time.getSFS()Get a reference to the Server's main objectcom.smartfoxserver.extensions.ExtensionTypegetType()handleInternalMessage(String cmdName, Object params) This method can be invoked across different Extensions.voidhandleServerEvent(ISFSEvent event) Handle server eventbooleanisActive()Checks if the Extension is active.voidremoveEventListener(SFSEventType eventType, ISFSEventListener listener) Remove an event listenerprotected voidremoveEventsForListener(ISFSEventListener listener) voidsend(String cmdName, ISFSObject params, User recipient) voidsend(String cmdName, ISFSObject params, User recipient, TransportType txType) Send an extension message/response to a single Uservoidsend(String cmdName, ISFSObject params, List<User> recipients) voidsend(String cmdName, ISFSObject params, List<User> recipients, TransportType txType) Send an extension message/response to a list of recipientsvoidsetActive(boolean flag) voidsetExtensionFileName(String fileName) voidsetLevel(com.smartfoxserver.extensions.ExtensionLevel level) voidvoidsetParentRoom(Room room) voidsetParentZone(Zone zone) voidsetPropertiesFileName(String fileName) voidvoidsetType(com.smartfoxserver.extensions.ExtensionType type) toString()voidtrace(ExtensionLogLevel level, Object... args) Trace a message to the console and log files using the specified logging levelvoidTraces a message to the console and log files using the Logger INFO levelMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.smartfoxserver.extensions.ISFSExtension
destroy, handleClientRequest, init
-
Field Details
-
log
protected final org.slf4j.Logger log -
sfsApi
A reference to the SmartFoxServer API main object- See Also:
-
-
Constructor Details
-
BaseSFSExtension
public BaseSFSExtension()
-
-
Method Details
-
getCurrentFolder
Return the relative path to the current extension folder
Typically this will return: extensions/{name-of-extension}/
The path is relative to the Server root folder and it can be used to load external data files that are stored together with the extension jar file(s)- Returns:
- the relative path to the current extension folder
-
getName
The extension name- Specified by:
getNamein interfaceISFSExtension- Returns:
- the extension name
-
setName
- Specified by:
setNamein interfaceISFSExtension
-
getExtensionFileName
Get the extension file name- Specified by:
getExtensionFileNamein interfaceISFSExtension- Returns:
- the Extension file name
-
getConfigProperties
Returns a reference the Properties object loaded from the specified properties file.By default SmartFox will attempt to load a file called config.properties located in the Extension folder. Example: if your extension name is ChessGame the system will try to load extensions/ChessGame/config.properties
No errors will be logged if the file is not found unless you have specified a custom properties file. In this case a warning will be logged if the file cannot be loaded.
If the file is not found the method will return null
- Specified by:
getConfigPropertiesin interfaceISFSExtension- Returns:
- the custom properties
-
getPropertiesFileName
Get the name of the properties file that was loaded at init time.- Specified by:
getPropertiesFileNamein interfaceISFSExtension- Returns:
- the name of the configuration properties file
-
setPropertiesFileName
- Specified by:
setPropertiesFileNamein interfaceISFSExtension- Throws:
IOException
-
getSFS
Get a reference to the Server's main object- Returns:
- a reference to the main server's instance singleton
-
getApi
Get a reference to the main SmartFoxServer Server API, which exposes useful methods for interacting with the server- Returns:
- the API object
- See Also:
-
getBuddyApi
Get a reference to the SmartFoxServer Buddy API, exposing useful methods for working with BuddyLists- Returns:
- the API object
- See Also:
-
getGameApi
Get a reference to the SmartFoxServer Game API, exposing useful methods for working with SFSGame classes, invitations and match making.- Returns:
- the API object
- See Also:
-
getMMOApi
Get a reference to the SmartFoxServer MMO API, exposing useful methods for working with MMORoom(s) and MMOItem(s) objects.- Returns:
- the API object
- See Also:
-
handleServerEvent
Handle server event- Specified by:
handleServerEventin interfaceISFSEventListener- Parameters:
event- the Event- Throws:
Exception- See Also:
-
handleInternalMessage
This method can be invoked across different Extensions. It can be used as a mean of inter-operability between multiple Extensions- Specified by:
handleInternalMessagein interfaceISFSExtension- Parameters:
cmdName- a command nameparams- custom parameters
-
setExtensionFileName
- Specified by:
setExtensionFileNamein interfaceISFSExtension
-
getParentRoom
Return the parent Room of the Extension. (valid only for Room-level extensions)- Specified by:
getParentRoomin interfaceISFSExtension- Returns:
- the Room or null if this is not a Room-level extension
-
setParentRoom
- Specified by:
setParentRoomin interfaceISFSExtension
-
getParentZone
Return the parent Zone of the Extension.- Specified by:
getParentZonein interfaceISFSExtension- Returns:
- the Zone of the Extension
-
setParentZone
- Specified by:
setParentZonein interfaceISFSExtension
-
addEventListener
Allows to add a listener for a specific server event.- Specified by:
addEventListenerin interfaceISFSExtension- Parameters:
eventType- the type of event to listen forlistener- the event handler- See Also:
-
removeEventListener
Remove an event listener- Specified by:
removeEventListenerin interfaceISFSExtension- Parameters:
eventType- the type of eventlistener- the event handler- See Also:
-
isActive
public boolean isActive()Checks if the Extension is active. If not the Extension is not going to respond to any events and/or requests.- Specified by:
isActivein interfaceISFSExtension- Returns:
- true if the Extension is active.
-
setActive
public void setActive(boolean flag) - Specified by:
setActivein interfaceISFSExtension
-
getLevel
public com.smartfoxserver.extensions.ExtensionLevel getLevel()Return the level of the extension. There are only 2 levels:- Room: the extension is attached to a Room
- Zone: the extension is attached to a Zone
- Specified by:
getLevelin interfaceISFSExtension- Returns:
- the extension Level
-
setLevel
public void setLevel(com.smartfoxserver.extensions.ExtensionLevel level) - Specified by:
setLevelin interfaceISFSExtension
-
getType
public com.smartfoxserver.extensions.ExtensionType getType()- Specified by:
getTypein interfaceISFSExtension
-
setType
public void setType(com.smartfoxserver.extensions.ExtensionType type) - Specified by:
setTypein interfaceISFSExtension
-
getReloadMode
- Specified by:
getReloadModein interfaceISFSExtension
-
setReloadMode
- Specified by:
setReloadModein interfaceISFSExtension
-
send
- Specified by:
sendin interfaceISFSExtension
-
send
- Specified by:
sendin interfaceISFSExtension
-
send
Send an extension message/response to a list of recipients- Specified by:
sendin interfaceISFSExtension- Parameters:
cmdName- the command nameparams- custom parametersrecipients- the list of recipientstxType- network transport to use (default is TCP)- See Also:
-
send
Description copied from interface:ISFSExtensionSend an extension message/response to a single User- Specified by:
sendin interfaceISFSExtension- Parameters:
cmdName- the command nameparams- custom parametersrecipient- the recipient of the messagetxType- network transport to use (default is TCP)- See Also:
-
toString
-
getLogger
public org.slf4j.Logger getLogger()Obtain a direct reference to the Extension's logger- Returns:
- the logger object
-
trace
Traces a message to the console and log files using the Logger INFO level- Parameters:
args- any number of strings/object to trace
-
trace
Trace a message to the console and log files using the specified logging level- Parameters:
level- the logging levelargs- any number of object to trace
-
removeEventsForListener
-