Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e5549cd
completed JSON -> table converter and working base for http client
zNotChill Apr 13, 2025
050f35a
Convert everything to Twine API
zNotChill Apr 16, 2025
f57609d
Rewrote the command system to use Twine, minor code cleanup
zNotChill Apr 18, 2025
5938a5d
chore: move to using `mavenLocal` for twine implementation
cerqiest Apr 19, 2025
cf2ffd7
feat: offline players
cerqiest Apr 19, 2025
6bb577b
chore: resolve early merge conflicts to avoid hassle when merging mater
cerqiest Apr 19, 2025
14ce687
chore: resolve early merge conflicts to avoid hassle when merging later
cerqiest Apr 19, 2025
72bbb46
Merge branch 'twine-api' of https://github.com/luarocket/rocket into …
cerqiest Apr 19, 2025
4812195
feat: autoload scripts
cerqiest Apr 19, 2025
2d338e2
fix: autocomplete reload scripts correctly on windows
cerqiest Apr 19, 2025
38d7593
feat: add custom fallback prefixes
cerqiest Apr 19, 2025
a9510b5
feat: server global and implementation
cerqiest Apr 19, 2025
ab2eb43
fix: remove getEntity function because LuaEntity is not implemented
cerqiest Apr 19, 2025
06c34a4
Add Rocket.instance
zNotChill Apr 19, 2025
ad7817e
Merge pull request #38 from LuaRocket/twine-api-server
zNotChill Apr 19, 2025
fd14692
Merge branch 'main' of github.com:LuaRocket/rocket into twine-api
zNotChill Apr 19, 2025
38e80ac
Bump Twine version to 1.0.2
zNotChill Apr 19, 2025
1ab9677
fix: deprecation of permissionMessage property
cerqiest Apr 19, 2025
d682b97
test: initialize unit testing stuff
gibbiemonster Apr 19, 2025
262dfde
chore: re-add a mistakenly removed restart function
gibbiemonster Apr 19, 2025
025d244
feat: add `toMiniMessage` extension function on component and refacto…
cerqiest Apr 20, 2025
94a62e6
Add `@Global` for auto global registering
zNotChill Apr 20, 2025
3a075cb
Prepare and solve old issues ready for merge
zNotChill Apr 21, 2025
c625951
Change any instance of TwineError to RocketError
zNotChill Apr 21, 2025
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: 11 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ group = "dev.znci"
version = "1.0-SNAPSHOT"

repositories {
mavenLocal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/") {
name = "papermc-repo"
}
maven("https://oss.sonatype.org/content/groups/public/") {
name = "sonatype"
}
maven("https://jitpack.io")
}

dependencies {
Expand All @@ -42,8 +44,13 @@ dependencies {
implementation("org.luaj:luaj-jse:3.0.1")
implementation("net.luckperms:api:5.4")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("dev.znci:twine:v1.0.4")
implementation("org.reflections:reflections:0.10.2")

testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.12.2")
testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.45.1")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
}

val targetJavaVersion = 21
Expand All @@ -69,7 +76,6 @@ tasks.withType<DokkaTask>().configureEach {
named("main") {
moduleName.set("Rocket Java API")
includes.from("Rocket.md")

}
}
}
Expand All @@ -87,4 +93,8 @@ tasks.withType(xyz.jpenilla.runtask.task.AbstractRun::class) {
tasks.runServer {
minecraftVersion("1.21.4")
jvmArgs("-Dcom.mojang.eula.agree=true")
}

tasks.test {
useJUnitPlatform()
}
21 changes: 14 additions & 7 deletions src/main/kotlin/dev/znci/rocket/Rocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ import dev.znci.rocket.i18n.LocaleManager
import dev.znci.rocket.scripting.ScriptManager
import dev.znci.rocket.scripting.events.EventListener
import dev.znci.rocket.scripting.GlobalInitializer
import dev.znci.rocket.scripting.annotations.Global
import org.bukkit.plugin.java.JavaPlugin
import org.reflections.Reflections
import java.io.File

class Rocket : JavaPlugin() {
open class Rocket : JavaPlugin() {
companion object {
lateinit var instance: Rocket
private set
}

private var defaultLocale: String = "en_GB"

override fun onEnable() {
instance = this

// Create the plugin data folder
saveDefaultConfig()

Expand Down Expand Up @@ -62,12 +71,10 @@ class Rocket : JavaPlugin() {
EventListener.registerAllEvents()

// Register globals
val globalInitialized = GlobalInitializer.init()
if (globalInitialized) {
logger.info("Globals successfully initialized")
} else {
logger.severe("Globals failed to initialize")
}
GlobalInitializer.registerAll()

// Automatically load all scripts in the scripts folder
ScriptManager.loadScripts()

logger.info("Rocket plugin enabled")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/znci/rocket/i18n/LocaleManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object LocaleManager {

val formattedMessage = try {
message.format(*formatArgs.map { it.toString() }.toTypedArray())
} catch (e: Exception) {
} catch (_: Exception) {
message
}

Expand Down
51 changes: 39 additions & 12 deletions src/main/kotlin/dev/znci/rocket/scripting/GlobalInitializer.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
/**
* Copyright 2025 znci
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.znci.rocket.scripting

import dev.znci.rocket.Rocket
import dev.znci.rocket.scripting.annotations.Global
import dev.znci.rocket.scripting.api.RocketError
import dev.znci.rocket.scripting.globals.tables.LuaCommands
import dev.znci.rocket.scripting.globals.tables.LuaHTTPClient
import dev.znci.rocket.scripting.globals.tables.LuaLocations
import dev.znci.rocket.scripting.globals.tables.LuaPlayers
import dev.znci.rocket.scripting.globals.tables.SimpleTest
import dev.znci.rocket.scripting.globals.tables.LuaServer
import dev.znci.rocket.scripting.globals.values.TestValue
import dev.znci.twine.TwineValueBase
import org.bukkit.plugin.java.JavaPlugin
import org.reflections.Reflections

/**
* The `GlobalInitializer` object is responsible for initializing and registering global objects
Expand All @@ -12,19 +35,23 @@ import dev.znci.rocket.scripting.globals.values.TestValue
*/
object GlobalInitializer {
/**
* Initializes the global objects and registers them with the `ScriptManager`.
* Uses reflection to find all classes marked with `@Global`.
*
* It returns `true` upon successful registration of these objects.
*
* @return `true` if the global objects were successfully initialized and registered.
* If a non-TwineValueBase value is marked with `@Global`, it throws an error.
*/
fun init(): Boolean {
ScriptManager.registerGlobal(SimpleTest())
ScriptManager.registerGlobal(TestValue())
ScriptManager.registerGlobal(LuaPlayers())
ScriptManager.registerGlobal(LuaLocations())
//ScriptManager.registerGlobal(GamemodeEnum())
fun registerAll() {
val reflections = Reflections("dev.znci.rocket")
val globalClasses = reflections.getTypesAnnotatedWith(Global::class.java)

globalClasses.forEach { globalClass ->
if (TwineValueBase::class.java.isAssignableFrom(globalClass)) {
val instance = globalClass.getDeclaredConstructor().newInstance() as TwineValueBase
ScriptManager.registerGlobal(instance)
} else {
throw RocketError("@Global annotated class does not extend TwineValueBase.")
}
}

return true
Rocket.instance.logger.info { "Successfully registered ${globalClasses.size} globals." }
}
}
Loading