Skip to content

Commit 967d9d9

Browse files
committed
WIP: Cleanup and seperating typescript tools from this repo.
1 parent 4499b26 commit 967d9d9

File tree

49 files changed

+141
-3091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+141
-3091
lines changed

.github/workflows/build-dev.yml

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,22 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Set up Adopt OpenJDK 11
15-
uses: actions/setup-java@v2
14+
- uses: actions/setup-java@v2
1615
with:
1716
distribution: 'adopt'
1817
java-version: '11'
19-
- name: Set up Node.js v14
20-
uses: actions/setup-node@v2
18+
- uses: actions/setup-node@v2
2119
with:
2220
node-version: '14'
2321
- name: Fix gradlew permissions
2422
run: chmod +x ./gradlew
25-
- name: Export TypeScript Libraries with Gradle
26-
run: ./gradlew :ScriptableMC-Tools-TS:Standalone:exportTypeScriptLibraries
27-
- name: Compile TypeScript libraries and create archives
28-
run: |
29-
cd ./ScriptableMC-Tools-TS/Standalone/lib/
30-
npm install
31-
npm run compile
32-
cd ./ts/
33-
zip -r ../ScriptableMC-TypeScript-Lib.zip ./*
34-
cd ../js/
35-
zip -r ../ScriptableMC-JavaScript-Lib.zip ./*
36-
cd ../
37-
cp ./ScriptableMC-JavaScript-Lib.zip ../../../ScriptableMC-Engine-JS/src/main/resources/libraries.zip
38-
- name: Export lib-smc with gradle
39-
run: ./gradlew :ScriptableMC-Tools-TS:Standalone:generateLibSMC
40-
- name: Compile lib-smc, create archive, and publish
41-
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
run: |
44-
cd ./ScriptableMC-Tools-TS/Standalone/lib-smc/
45-
npm install
46-
npm run compile
47-
npm publish ./js
48-
zip -r ./Lib-SMC.zip ./*
49-
- name: Build All Plugins with Gradle
23+
- name: Build plugin jar files with Gradle
5024
run: ./gradlew :shadowJarAll
5125
- name: Copy artifacts
5226
run: |
5327
mkdir artifacts
5428
cp ./build/ScriptableMC-Engine-JS.jar ./artifacts/
5529
cp ./build/ScriptableMC-Engine-JS-Bundled.jar ./artifacts/
56-
cp ./build/ScriptableMC-Tools-TS.jar ./artifacts/
57-
cp ./build/ScriptableMC-Tools-TS-Standalone.jar ./artifacts/
58-
cp ./ScriptableMC-Tools-TS/Standalone/lib/ScriptableMC-TypeScript-Lib.zip ./artifacts/
59-
cp ./ScriptableMC-Tools-TS/Standalone/lib/ScriptableMC-JavaScript-Lib.zip ./artifacts/
60-
cp ./ScriptableMC-Tools-TS/Standalone/lib-smc/Lib-SMC.zip ./artifacts/
6130
- uses: actions/upload-artifact@v2
6231
with:
6332
name: ScriptableMC-Engine-DEV

.idea/kotlinScripting.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Run JavaScript/TypeScript plugins for Minecraft 1.17 using the GraalJS script en
88
Supported Minecraft Versions: Bukkit/Spigot/Paper **1.17**<br />
99
Previous Minecraft Versions: [Use v1.3.X version of the plugin](https://github.com/astorks/ScriptableMC-Engine/tree/1.3.x) <br />
1010

11-
#### New Version Numbering
11+
#### New v1.17.X
1212
**We are switching to a new version numbering to match the supporting minecraft version.**<br />
1313
**New v1.17.X builds of this plugin will only work with Minecraft 1.17+**<br />
1414
**For Minecraft v1.12-1.16 you should use v1.3.X of this plugin.**<br />
@@ -42,24 +42,10 @@ You can take the typescript example and compile it, then directly modify the jav
4242
##### ScritableMC JavaScript Engine Commands
4343
| Command | Alias | Description | Permission |
4444
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
45-
| `/scriptablemc javascript reload` | `/smc rl /jsrl` | Fully reloads the javascript engine and all script files. | `scriptablemc.js.reload` |
46-
| `/scriptablemc javascript execute <source>` | `/smc js ex <source>` | Executes javascript source and prints the return value. | `scriptablemc.js.execute` |
47-
| `/scriptablemc javascript execute stash` | `/smc js ex stash` | Executes javascript source stored in your stash. | `scriptablemc.js.execute` |
48-
| `/scriptablemc javascript file <filePath>` | `/smc js f <filePath>` | Executes javascript file from the scripts folder. | `scriptablemc.js.execute.file` |
49-
| `/scriptablemc javascript stash` | `/smc js st` | Prints all stored javascript lines in your stash. | `scriptablemc.js.execute` |
50-
| `/scriptablemc javascript stash <source>` | `/smc js st <source>` | Adds a line to your javascript stash. | `scriptablemc.js.execute` |
51-
| `/scriptablemc javascript stash clear` | `/smc js st clear` | Clears your javascript stash. | `scriptablemc.js.execute` |
52-
53-
##### ScritableMC Python Engine Commands
54-
| Command | Alias | Description | Permission |
55-
| ------------- | ------------- |-----------------------------------------------------| ------------------------ |
56-
| `/scriptablemc python reload` | `/smc rl /pyrl` | Fully reloads the python script engine and all script files. | `scriptablemc.python.reload` |
57-
| `/scriptablemc python execute <source>` | `/smc py ex <source> /pyex` | Executes python source and prints the return value. | `scriptablemc.python.execute` |
58-
| `/scriptablemc python execute stash` | `/smc py ex stash` | Executes python source stored in your stash. | `scriptablemc.python.execute` |
59-
| `/scriptablemc python file <filePath>` | `/smc py f <filePath>` | Executes python file from the scripts folder. | `scriptablemc.python.execute.file` |
60-
| `/scriptablemc python stash` | `/smc py st` | Prints all stored python lines in your stash. | `scriptablemc.python.execute` |
61-
| `/scriptablemc python stash <source>` | `/smc py st <source>` | Adds a line to your python stash. | `scriptablemc.python.execute` |
62-
| `/scriptablemc python stash clear` | `/smc py st clear` | Clears your python stash. | `scriptablemc.python.execute` |
45+
| `/scriptablemc javascript reload` | `/smc js rl` `/jsrl` | Fully reloads the javascript engine and all script files. | `scriptablemc.js.reload` |
46+
| `/scriptablemc javascript execute <source>` | `/smc js ex <source>` `/jsex <source>` | Executes javascript source and prints the return value. | `scriptablemc.js.execute` |
47+
| `/scriptablemc javascript file <filePath>` | `/smc js f <filePath>` `/jsexf` | Executes javascript file from the scripts folder. | `scriptablemc.js.execute.file` |
48+
| `/scriptablemc javascript pastebin <filePath>` | `/smc js pb <filePath>` `/jsexpb` | Executes javascript source from a pastebin. | `scriptablemc.js.execute.pastebin` |
6349

6450
### `/smc javascript execute` Command Example
6551
> `/jsex return 1 + 1` <br>

ScriptableMC-Engine-Core/build.gradle.kts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
java
33
id("org.jetbrains.kotlin.jvm")
4+
id("com.github.johnrengelman.shadow")
45
id("org.jetbrains.gradle.plugin.idea-ext")
56
}
67

@@ -36,14 +37,21 @@ dependencies {
3637
// 3rd-Party Libraries
3738
implementation("com.github.jkcclemens:khttp:-SNAPSHOT")
3839
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT")
39-
compileOnly("fr.minuskube.inv:smart-invs:1.2.7")
40+
implementation("de.tr7zw:item-nbt-api:2.8.0")
41+
implementation("fr.minuskube.inv:smart-invs:1.2.7")
4042
compileOnly("me.clip:placeholderapi:2.10.4")
41-
compileOnly("commons-io:commons-io:2.6")
42-
compileOnly("de.tr7zw:item-nbt-api:2.7.1")
4343

4444
testImplementation("junit", "junit", "4.12")
4545
}
4646

47+
tasks.shadowJar {
48+
dependencies {
49+
exclude(dependency("org.spigotmc:spigot-api"))
50+
}
51+
52+
archiveFileName.set("ScriptableMC-Engine-Core.jar")
53+
}
54+
4755
tasks.compileKotlin {
4856
kotlinOptions.jvmTarget = "11"
4957
kotlinOptions.javaParameters = true

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/PluginEngineMain.kt renamed to ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/ScriptablePluginEngineBootstrapper.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender
88
import org.bukkit.plugin.java.JavaPlugin
99

1010
@Suppress("unused")
11-
abstract class PluginEngineMain : JavaPlugin() {
11+
abstract class ScriptablePluginEngineBootstrapper : JavaPlugin() {
1212
var scriptEngine: ScriptablePluginEngine? = null
1313
var commandManager: PaperCommandManager? = null
1414
abstract val chatMessagePrefix: String
@@ -46,7 +46,7 @@ abstract class PluginEngineMain : JavaPlugin() {
4646
}
4747

4848
companion object {
49-
private val scriptEngines: MutableMap<String, PluginEngineMain?> = mutableMapOf()
49+
private val scriptEngines: MutableMap<String, ScriptablePluginEngineBootstrapper?> = mutableMapOf()
5050
/**
5151
* Patches the bukkit class loader to allow for GraalVM class loading from inside plugin jar.
5252
* A bit hackish but it works.
@@ -60,7 +60,7 @@ abstract class PluginEngineMain : JavaPlugin() {
6060
}
6161

6262
@JvmStatic
63-
fun registerScriptEngine(language: String, scriptEngineMain: PluginEngineMain) {
63+
fun registerScriptEngine(language: String, scriptEngineMain: ScriptablePluginEngineBootstrapper) {
6464
scriptEngines[language] = scriptEngineMain
6565
}
6666

@@ -70,12 +70,12 @@ abstract class PluginEngineMain : JavaPlugin() {
7070
}
7171

7272
@JvmStatic
73-
fun resolveScriptEngine(language: String): PluginEngineMain? {
73+
fun resolveScriptEngine(language: String): ScriptablePluginEngineBootstrapper? {
7474
return scriptEngines.getOrDefault(language, null)
7575
}
7676

7777
@JvmStatic
78-
fun getAllScriptEngines(): Array<PluginEngineMain> {
78+
fun getAllScriptEngines(): Array<ScriptablePluginEngineBootstrapper> {
7979
return scriptEngines.values.filterNotNull().toTypedArray()
8080
}
8181

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/PluginEngineCommands.kt renamed to ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/ScriptablePluginEngineCommands.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import org.bukkit.command.CommandSender
99

1010
@Suppress("unused")
1111
@CommandAlias("scriptablemc|smc")
12-
class PluginEngineCommands(private val basePlugin: PluginEngineMain) : BaseCommand() {
12+
class ScriptablePluginEngineCommands(private val bootstrapper: ScriptablePluginEngineBootstrapper) : BaseCommand() {
1313

1414
@Subcommand("info|i")
1515
@CommandAlias("smci")
1616
@CommandPermission("scriptablemc.info")
1717
fun info(sender: CommandSender) {
1818
sender.sendMessage("-----------------------------------------------------")
19-
sender.sendMessage("- ${ChatColor.DARK_PURPLE}ScriptableMC Version: ${basePlugin.description.version}")
19+
sender.sendMessage("- ${ChatColor.DARK_PURPLE}ScriptableMC Version: ${bootstrapper.description.version}")
2020
sender.sendMessage("-----------------------------------------------------")
21-
for (scriptEngineMain in PluginEngineMain.getAllScriptEngines()) {
21+
for (scriptEngineMain in ScriptablePluginEngineBootstrapper.getAllScriptEngines()) {
2222
if (scriptEngineMain.scriptLanguage == "js") {
2323
val scriptEngine = scriptEngineMain.scriptEngine
2424
val isGraalRuntime = scriptEngine?.eval("if (typeof Graal != 'undefined') { Graal.isGraalRuntime() } else { false }")?.asBoolean() == true
@@ -47,14 +47,14 @@ class PluginEngineCommands(private val basePlugin: PluginEngineMain) : BaseComma
4747
@CommandAlias("smcv")
4848
@CommandPermission("scriptablemc.versioncheck")
4949
fun version(sender: CommandSender) {
50-
basePlugin.versionCheck(sender)
50+
bootstrapper.versionCheck(sender)
5151
}
5252

5353
@Subcommand("reload|rl")
5454
@CommandAlias("smcrl")
5555
@CommandPermission("scriptablemc.reload")
5656
fun reload(sender: CommandSender) {
57-
PluginEngineMain.reloadAllScriptEngines(sender)
57+
ScriptablePluginEngineBootstrapper.reloadAllScriptEngines(sender)
5858
}
5959

6060
}

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/PluginEngineConfig.kt renamed to ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/ScriptablePluginEngineConfig.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.pixlfox.scriptablemc
22

33
import org.bukkit.configuration.file.FileConfiguration
44

5-
abstract class PluginEngineConfig(private val config: FileConfiguration) {
5+
abstract class ScriptablePluginEngineConfig(private val config: FileConfiguration) {
66
val rootScriptsFolder: String
77
get() = readConfigString("root_scripts_folder", "./scripts")
88

@@ -25,7 +25,7 @@ abstract class PluginEngineConfig(private val config: FileConfiguration) {
2525
@JvmOverloads
2626
fun readConfigString(path: String, def: String = ""): String {
2727
val input = config.getString(path, def).orEmpty()
28-
val regex = Regex("\\\$\\{(.*)}")
28+
val regex = Regex("[@|\\\$]\\{(.*)}")
2929

3030
return regex.replace(input) {
3131
val configValue = readConfigString(it.groups[1]!!.value)
@@ -36,7 +36,7 @@ abstract class PluginEngineConfig(private val config: FileConfiguration) {
3636
@JvmOverloads
3737
fun readConfigStringList(path: String, def: List<String> = listOf()): List<String> {
3838
val inputList = config.getStringList(path)
39-
val regex = Regex("\\\$\\{(.*)}")
39+
val regex = Regex("[@|\\\$]\\{(.*)}")
4040

4141
if(inputList.isEmpty()) {
4242
inputList.addAll(def)
@@ -57,7 +57,7 @@ abstract class PluginEngineConfig(private val config: FileConfiguration) {
5757
return readConfigString(path, def.toString()).equals("true", true)
5858
}
5959

60-
class ScriptEngineDebuggerConfig(private val config: PluginEngineConfig) {
60+
class ScriptEngineDebuggerConfig(private val config: ScriptablePluginEngineConfig) {
6161
val enabled: Boolean
6262
get() = config.readConfigBoolean("debugger.enabled", false)
6363

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.pixlfox.scriptablemc.core
22

33
import com.smc.version.Version
4-
import fr.minuskube.inv.InventoryManager
54
import me.clip.placeholderapi.PlaceholderAPI
65
import org.bukkit.Bukkit
76
import org.bukkit.Material
@@ -27,7 +26,6 @@ abstract class ScriptablePluginContext: Listener {
2726
abstract val engine: ScriptablePluginEngine
2827
abstract val pluginName: String
2928
abstract val pluginInstance: Value
30-
// abstract val inventoryManager: InventoryManager
3129
abstract val pluginVersion: Version
3230
open val pluginIcon: Material = Material.STONE
3331

@@ -38,7 +36,7 @@ abstract class ScriptablePluginContext: Listener {
3836
get() = Bukkit.getServer()
3937

4038
val javaPlugin: JavaPlugin
41-
get() = engine.bootstrapPlugin
39+
get() = engine.bootstrapper
4240

4341
val servicesManager: ServicesManager
4442
get() = Bukkit.getServicesManager()
@@ -133,7 +131,7 @@ abstract class ScriptablePluginContext: Listener {
133131
return PlaceholderAPI.setPlaceholders(player, placeholderText)
134132
}
135133

136-
engine.bootstrapPlugin.logger.warning("[$pluginName] Placeholder API is missing.")
134+
engine.bootstrapper.logger.warning("[$pluginName] Placeholder API is missing.")
137135
return placeholderText
138136
}
139137

@@ -142,7 +140,7 @@ abstract class ScriptablePluginContext: Listener {
142140
return PlaceholderAPI.setPlaceholders(player, placeholderText)
143141
}
144142

145-
engine.bootstrapPlugin.logger.warning("[$pluginName] Placeholder API is missing.")
143+
engine.bootstrapper.logger.warning("[$pluginName] Placeholder API is missing.")
146144
return placeholderText
147145
}
148146

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.pixlfox.scriptablemc.core
22

3-
import com.pixlfox.scriptablemc.PluginEngineConfig
4-
import com.pixlfox.scriptablemc.PluginEngineMain
3+
import com.pixlfox.scriptablemc.ScriptablePluginEngineBootstrapper
4+
import com.pixlfox.scriptablemc.ScriptablePluginEngineConfig
55
import com.smc.exceptions.ScriptNotFoundException
66
import com.smc.version.Version
7+
import fr.minuskube.inv.InventoryManager
78
import org.bukkit.Bukkit
89
import org.bukkit.command.CommandSender
910
import org.graalvm.polyglot.*
@@ -14,18 +15,21 @@ import java.util.*
1415
abstract class ScriptablePluginEngine {
1516
abstract val languageName: String
1617
abstract val languageFileExtension: String
17-
abstract val bootstrapPlugin: PluginEngineMain
18+
abstract val bootstrapper: ScriptablePluginEngineBootstrapper
1819
abstract val debugEnabled: Boolean
1920

2021
abstract val scriptablePlugins: MutableList<ScriptablePluginContext>
2122

2223
abstract val graalContext: Context
2324
abstract val globalBindings: Value
2425

25-
abstract val config: PluginEngineConfig
26+
abstract val config: ScriptablePluginEngineConfig
27+
28+
val inventoryManager: InventoryManager
29+
get() = InventoryManager(bootstrapper)
2630

2731
val pluginVersion: Version
28-
get() = bootstrapPlugin.pluginVersion
32+
get() = bootstrapper.pluginVersion
2933

3034
var enabledAllPlugins: Boolean = false
3135
internal set
@@ -62,7 +66,7 @@ abstract class ScriptablePluginEngine {
6266
}
6367
catch (e: Exception) {
6468
if(!helperClass.startsWith("*")) {
65-
bootstrapPlugin.logger.warning("Failed to load helper class \"$helperClass\" via classloader.")
69+
bootstrapper.logger.warning("Failed to load helper class \"$helperClass\" via classloader.")
6670
e.printStackTrace()
6771
}
6872
}
@@ -88,7 +92,7 @@ abstract class ScriptablePluginEngine {
8892
pluginContext.enable()
8993
}
9094
else {
91-
bootstrapPlugin.logger.warning("Trying to enable an already-enabled scriptable plugin context.")
95+
bootstrapper.logger.warning("Trying to enable an already-enabled scriptable plugin context.")
9296
}
9397
}
9498

@@ -97,7 +101,7 @@ abstract class ScriptablePluginEngine {
97101
pluginContext.disable()
98102
}
99103
else {
100-
bootstrapPlugin.logger.warning("Trying to disabled an already-disabled scriptable plugin context.")
104+
bootstrapper.logger.warning("Trying to disabled an already-disabled scriptable plugin context.")
101105
}
102106
}
103107

ScriptableMC-Engine-Core/src/main/kotlin/com/smc/version/MinecraftVersions.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ import java.util.regex.Pattern
3434
@Suppress("unused")
3535
class MinecraftVersions private constructor(){
3636
companion object {
37+
/**
38+
* Version 1.17 - caves and cliffs update
39+
*/
40+
@JvmField
41+
val v1_17 = parse("1.17")
42+
43+
/**
44+
* Version 1.16 - nether update
45+
*/
46+
@JvmField
47+
val v1_16 = parse("1.16")
48+
3749
/**
3850
* Version 1.15 - buzzy bees update
3951
*/

0 commit comments

Comments
 (0)