Skip to content

Commit 20fbacb

Browse files
committed
Support for Minecraft 1.19
1 parent 967d9d9 commit 20fbacb

26 files changed

+616
-383
lines changed

.idea/kotlinc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScriptableMC-Engine-Core/build.gradle.kts

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
java
35
id("org.jetbrains.kotlin.jvm")
46
id("com.github.johnrengelman.shadow")
57
id("org.jetbrains.gradle.plugin.idea-ext")
68
}
79

8-
var graalvmVersion = findProperty("graalvm.version")
9-
var spigotmcVersion = findProperty("spigotmc.version")
10+
var graalvmVersion = findProperty("dependencies.graalvm.version") ?: "22.3.0"
11+
var spigotmcVersion = findProperty("dependencies.spigotmc.version") ?: "1.19.2-R0.1-SNAPSHOT"
1012

1113
java {
1214
sourceCompatibility = JavaVersion.VERSION_11
@@ -20,6 +22,8 @@ idea {
2022
}
2123
}
2224

25+
val coreShadow by configurations.creating
26+
2327
dependencies {
2428
// Kotlin Standard Library & Reflection
2529
implementation("org.jetbrains.kotlin:kotlin-stdlib")
@@ -35,20 +39,30 @@ dependencies {
3539
compileOnly("org.graalvm.truffle:truffle-api:$graalvmVersion")
3640

3741
// 3rd-Party Libraries
38-
implementation("com.github.jkcclemens:khttp:-SNAPSHOT")
39-
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT")
42+
implementation("com.github.kittinunf.fuel:fuel:2.3.1")
43+
implementation("com.github.kittinunf.fuel:fuel-json:2.3.1")
44+
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
4045
implementation("de.tr7zw:item-nbt-api:2.8.0")
4146
implementation("fr.minuskube.inv:smart-invs:1.2.7")
42-
compileOnly("me.clip:placeholderapi:2.10.4")
47+
compileOnly("me.clip:placeholderapi:2.11.2")
48+
49+
50+
coreShadow(project)
51+
coreShadow("org.spigotmc:spigot-api:$spigotmcVersion:shaded")
52+
coreShadow("org.graalvm.sdk:graal-sdk:$graalvmVersion")
53+
coreShadow("org.graalvm.truffle:truffle-api:$graalvmVersion")
54+
coreShadow("com.github.kittinunf.fuel:fuel:2.3.1")
55+
coreShadow("com.github.kittinunf.fuel:fuel-json:2.3.1")
56+
coreShadow("co.aikar:acf-paper:0.5.1-SNAPSHOT")
57+
coreShadow("de.tr7zw:item-nbt-api:2.8.0")
58+
coreShadow("fr.minuskube.inv:smart-invs:1.2.7")
59+
coreShadow("me.clip:placeholderapi:2.11.2")
4360

4461
testImplementation("junit", "junit", "4.12")
4562
}
4663

4764
tasks.shadowJar {
48-
dependencies {
49-
exclude(dependency("org.spigotmc:spigot-api"))
50-
}
51-
65+
configurations = listOf(coreShadow)
5266
archiveFileName.set("ScriptableMC-Engine-Core.jar")
5367
}
5468

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

+25-25
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.bukkit.plugin.java.JavaPlugin
99

1010
@Suppress("unused")
1111
abstract class ScriptablePluginEngineBootstrapper : JavaPlugin() {
12-
var scriptEngine: ScriptablePluginEngine? = null
13-
var commandManager: PaperCommandManager? = null
12+
lateinit var scriptEngine: ScriptablePluginEngine
13+
lateinit var commandManager: PaperCommandManager
1414
abstract val chatMessagePrefix: String
1515
abstract val scriptLanguage: String
1616

@@ -20,29 +20,29 @@ abstract class ScriptablePluginEngineBootstrapper : JavaPlugin() {
2020
abstract fun reloadScriptEngine(sender: CommandSender? = null)
2121

2222
fun versionCheck(sender: CommandSender? = null) {
23-
if(config.getBoolean("version_check", true)) {
24-
khttp.async.get("https://api.github.com/repos/astorks/ScriptableMC-Engine/releases/latest") {
25-
val githubReleaseInfo = this.jsonObject
26-
val latestReleaseVersion = Version.parse(githubReleaseInfo.getString("tag_name"))
27-
val currentVersion = Version.parse("v${description.version}")
28-
val releaseLink = githubReleaseInfo.getString("html_url")
29-
30-
if (currentVersion.isBefore(latestReleaseVersion)) {
31-
sender?.sendMessage("$chatMessagePrefix ${ChatColor.YELLOW}An update was found.")
32-
sender?.sendMessage("$chatMessagePrefix CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion.")
33-
sender?.sendMessage("$chatMessagePrefix Download Page: $releaseLink")
34-
logger.warning("An update was found. CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
35-
logger.fine("Download Page: $releaseLink")
36-
}
37-
else {
38-
sender?.sendMessage("$chatMessagePrefix No updates found.")
39-
sender?.sendMessage("$chatMessagePrefix CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
40-
if (config.getBoolean("debug", false)) {
41-
logger.info("No updates found. CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
42-
}
43-
}
44-
}
45-
}
23+
// if(config.getBoolean("version_check", true)) {
24+
// khttp.async.get("https://api.github.com/repos/astorks/ScriptableMC-Engine/releases/latest") {
25+
// val githubReleaseInfo = this.jsonObject
26+
// val latestReleaseVersion = Version.parse(githubReleaseInfo.getString("tag_name"))
27+
// val currentVersion = Version.parse("v${description.version}")
28+
// val releaseLink = githubReleaseInfo.getString("html_url")
29+
//
30+
// if (currentVersion.isBefore(latestReleaseVersion)) {
31+
// sender?.sendMessage("$chatMessagePrefix ${ChatColor.YELLOW}An update was found.")
32+
// sender?.sendMessage("$chatMessagePrefix CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion.")
33+
// sender?.sendMessage("$chatMessagePrefix Download Page: $releaseLink")
34+
// logger.warning("An update was found. CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
35+
// logger.fine("Download Page: $releaseLink")
36+
// }
37+
// else {
38+
// sender?.sendMessage("$chatMessagePrefix No updates found.")
39+
// sender?.sendMessage("$chatMessagePrefix CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
40+
// if (config.getBoolean("debug", false)) {
41+
// logger.info("No updates found. CurrentVersion: $currentVersion, LatestRelease: $latestReleaseVersion")
42+
// }
43+
// }
44+
// }
45+
// }
4646
}
4747

4848
companion object {

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

+5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ abstract class ScriptablePluginContext: Listener {
2727
abstract val pluginName: String
2828
abstract val pluginInstance: Value
2929
abstract val pluginVersion: Version
30+
abstract val logger: ScriptablePluginLogger
31+
abstract val scheduler: ScriptablePluginScheduler
3032
open val pluginIcon: Material = Material.STONE
33+
open val pluginPriority: Int = 0
3134

3235
var isEnabled: Boolean = false
3336
internal set
@@ -49,6 +52,8 @@ abstract class ScriptablePluginContext: Listener {
4952

5053
abstract fun disable()
5154

55+
abstract fun unload()
56+
5257
fun registerEvent(eventClass: Class<out Event>, executor: EventExecutor) {
5358
Bukkit.getServer().pluginManager.registerEvent(eventClass, this, EventPriority.NORMAL, executor, javaPlugin)
5459
}

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

+29-33
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,20 @@ abstract class ScriptablePluginEngine {
3737
val startupErrors: MutableList<Exception> = mutableListOf()
3838

3939
open fun start() {
40+
startupErrors.clear()
41+
4042
globalBindings.putMember("engine", this)
4143

4244
loadAllHelperClasses()
4345

4446
for(mainScriptFile in config.mainScriptFiles) {
4547
loadMainScript(mainScriptFile)
4648
}
47-
48-
if(!enabledAllPlugins && config.autoEnablePlugins) {
49-
enableAllPlugins()
50-
}
5149
}
5250

5351
open fun close() {
54-
for(scriptablePlugin in scriptablePlugins) {
55-
scriptablePlugin.disable()
56-
}
57-
scriptablePlugins.clear()
58-
52+
disableAllPlugins()
53+
unloadAllPlugins()
5954
graalContext.close(true)
6055
}
6156

@@ -74,19 +69,31 @@ abstract class ScriptablePluginEngine {
7469
}
7570

7671
open fun enableAllPlugins() {
77-
for (pluginContext in scriptablePlugins.filter { !it.isEnabled }) {
72+
val scriptablePlugins = scriptablePlugins.toList()
73+
74+
for (pluginContext in scriptablePlugins.filter { !it.isEnabled }.sortedByDescending { it.pluginPriority }) {
7875
enablePlugin(pluginContext)
7976
}
8077
enabledAllPlugins = true
8178
}
8279

8380
open fun disableAllPlugins() {
84-
for (pluginContext in scriptablePlugins.filter { it.isEnabled }) {
81+
val scriptablePlugins = scriptablePlugins.toList()
82+
83+
for (pluginContext in scriptablePlugins.filter { it.isEnabled }.sortedBy { it.pluginPriority }) {
8584
disablePlugin(pluginContext)
8685
}
8786
enabledAllPlugins = false
8887
}
8988

89+
open fun unloadAllPlugins() {
90+
val scriptablePlugins = scriptablePlugins.toList()
91+
92+
for (pluginContext in scriptablePlugins.sortedBy { it.pluginPriority }) {
93+
unloadPlugin(pluginContext)
94+
}
95+
}
96+
9097
open fun enablePlugin(pluginContext: ScriptablePluginContext) {
9198
if(!pluginContext.isEnabled) {
9299
pluginContext.enable()
@@ -120,22 +127,8 @@ abstract class ScriptablePluginEngine {
120127
open fun evalCommandSender(source: String, sender: CommandSender): Value {
121128
val tempScriptFile = File("${config.rootScriptsFolder}/${UUID.randomUUID()}.$languageFileExtension")
122129
try {
123-
tempScriptFile.writeText(config.executeCommandTemplate.replace("%SOURCE%", source))
124-
125-
var evalReturn = evalFile(tempScriptFile)
126-
127-
if(evalReturn.canInstantiate()) {
128-
evalReturn = evalReturn.newInstance()
129-
}
130-
131-
if(evalReturn.hasMember("execute") && evalReturn.canInvokeMember("execute")) {
132-
evalReturn.putMember("sender", sender)
133-
evalReturn.putMember("server", Bukkit.getServer())
134-
evalReturn.putMember("servicesManager", Bukkit.getServicesManager())
135-
return evalReturn.invokeMember("execute", sender, Bukkit.getServer(), Bukkit.getServicesManager())
136-
}
137-
138-
return evalReturn
130+
tempScriptFile.writeText(source)
131+
return evalFile(tempScriptFile)
139132
}
140133
finally {
141134
tempScriptFile.delete()
@@ -184,6 +177,10 @@ abstract class ScriptablePluginEngine {
184177

185178
open fun loadMainScript(path: String) {
186179
try {
180+
if(config.debug) {
181+
bootstrapper.logger.info("Loading main script file: $path")
182+
}
183+
187184
val mainScriptFile = File(path)
188185
if(!mainScriptFile.parentFile.exists()) {
189186
mainScriptFile.parentFile.mkdirs()
@@ -195,14 +192,13 @@ abstract class ScriptablePluginEngine {
195192
.name(mainScriptFile.name)
196193
.mimeType(config.scriptMimeType)
197194
.interactive(false)
195+
.cached(false)
198196
.build()
199197
)
200198

201-
// Load all plugin types returned as an array
202-
if(mainReturn.hasArrayElements()) {
203-
for (i in 0 until mainReturn.arraySize) {
204-
this.loadPlugin(mainReturn.getArrayElement(i))
205-
}
199+
// Load exported JsPlugins
200+
for(key in mainReturn.memberKeys) {
201+
this.loadPlugin(mainReturn.getMember(key))
206202
}
207203
}
208204
else {
@@ -215,6 +211,7 @@ abstract class ScriptablePluginEngine {
215211
}
216212

217213
abstract fun loadPlugin(scriptableClass: Value): ScriptablePluginContext
214+
abstract fun unloadPlugin(pluginContext: ScriptablePluginContext)
218215

219216
companion object {
220217
val preLoadClasses: Array<String> = arrayOf(
@@ -223,7 +220,6 @@ abstract class ScriptablePluginEngine {
223220

224221
"com.smc.utils.ItemBuilder",
225222
"com.smc.utils.MysqlWrapper",
226-
"com.smc.utils.Http",
227223

228224
"com.smc.smartinvs.SmartInventory",
229225
"com.smc.smartinvs.SmartInventoryProvider",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.pixlfox.scriptablemc.core
2+
3+
import java.util.logging.Level
4+
import java.util.logging.LogRecord
5+
import java.util.logging.Logger
6+
7+
class ScriptablePluginLogger(private val context: ScriptablePluginContext) : Logger(context.javaPlugin.description.prefix ?: context.javaPlugin.description.name, null) {
8+
init {
9+
parent = context.javaPlugin.server.logger.parent
10+
level = Level.ALL
11+
}
12+
13+
override fun log(logRecord: LogRecord) {
14+
logRecord.message = "[${context.pluginName}] ${logRecord.message}"
15+
super.log(logRecord)
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.pixlfox.scriptablemc.core
2+
3+
import org.bukkit.Bukkit
4+
import org.bukkit.scheduler.BukkitTask
5+
6+
class ScriptablePluginScheduler(private val context: ScriptablePluginContext) {
7+
private val serverScheduler = Bukkit.getScheduler()
8+
private val tasks = mutableListOf<BukkitTask>()
9+
10+
fun runTaskTimer(run: () -> Unit, delay: Long, period: Long): BukkitTask {
11+
val task = serverScheduler.runTaskTimer(context.javaPlugin, Runnable { run.invoke() }, delay, period)
12+
tasks.add(task)
13+
return task
14+
}
15+
16+
fun cancelAllTasks() {
17+
for(task in tasks) {
18+
if(!task.isCancelled) {
19+
task.cancel()
20+
}
21+
}
22+
}
23+
}

ScriptableMC-Engine-Core/src/main/kotlin/com/smc/utils/Http.kt

-46
This file was deleted.

0 commit comments

Comments
 (0)