Core
com.jsmacrosce.jsmacros.core.Core
Connects a runtime's profile, configuration, event and library registries, extensions, services, and script execution facilities.
js
const Client = Java.type('com.jsmacrosce.jsmacros.client.JsMacrosClient');
const core = Client.clientCore;
Chat.log(core.profile.getCurrentProfileName());Type Parameters
T: profile implementation typeU: event registry factory result type
Constructors
new Core
new Core(Function<Core<T extends BaseProfile, U extends BaseEventRegistry>, U extends BaseEventRegistry> eventRegistryFunction, BiFunction<Core<T extends BaseProfile, U extends BaseEventRegistry>, Logger, T extends BaseProfile> profileFunction, File configFolder, File macroFolder, Logger logger)#Creates the event registry, loads configuration, creates the profile and managers, then calls profile initialization with the configured default name and loads configured services, starting enabled entries. The event-registry factory runs first and receives this partially initialized core; the profile factory runs after configuration setup but before the extension loader and service manager are assigned.
Parameters:
eventRegistryFunction: factory that creates the event registry from this coreprofileFunction: factory that creates the profile from this core and loggerconfigFolder: configuration directorymacroFolder: script directorylogger: diagnostics logger
Fields
config
Configuration manager associated with this core.
eventRegistry
Event registry supplied by the event-registry factory.
extensions
Extension loader associated with this core; extensions are not necessarily loaded during construction.
helperRegistry
Maps Java object types to helper wrappers; initially, unmatched objects use an
Object fallback returning null.libraryRegistry
Registry of scripting libraries associated with this core.
profile
Profile instance returned by the profile factory.
services
Service manager associated with this core.
threadPool
Worker pool used for scripts associated with this core.
Methods
addContext
addContext(EventContainer<?> container): void#Adds the event container's context to the weakly tracked set.
Parameters:
container: event container whose context is tracked
exec
exec(ScriptTrigger macro, BaseEvent event): EventContainer<?>#Starts the trigger's script for an event and returns its event container.
Parameters:
macro: script trigger to executeevent: event supplied to the script
Returns: the event container for the script execution
exec(ScriptTrigger macro, BaseEvent event, Runnable then, Consumer<Throwable> catcher): EventContainer<?>#Starts the trigger's script and returns its event container, with optional completion and failure callbacks.
Parameters:
macro: script trigger to executeevent: event supplied to the scriptthen: callback run after successful script executioncatcher: callback given an execution failure
Returns: the event container for the script execution
exec(String lang, String script, File fakeFile, BaseEvent event, Runnable then, Consumer<Throwable> catcher): EventContainer<?>Since1.7.0#Starts source execution, selecting its language from
fakeFile's extension when supplied, or from lang otherwise.Parameters:
lang: language identifier or extension hintscript: source textfakeFile: optional file used to select a language extension and as the script file; may benullevent: event supplied to the scriptthen: callback run after successful script executioncatcher: callback given an execution failure
Returns: the event container for the script execution
getContexts
getContexts(): Set<BaseScriptContext<?>>#Returns the tracked script contexts.
Returns: the live set, which holds contexts weakly and does not keep them alive
registerHelper
registerHelper(Class<E> type, Class<R extends BaseHelper<E>> wrapper): void#Registers a helper wrapper for objects of the specified Java type; the wrapper is constructed when the registered mapping is used. A missing or inaccessible matching constructor causes
RuntimeException during registration. Failures invoking the constructor are wrapped in RuntimeException when the mapping is used.Parameters:
type: exact constructor parameter type accepted by the wrapperwrapper: helper class with an accessible constructor takingtype
Type Parameters:
E: input Java object typeR: helper type forE
wrapException
wrapException(Throwable ex): BaseWrappedException<?>#Wraps an exception with the first language-specific wrapper available, or as a host-stack exception otherwise.
Parameters:
ex: exception to wrap
Returns: the wrapped exception, or
null when ex is null