Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

JavaScript Overview

DarkKronicle edited this page Oct 22, 2021 · 1 revision

AdvancedChatFilters uses Nashorn Sandbox to manage the JavaScript engine. On top of that custom parameters are set and only specific Java classes can be accessed. Details on the engine are found in ScriptManager.java.

Script Usage

For security filters have to manually be enabled in the configuration file. The configuration file is found in the Minecraft directory in config/advancedchat/advancedchatfilters.json. Set the value advanced_filters_on to true. Without this on no JavaScript can be evaluated.

Make sure you trust the code before you run anything.

All scripts are then put into config/advancedchat/filters and should have a .js extension to be properly loaded.

When first loaded AdvancedChatFilters only grabs the file name and lists that in the configuration page. (AdvancedChat Settings -> filters -> advanced filters). In that entry an "install" button will be shown. When the install button is shown the code will be evaluated for metadata. The code will not ever be executed unless explicitly installed.

Once installed the filter is by default off. This means that it won't be called to filter any text. Once it's on text will be ran through it.

Reloading scripts?

For changes in the filters directory to be shown or for any changes to be applied, the filters have to be reloaded. This is done by going into the advanced filters configuration page and closing out of it. There will probably be a lag spike each time you do this.

What is needed for a script to work?

Each script requires two functions. setup(payload) and filter(payload).

Setup

The setup function is to provide information about the filter. This includes display name, hover lines, and other metadata. This is ran every time that filters are reloaded. It has to be there and it is case sensitive. A Script Filter instance will be passed into the method. At this point functions like setDisplayName("name"), setId("id"), setHoverLines("lines") can be called from that object.

Filter

The filter function is where text goes to get filtered. The method should be exactly called filter and take in one argument. The payload passed in is Script Filter Context and that is where all the helper functions are and contains the filtered text. The filtered text should be set with setText(text).

Clone this wiki locally