Skip to content

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 type
  • U: 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 core
  • profileFunction: factory that creates the profile from this core and logger
  • configFolder: configuration directory
  • macroFolder: script directory
  • logger: diagnostics logger

Fields ​

config ​

config: ConfigManagerread-only#
Configuration manager associated with this core.

eventRegistry ​

eventRegistry: BaseEventRegistryread-only#
Event registry supplied by the event-registry factory.

extensions ​

extensions: ExtensionLoaderread-only#
Extension loader associated with this core; extensions are not necessarily loaded during construction.

helperRegistry ​

helperRegistry: ClassWrapperTree<Object, BaseHelper<?>>read-only#
Maps Java object types to helper wrappers; initially, unmatched objects use an Object fallback returning null.

libraryRegistry ​

libraryRegistry: LibraryRegistryread-only#
Registry of scripting libraries associated with this core.

profile ​

profile: T extends BaseProfileread-only#
Profile instance returned by the profile factory.

services ​

services: ServiceManagerread-only#
Service manager associated with this core.

threadPool ​

threadPool: JsMacrosThreadPoolread-only#
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 execute
  • event: 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 execute
  • event: event supplied to the script
  • then: callback run after successful script execution
  • catcher: 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 hint
  • script: source text
  • fakeFile: optional file used to select a language extension and as the script file; may be null
  • event: event supplied to the script
  • then: callback run after successful script execution
  • catcher: 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 wrapper
  • wrapper: helper class with an accessible constructor taking type

Type Parameters:

  • E: input Java object type
  • R: helper type for E

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