Skip to content

Commit a652e48

Browse files
authored
Merge pull request #7 from integr-dev/develop
Add BStats integration and update documentation
2 parents a73ba3f + 3695e39 commit a652e48

82 files changed

Lines changed: 2972 additions & 259 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ All script files should be placed in the `scripts/` directory in your server's r
8383
Every script file must evaluate to an object that extends `ManagedLifecycle`. This class provides the necessary hooks for the script engine to manage the script's lifecycle.
8484

8585
```kotlin
86-
import net.integr.backbone.Backbone
87-
import net.integr.backbone.events.TickEvent
88-
import net.integr.backbone.systems.event.BackboneEventHandler
89-
import net.integr.backbone.systems.hotloader.lifecycle.ManagedLifecycle
90-
import net.integr.backbone.systems.hotloader.lifecycle.sustained
91-
9286
// Each script must return an object that extends ManagedLifecycle.
9387
object : ManagedLifecycle() {
9488
// 'sustained' properties persist their values across script reloads.
@@ -151,10 +145,6 @@ You can pull in external libraries directly from Maven repositories using the `@
151145
// Depend on a library from that repository
152146
@file:DependsOn("com.github.javafaker:javafaker:1.0.2")
153147

154-
import com.github.javafaker.Faker
155-
import kotlin.script.experimental.dependencies.DependsOn
156-
import kotlin.script.experimental.dependencies.Repository
157-
158148
// ... inside your script
159149
val faker = Faker()
160150
val randomName = faker.name().fullName()
@@ -260,10 +250,11 @@ class MyCustomEvent(val message: String) : Event()
260250
@BackboneEventHandler(EventPriority.THREE_BEFORE)
261251
fun onMyCustomEvent(event: MyCustomEvent) {
262252
println("Received custom event: ${event.message}")
253+
event.setCallback("yay!")
263254
}
264255

265256
// Fire the custom event from anywhere in your code
266-
EventBus.post(MyCustomEvent("Hello, world!"))
257+
val callback = EventBus.post(MyCustomEvent("Hello, world!")) // "yay!"
267258
```
268259

269260
### Commands
@@ -363,19 +354,17 @@ object MyItem : CustomItem("my_item", MyItemState) {
363354
}
364355

365356
// Define the state for the custom item
366-
object MyItemState : CustomItemState("default") {
367-
override fun generate(): ItemStack {
368-
return ItemStack(Material.DIAMOND_SWORD).apply {
369-
itemMeta = itemMeta.apply {
370-
setDisplayName("My Custom Sword")
371-
}
357+
object MyItemState : CustomItemState(Material.DIAMOND_SWORD, "default") {
358+
override fun populate(stack: ItemStack) {
359+
stack.applyMeta {
360+
isUnbreakable = true
372361
}
373362
}
374363
}
375364

376365
// In your ManagedLifecycle's onLoad:
377366
override fun onLoad() {
378-
Backbone.Handlers.ITEM.register(MyItem)
367+
Backbone.Handler.ITEM.register(MyItem)
379368
}
380369
```
381370

build.gradle.kts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "net.integr"
10-
version = "1.1.0"
10+
version = "1.2.0"
1111

1212
repositories {
1313
mavenCentral()
@@ -19,12 +19,15 @@ repositories {
1919
maven("https://repo.extendedclip.com/releases/")
2020
}
2121

22+
val paper = "io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT"
23+
2224
dependencies {
23-
implementation("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
25+
compileOnly(paper)
26+
27+
implementation("org.bstats:bstats-bukkit:3.2.1")
2428

2529
implementation("me.clip:placeholderapi:2.12.2")
2630

27-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
2831
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
2932

3033
implementation(kotlin("stdlib"))
@@ -38,16 +41,18 @@ dependencies {
3841

3942
implementation("org.apache.ivy:ivy:2.5.2")
4043

41-
// The core engine
4244
implementation("tools.jackson.core:jackson-databind:3.0.4")
4345
implementation("tools.jackson.dataformat:jackson-dataformat-yaml:3.0.4")
4446
implementation("tools.jackson.module:jackson-module-kotlin:3.0.4")
4547

4648
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
49+
4750
testImplementation("org.mockito:mockito-core:5.2.0")
4851
testImplementation("org.mockito:mockito-inline:5.2.0")
4952
testImplementation("org.mockito:mockito-junit-jupiter:5.2.0")
53+
5054
testImplementation("org.xerial:sqlite-jdbc:3.46.0.0")
55+
testImplementation(paper)
5156
}
5257

5358
tasks {
@@ -80,5 +85,5 @@ tasks.processResources {
8085
}
8186

8287
tasks.withType<ShadowJar> {
83-
mergeServiceFiles()
88+
relocate("org.bstats", "net.integr.backbone.systems.bstats")
8489
}

src/main/kotlin/net/integr/backbone/Backbone.kt

Lines changed: 155 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,73 +25,219 @@ import org.bukkit.NamespacedKey
2525
import org.bukkit.event.HandlerList
2626
import org.bukkit.event.Listener
2727
import org.bukkit.plugin.java.JavaPlugin
28-
28+
import org.jetbrains.annotations.ApiStatus
29+
30+
/**
31+
*
32+
* The main entry point for the Backbone API.
33+
*
34+
* This object provides access to various Backbone systems and utilities.
35+
*
36+
* @since 1.0.0
37+
*/
2938
object Backbone {
30-
//TODO: dialogues
39+
//TODO: dialogues, command help builder
40+
/**
41+
* Backbones internal storage pool. **Important:** Do not use this.
42+
* Create a new pool instead:
43+
* ```kotlin
44+
* val pool = ResourcePool.fromStorage("my-server")
45+
* ```
46+
*
47+
* @since 1.0.0
48+
*/
49+
@ApiStatus.Internal
3150
val STORAGE_POOL = ResourcePool.fromStorage("backbone")
51+
52+
/**
53+
* Backbones internal config pool. **Important:** Do not use this.
54+
* Create a new pool instead:
55+
* ```kotlin
56+
* val pool = ResourcePool.fromConfig("my-server")
57+
* ```
58+
*
59+
* @since 1.0.0
60+
*/
61+
@ApiStatus.Internal
3262
val CONFIG_POOL = ResourcePool.fromConfig("backbone")
3363

64+
/**
65+
* Internal script pool.
66+
*
67+
* @since 1.0.0
68+
*/
69+
@ApiStatus.Internal
3470
val SCRIPT_POOL = ResourcePool.getScripts()
3571

36-
val ROOT_PERMISSION by lazy {
37-
PermissionNode("backbone")
38-
}
39-
72+
/**
73+
* Backbones internal logger. **Important:** Do not use this for your own logging.
74+
* Create a new logger instead:
75+
* ```kotlin
76+
* val logger = BackboneLogger("my-server")
77+
* ```
78+
*
79+
* @since 1.0.0
80+
*/
81+
@ApiStatus.Internal
82+
val LOGGER = BackboneLogger("backbone")
83+
84+
/**
85+
* Backbones root permission. **Important:** Do not use this for your own permission checks.
86+
* Create a new node instead:
87+
* ```kotlin
88+
* val node = PermissionNode("my-server")
89+
* ```
90+
*
91+
* @since 1.0.0
92+
*/
93+
@ApiStatus.Internal
94+
val ROOT_PERMISSION = PermissionNode("backbone")
95+
96+
/**
97+
* Backbones placeholders. **Important:** Do not use this for your own custom placeholders.
98+
* Create a new group instead:
99+
* ```kotlin
100+
* val group = PlaceholderGroup("1.0.0", "my-server")
101+
* ```
102+
*
103+
* @since 1.0.0
104+
*/
105+
@get:ApiStatus.Internal
40106
val PLACEHOLDER_GROUP by lazy {
41107
PlaceholderGroup(VERSION, "backbone")
42108
}
43109

110+
/**
111+
* The internally checked plugin instance.
112+
* Null if we are in a testing environment.
113+
*
114+
* @since 1.0.0
115+
*/
44116
private val pluginInternal: JavaPlugin? by lazy {
45117
Utils.tryOrNull { JavaPlugin.getPlugin(BackboneServer::class.java) } // For testing purposes
46118
}
47119

120+
/**
121+
* The global backbone plugin instance.
122+
*
123+
* @since 1.0.0
124+
*/
48125
val PLUGIN
49126
get() = pluginInternal!!
50127

128+
/**
129+
* The global server instance.
130+
*
131+
* @since 1.0.0
132+
*/
51133
val SERVER
52134
get() = PLUGIN.server
53135

136+
/**
137+
* The version of the backbone plugin.
138+
*
139+
* @since 1.0.0
140+
*/
54141
val VERSION
55142
get() = PLUGIN.pluginMeta.version
56143

57-
val LOGGER: BackboneLogger by lazy {
58-
BackboneLogger("backbone", pluginInternal)
59-
}
60144

145+
/**
146+
* Registers a listener to the server's plugin manager and the internal event bus.
147+
*
148+
* @param listener The listener to register.
149+
*
150+
* @since 1.0.0
151+
*/
61152
fun registerListener(listener: Listener) {
62153
LOGGER.info("Registering listener: ${listener.javaClass.name}")
63154
SERVER.pluginManager.registerEvents(listener, PLUGIN)
64155
EventBus.register(listener)
65156
}
66157

158+
/**
159+
* Removes a listener from the server's plugin manager and the internal event bus.
160+
*
161+
* @param listener The listener to register.
162+
*
163+
* @since 1.0.0
164+
*/
67165
fun unregisterListener(listener: Listener) {
68166
LOGGER.info("Unregistering listener: ${listener.javaClass.name}")
69167
HandlerList.unregisterAll(listener)
70168
EventBus.unregister(listener)
71169
}
72170

171+
/**
172+
* Dispatches a task to be run on the main thread of the server.
173+
*
174+
* @param block The block of code to run.
175+
*
176+
* @since 1.0.0
177+
*/
73178
fun dispatchMain(block: () -> Unit) {
74179
SERVER.scheduler.runTask(PLUGIN, block)
75180
}
76181

182+
/**
183+
* Dispatches a task to be run asynchronously on the server.
184+
*
185+
* @param block The block of code to run.
186+
*
187+
* @since 1.0.0
188+
*/
77189
fun dispatch(block: () -> Unit) {
78190
SERVER.scheduler.runTaskAsynchronously(PLUGIN, block)
79191
}
80192

193+
/**
194+
* Gets a namespaced key.
195+
*
196+
* @param namespace The namespace of the key.
197+
* @param key The key.
198+
* @return A namespaced key.
199+
*
200+
* @since 1.0.0
201+
*/
81202
fun getKey(namespace: String, key: String): NamespacedKey {
82203
return NamespacedKey(namespace, key)
83204
}
84205

206+
/**
207+
* Backbone's handlers for use in your scripts.
208+
*
209+
* @since 1.1.0
210+
*/
85211
object Handler {
212+
/**
213+
* The command handler used to register and manage commands.
214+
*
215+
* @since 1.1.0
216+
*/
86217
val COMMAND
87218
get() = CommandHandler
88219

220+
/**
221+
* The item handler used to manage items.
222+
*
223+
* @since 1.1.0
224+
*/
89225
val ITEM
90226
get() = ItemHandler
91227

228+
/**
229+
* The entity handler used to manage entities.
230+
*
231+
* @since 1.1.0
232+
*/
92233
val ENTITY
93234
get() = EntityHandler
94235

236+
/**
237+
* The gui handler used to manage guis.
238+
*
239+
* @since 1.1.0
240+
*/
95241
val GUI
96242
get() = GuiHandler
97243
}

src/main/kotlin/net/integr/backbone/BackboneLogger.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package net.integr.backbone
1515

16-
import org.bukkit.plugin.java.JavaPlugin
1716
import java.nio.file.Path
1817
import java.text.SimpleDateFormat
1918
import java.util.Date
@@ -22,7 +21,18 @@ import kotlin.io.path.appendText
2221
import kotlin.io.path.createDirectories
2322
import kotlin.io.path.createFile
2423

25-
class BackboneLogger(name: String, private val plugin: JavaPlugin?) : Logger(name, null) {
24+
/**
25+
26+
* A custom logger for the Backbone plugin.
27+
*
28+
* This logger provides colored console output and logs severe messages to a file.
29+
* It also allows for deriving sub-loggers with specific names.
30+
*
31+
* @param name The name of the logger.
32+
*
33+
* @since 1.0.0
34+
*/
35+
class BackboneLogger(name: String) : Logger(name, null) {
2636
private val logFile = Path.of("./logs/backbone.log")
2737
private val customFormat = CustomFormat(name, true)
2838
private val customFileFormat = CustomFormat(name, false)
@@ -39,13 +49,22 @@ class BackboneLogger(name: String, private val plugin: JavaPlugin?) : Logger(nam
3949
addHandler(CustomHandler())
4050
}
4151

52+
53+
/**
54+
* Derive a new logger with a sub-name.
55+
*
56+
* @param subName The sub-name for the new logger.
57+
* @return A new `BackboneLogger` instance.
58+
*
59+
* @since 1.0.0
60+
*/
4261
fun derive(subName: String): BackboneLogger {
43-
return BackboneLogger("$name.$subName", plugin)
62+
return BackboneLogger("$name.$subName")
4463
}
4564

4665
private inner class CustomHandler : Handler() {
4766
override fun publish(record: LogRecord) {
48-
if (!isLoggable(record) || plugin == null) return
67+
if (!isLoggable(record)) return
4968
val message = customFormat.format(record)
5069
val fileMessage = customFileFormat.format(record)
5170
println(message)

0 commit comments

Comments
 (0)