Skip to content

Commit bf1b8a4

Browse files
authored
Merge pull request #22 from astorks/dev
Dev -> Master v1.2.1
2 parents 8bcb623 + e3d4fad commit bf1b8a4

29 files changed

Lines changed: 692 additions & 394 deletions

File tree

.github/workflows/build-dev.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ jobs:
3434
zip -r ../ScriptableMC-JavaScript-Lib.zip ./*
3535
cd ../
3636
cp ./ScriptableMC-JavaScript-Lib.zip ../../ScriptableMC-Engine-JS/src/main/resources/libraries.zip
37+
- name: Export lib-smc with gradle
38+
run: ./gradlew :ScriptableMC-Tools-TS:generateLibSMC
39+
- name: Compile lib-smc, create archive, and publish
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
cd ./ScriptableMC-Tools-TS/lib-smc/
44+
npm install
45+
npm run compile
46+
npm publish ./js
47+
zip -r ./Lib-SMC.zip ./*
3748
- name: Build All Plugins with Gradle
3849
run: ./gradlew :shadowJarAll
3950
- name: Copy artifacts
@@ -45,6 +56,7 @@ jobs:
4556
cp ./build/ScriptableMC-Engine-PY-Bundled.jar ./artifacts/
4657
cp ./ScriptableMC-Tools-TS/lib/ScriptableMC-TypeScript-Lib.zip ./artifacts/
4758
cp ./ScriptableMC-Tools-TS/lib/ScriptableMC-JavaScript-Lib.zip ./artifacts/
59+
cp ./ScriptableMC-Tools-TS/lib-smc/Lib-SMC.zip ./artifacts/
4860
- uses: actions/upload-artifact@v1
4961
with:
5062
name: ScriptableMC-Engine-DEV

.github/workflows/release.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ jobs:
3030
zip -r ../ScriptableMC-JavaScript-Lib.zip ./*
3131
cd ../
3232
cp ./ScriptableMC-JavaScript-Lib.zip ../../ScriptableMC-Engine-JS/src/main/resources/libraries.zip
33+
- name: Export lib-smc with gradle
34+
run: ./gradlew :ScriptableMC-Tools-TS:generateLibSMCRelease
35+
- name: Compile lib-smc, create archive, and publish
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
run: |
40+
cd ./ScriptableMC-Tools-TS/lib-smc/
41+
npm install
42+
npm run compile
43+
npm publish ./js --access public
44+
zip -r ./Lib-SMC.zip ./*
3345
- name: Build JS Engine with Gradle
3446
run: ./gradlew :shadowJarAll
3547
- name: Upload JavaScript Engine Plugin Jar
@@ -49,13 +61,13 @@ jobs:
4961
env:
5062
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5163
with:
52-
args: 'ScriptableMC-Engine-JS-Bundled/build/libs/ScriptableMC-Engine-JS-Bundled.jar'
64+
args: 'ScriptableMC-Engine-JS/Bundled/build/libs/ScriptableMC-Engine-JS-Bundled.jar'
5365
- name: Upload Bundled Python Engine Plugin Jar
5466
uses: skx/github-action-publish-binaries@master
5567
env:
5668
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5769
with:
58-
args: 'ScriptableMC-Engine-PY-Bundled/build/libs/ScriptableMC-Engine-PY-Bundled.jar'
70+
args: 'ScriptableMC-Engine-PY/Bundled/build/libs/ScriptableMC-Engine-PY-Bundled.jar'
5971
- name: Upload TypeScript Libraries
6072
uses: skx/github-action-publish-binaries@master
6173
env:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ node_modules/
4242
.rpt2_cache/
4343
libraries/tools/kotlin-test-nodejs-runner/lib/
4444
local.properties
45-
lib
45+
lib
46+
lib-smc

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![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)
44
[![SpigotMC Resource](https://img.shields.io/badge/SpigotMC-Resource-yellow?style=for-the-badge)](https://www.spigotmc.org/resources/scriptablemc-engine.74690/)
5+
![License](https://img.shields.io/github/license/astorks/ScriptableMC-Engine?style=for-the-badge)
56

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

1617
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.
1718

18-
## Installing The Plugin
19-
- Ensure your server is running OpenJDK 8+ or GraalVM
20-
- [Download the latest ScriptableMC plugin](https://github.com/astorks/ScriptableMC-Engine/releases/latest) and place it in your plugins folder.
21-
- Take a look at [ScriptableMC-TypeScript](https://github.com/astorks/ScriptableMC-TypeScript) for a full typescript plugin example.
19+
## Installing The JavaScript Engine Plugin
20+
##### If your server is running on a Standard JDK
21+
- 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.
22+
##### If your server is running on a GraalVM JDK
23+
- 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.
24+
25+
Take a look at [ScriptableMC-TypeScript](https://github.com/astorks/ScriptableMC-TypeScript) for a full typescript plugin example.
2226
You can take the typescript example and compile it, then directly modify the javascript if you don't want to use typescript.
2327

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

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

48+
##### ScritableMC Python Engine Commands
49+
| Command | Alias | Description | Permission |
50+
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
51+
| `/scriptablemc python reload` | `/smc rl /pyrl` | Fully reloads the python script engine and all script files. | `scriptablemc.python.reload` |
52+
| `/scriptablemc python execute <source>` | `/smc py ex <source> /pyex` | Executes python source and prints the return value. | `scriptablemc.python.execute` |
53+
| `/scriptablemc python execute stash` | `/smc py ex stash` | Executes python source stored in your stash. | `scriptablemc.python.execute` |
54+
| `/scriptablemc python file <filePath>` | `/smc py f <filePath>` | Executes python file from the scripts folder. | `scriptablemc.python.execute.file` |
55+
| `/scriptablemc python stash` | `/smc py st` | Prints all stored python lines in your stash. | `scriptablemc.python.execute` |
56+
| `/scriptablemc python stash <source>` | `/smc py st <source>` | Adds a line to your python stash. | `scriptablemc.python.execute` |
57+
| `/scriptablemc python stash clear` | `/smc py st clear` | Clears your python stash. | `scriptablemc.python.execute` |
58+
4459
### `/smc javascript execute` Command Example
4560
> `/jsex return 1 + 1` <br>
4661
> ![2](https://i.imgur.com/1MkiDxW.png)
@@ -54,4 +69,5 @@ https://github.com/MinusKube/SmartInvs - Inventory helper library<br />
5469
https://github.com/lucko/helper - MinecraftVersions helper library<br />
5570
https://github.com/jkcclemens/khttp - HTTP helper library<br />
5671
https://github.com/aikar/commands - Built-in commands and auto-completion<br />
72+
https://github.com/apache/commons-io - FileUtils helper library<br />
5773
https://github.com/graalvm/graaljs - JavaScript engine
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.pixlfox.scriptablemc
2+
3+
import org.bukkit.configuration.file.FileConfiguration
4+
5+
abstract class ScriptEngineConfig(private val config: FileConfiguration) {
6+
val rootScriptsFolder: String
7+
get() = readConfigString("root_scripts_folder", "./scripts")
8+
9+
abstract val mainScriptFiles: List<String>
10+
abstract val executeCommandTemplate: String
11+
abstract val scriptMimeType: String
12+
13+
val autoEnablePlugins: Boolean
14+
get() = readConfigBoolean("auto_enable_plugins", true)
15+
16+
val debug: Boolean
17+
get() = readConfigBoolean("debug", false)
18+
19+
val extractLibs: Boolean
20+
get() = readConfigBoolean("extract_libs", true)
21+
22+
val debugger: ScriptEngineDebuggerConfig
23+
get() = ScriptEngineDebuggerConfig(this)
24+
25+
@JvmOverloads
26+
fun readConfigString(path: String, def: String = ""): String {
27+
val input = config.getString(path, def).orEmpty()
28+
val regex = Regex("\\\$\\{(.*)}")
29+
30+
return regex.replace(input) {
31+
val configValue = readConfigString(it.groups[1]!!.value)
32+
configValue
33+
}
34+
}
35+
36+
@JvmOverloads
37+
fun readConfigStringList(path: String, def: List<String> = listOf()): List<String> {
38+
val inputList = config.getStringList(path)
39+
val regex = Regex("\\\$\\{(.*)}")
40+
41+
if(inputList.isEmpty()) {
42+
inputList.addAll(def)
43+
}
44+
45+
for((index, input) in inputList.withIndex()) {
46+
inputList[index] = regex.replace(input) {
47+
val configValue = readConfigString(it.groups[1]!!.value)
48+
configValue
49+
}
50+
}
51+
52+
return inputList
53+
}
54+
55+
@JvmOverloads
56+
fun readConfigBoolean(path: String, def: Boolean = false): Boolean {
57+
return readConfigString(path, def.toString()).equals("true", true)
58+
}
59+
}
60+
61+
class ScriptEngineDebuggerConfig(private val config: ScriptEngineConfig) {
62+
val enabled: Boolean
63+
get() = config.readConfigBoolean("debugger.enabled", false)
64+
65+
val address: String
66+
get() = config.readConfigString("debugger.address", "127.0.0.1:9229")
67+
68+
val waitAttached: Boolean
69+
get() = config.readConfigBoolean("debugger.wait_attached", true)
70+
}

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/core/ScriptablePluginContext.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ abstract class ScriptablePluginContext: Listener {
2929
abstract val inventoryManager: InventoryManager
3030
abstract val pluginVersion: Version
3131

32+
var isEnabled: Boolean = false
33+
internal set
34+
3235
val server: Server
3336
get() = Bukkit.getServer()
3437

0 commit comments

Comments
 (0)