Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
25b0364
Merge branch 'master' into dev
astorks Feb 20, 2020
251007a
Merge branch 'master' into dev
astorks Feb 20, 2020
e7cdc6d
Updating readme
astorks Feb 20, 2020
13d40f0
Updating readme
astorks Feb 20, 2020
97803e3
Added commonjs build step to libraries, for use later.
astorks Feb 20, 2020
e447c2f
Bumped version to v1.2.1.
astorks Feb 20, 2020
f34cd24
Updated python config docs.
astorks Feb 20, 2020
168267f
Added config option to change the main entrypoint file.
astorks Feb 20, 2020
eb2755c
Updated dev build to create lib-smc archive.
astorks Feb 20, 2020
83f1a72
Updated dev build to publish lib-smc to github packages.
astorks Feb 20, 2020
2bdd2a7
Fixed missing environment variable GITHUB_TOKEN.
astorks Feb 21, 2020
35d6ff2
Updated dev build.
astorks Feb 21, 2020
d53491d
Fixed dev build
astorks Feb 21, 2020
ac9e078
Hopefully fixed dev build
astorks Feb 21, 2020
57fbb1b
Hopefully fixed dev build
astorks Feb 21, 2020
22869ba
Fixed a dumb bug
astorks Feb 21, 2020
e19af64
Please work
astorks Feb 21, 2020
a433b83
pls work
astorks Feb 21, 2020
0f3fe0e
Added github actions build and release support for lib-smc.
astorks Feb 21, 2020
5e4cc89
Debugging release build.
astorks Feb 21, 2020
5418aad
Fixed release build.
astorks Feb 21, 2020
a0f16f8
Updated release build script to publish to npm.
astorks Feb 21, 2020
5867571
Updated release build script to publish to npm.
astorks Feb 21, 2020
db56951
Updated build system.
astorks Feb 21, 2020
b85e764
Testing npm build script.
astorks Feb 21, 2020
5bdecf8
Fixed js config common_js.globals_file should work properly now.
astorks Feb 22, 2020
44fe98b
Continued cleanup and moving code shared between both js and py engin…
astorks Feb 22, 2020
f1bc677
Added a few more config options and moving shared code to code engine.
astorks Feb 24, 2020
666bc89
Moved bundled plugin projects inside their base plugins project folder.
astorks Feb 24, 2020
2275c53
Better plugin context enabling and disabling.
astorks Feb 24, 2020
e3d4fad
Moved try/catch handling to ScriptablePluginEngine.loadMainScript
astorks Feb 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ jobs:
zip -r ../ScriptableMC-JavaScript-Lib.zip ./*
cd ../
cp ./ScriptableMC-JavaScript-Lib.zip ../../ScriptableMC-Engine-JS/src/main/resources/libraries.zip
- name: Export lib-smc with gradle
run: ./gradlew :ScriptableMC-Tools-TS:generateLibSMC
- name: Compile lib-smc, create archive, and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd ./ScriptableMC-Tools-TS/lib-smc/
npm install
npm run compile
npm publish ./js
zip -r ./Lib-SMC.zip ./*
- name: Build All Plugins with Gradle
run: ./gradlew :shadowJarAll
- name: Copy artifacts
Expand All @@ -45,6 +56,7 @@ jobs:
cp ./build/ScriptableMC-Engine-PY-Bundled.jar ./artifacts/
cp ./ScriptableMC-Tools-TS/lib/ScriptableMC-TypeScript-Lib.zip ./artifacts/
cp ./ScriptableMC-Tools-TS/lib/ScriptableMC-JavaScript-Lib.zip ./artifacts/
cp ./ScriptableMC-Tools-TS/lib-smc/Lib-SMC.zip ./artifacts/
- uses: actions/upload-artifact@v1
with:
name: ScriptableMC-Engine-DEV
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ jobs:
zip -r ../ScriptableMC-JavaScript-Lib.zip ./*
cd ../
cp ./ScriptableMC-JavaScript-Lib.zip ../../ScriptableMC-Engine-JS/src/main/resources/libraries.zip
- name: Export lib-smc with gradle
run: ./gradlew :ScriptableMC-Tools-TS:generateLibSMCRelease
- name: Compile lib-smc, create archive, and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ./ScriptableMC-Tools-TS/lib-smc/
npm install
npm run compile
npm publish ./js --access public
zip -r ./Lib-SMC.zip ./*
- name: Build JS Engine with Gradle
run: ./gradlew :shadowJarAll
- name: Upload JavaScript Engine Plugin Jar
Expand All @@ -49,13 +61,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'ScriptableMC-Engine-JS-Bundled/build/libs/ScriptableMC-Engine-JS-Bundled.jar'
args: 'ScriptableMC-Engine-JS/Bundled/build/libs/ScriptableMC-Engine-JS-Bundled.jar'
- name: Upload Bundled Python Engine Plugin Jar
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'ScriptableMC-Engine-PY-Bundled/build/libs/ScriptableMC-Engine-PY-Bundled.jar'
args: 'ScriptableMC-Engine-PY/Bundled/build/libs/ScriptableMC-Engine-PY-Bundled.jar'
- name: Upload TypeScript Libraries
uses: skx/github-action-publish-binaries@master
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ node_modules/
.rpt2_cache/
libraries/tools/kotlin-test-nodejs-runner/lib/
local.properties
lib
lib
lib-smc
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/astorks/ScriptableMC-Engine?label=ScriptableMC&style=for-the-badge)](https://github.com/astorks/ScriptableMC-Engine/releases/latest)
[![SpigotMC Resource](https://img.shields.io/badge/SpigotMC-Resource-yellow?style=for-the-badge)](https://www.spigotmc.org/resources/scriptablemc-engine.74690/)
![License](https://img.shields.io/github/license/astorks/ScriptableMC-Engine?style=for-the-badge)

Run JavaScript/TypeScript plugins for Minecraft 1.15 using the GraalJS script engine.<br />
Supported Minecraft Versions: Bukkit/Spigot/Paper 1.12, 1.13, 1.14, **1.15**<br />
Expand All @@ -15,32 +16,46 @@ Most linux servers already use OpenJDK, however if you're running windows or wan

GraalVM-CE is a free open source java runtime created by Oracle that is pre-packaged with the GraalJS Engine allowing all javascript engine features including AOT compilation of javascript.

## Installing The Plugin
- Ensure your server is running OpenJDK 8+ or GraalVM
- [Download the latest ScriptableMC plugin](https://github.com/astorks/ScriptableMC-Engine/releases/latest) and place it in your plugins folder.
- Take a look at [ScriptableMC-TypeScript](https://github.com/astorks/ScriptableMC-TypeScript) for a full typescript plugin example.
## Installing The JavaScript Engine Plugin
##### If your server is running on a Standard JDK
- Download the latest [`ScriptableMC-Engine-JS-Bundled.jar`](https://github.com/astorks/ScriptableMC-Engine/releases/latest/download/ScriptableMC-Engine-JS-Bundled.jar) and place it in your plugins folder.
##### If your server is running on a GraalVM JDK
- Download the latest [`ScriptableMC-Engine-JS.jar`](https://github.com/astorks/ScriptableMC-Engine/releases/latest/download/ScriptableMC-Engine-JS.jar) and place it in your plugins folder.

Take a look at [ScriptableMC-TypeScript](https://github.com/astorks/ScriptableMC-TypeScript) for a full typescript plugin example.
You can take the typescript example and compile it, then directly modify the javascript if you don't want to use typescript.

## Commands and Permissions
##### ScritableMC Base Command
| Command | Alias | Description | Permission |
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
| `/scriptablemc menu` | `/smc m` | Opens an inventory menu that allows you to control the scriptable engine. | `scriptablemc.menu` |
| `/scriptablemc info` | `/smc i` | Prints plugin version and GraalVM/GraalJS versions if available. | `scriptablemc.info` |
| `/scriptablemc reload` | `/smc rl` | Fully reloads all script engines. | `scriptablemc.reload` |
| `/scriptablemc menu` | `/smc m` | Opens an inventory menu that allows you to control the script engines. | `scriptablemc.menu` |
| `/scriptablemc info` | `/smc i` | Prints plugin version and all loaded script engine versions if available. | `scriptablemc.info` |
| `/scriptablemc reload` | `/smc rl` | Fully reloads all script engines and all script files. | `scriptablemc.reload` |
| `/scriptablemc version` | `/smc v` | Check the github releases for any updates. | `scriptablemc.version` |

##### ScritableMC JavaScript Sub Command
##### ScritableMC JavaScript Engine Commands
| Command | Alias | Description | Permission |
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
| `/scriptablemc reload` | `/smc rl /jsrl` | Fully reloads the script engine and all script files. | `scriptablemc.reload` |
| `/scriptablemc javascript reload` | `/smc rl /jsrl` | Fully reloads the javascript engine and all script files. | `scriptablemc.js.reload` |
| `/scriptablemc javascript execute <source>` | `/smc js ex <source>` | Executes javascript source and prints the return value. | `scriptablemc.js.execute` |
| `/scriptablemc javascript execute stash` | `/smc js ex stash` | Executes javascript source stored in your stash. | `scriptablemc.js.execute` |
| `/scriptablemc javascript file <filePath>` | `/smc js f <filePath>` | Executes javascript file from the scripts folder. | `scriptablemc.js.execute.file` |
| `/scriptablemc javascript stash` | `/smc js st` | Prints all stored javascript lines in your stash. | `scriptablemc.js.execute` |
| `/scriptablemc javascript stash <source>` | `/smc js st <source>` | Adds a line to your javascript stash. | `scriptablemc.js.execute` |
| `/scriptablemc javascript stash clear` | `/smc js st clear` | Clears your javascript stash. | `scriptablemc.js.execute` |

##### ScritableMC Python Engine Commands
| Command | Alias | Description | Permission |
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
| `/scriptablemc python reload` | `/smc rl /pyrl` | Fully reloads the python script engine and all script files. | `scriptablemc.python.reload` |
| `/scriptablemc python execute <source>` | `/smc py ex <source> /pyex` | Executes python source and prints the return value. | `scriptablemc.python.execute` |
| `/scriptablemc python execute stash` | `/smc py ex stash` | Executes python source stored in your stash. | `scriptablemc.python.execute` |
| `/scriptablemc python file <filePath>` | `/smc py f <filePath>` | Executes python file from the scripts folder. | `scriptablemc.python.execute.file` |
| `/scriptablemc python stash` | `/smc py st` | Prints all stored python lines in your stash. | `scriptablemc.python.execute` |
| `/scriptablemc python stash <source>` | `/smc py st <source>` | Adds a line to your python stash. | `scriptablemc.python.execute` |
| `/scriptablemc python stash clear` | `/smc py st clear` | Clears your python stash. | `scriptablemc.python.execute` |

### `/smc javascript execute` Command Example
> `/jsex return 1 + 1` <br>
> ![2](https://i.imgur.com/1MkiDxW.png)
Expand All @@ -54,4 +69,5 @@ https://github.com/MinusKube/SmartInvs - Inventory helper library<br />
https://github.com/lucko/helper - MinecraftVersions helper library<br />
https://github.com/jkcclemens/khttp - HTTP helper library<br />
https://github.com/aikar/commands - Built-in commands and auto-completion<br />
https://github.com/apache/commons-io - FileUtils helper library<br />
https://github.com/graalvm/graaljs - JavaScript engine
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.pixlfox.scriptablemc

import org.bukkit.configuration.file.FileConfiguration

abstract class ScriptEngineConfig(private val config: FileConfiguration) {
val rootScriptsFolder: String
get() = readConfigString("root_scripts_folder", "./scripts")

abstract val mainScriptFiles: List<String>
abstract val executeCommandTemplate: String
abstract val scriptMimeType: String

val autoEnablePlugins: Boolean
get() = readConfigBoolean("auto_enable_plugins", true)

val debug: Boolean
get() = readConfigBoolean("debug", false)

val extractLibs: Boolean
get() = readConfigBoolean("extract_libs", true)

val debugger: ScriptEngineDebuggerConfig
get() = ScriptEngineDebuggerConfig(this)

@JvmOverloads
fun readConfigString(path: String, def: String = ""): String {
val input = config.getString(path, def).orEmpty()
val regex = Regex("\\\$\\{(.*)}")

return regex.replace(input) {
val configValue = readConfigString(it.groups[1]!!.value)
configValue
}
}

@JvmOverloads
fun readConfigStringList(path: String, def: List<String> = listOf()): List<String> {
val inputList = config.getStringList(path)
val regex = Regex("\\\$\\{(.*)}")

if(inputList.isEmpty()) {
inputList.addAll(def)
}

for((index, input) in inputList.withIndex()) {
inputList[index] = regex.replace(input) {
val configValue = readConfigString(it.groups[1]!!.value)
configValue
}
}

return inputList
}

@JvmOverloads
fun readConfigBoolean(path: String, def: Boolean = false): Boolean {
return readConfigString(path, def.toString()).equals("true", true)
}
}

class ScriptEngineDebuggerConfig(private val config: ScriptEngineConfig) {
val enabled: Boolean
get() = config.readConfigBoolean("debugger.enabled", false)

val address: String
get() = config.readConfigString("debugger.address", "127.0.0.1:9229")

val waitAttached: Boolean
get() = config.readConfigBoolean("debugger.wait_attached", true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ abstract class ScriptablePluginContext: Listener {
abstract val inventoryManager: InventoryManager
abstract val pluginVersion: Version

var isEnabled: Boolean = false
internal set

val server: Server
get() = Bukkit.getServer()

Expand Down
Loading