Skip to content

Commit 4e3ddac

Browse files
committed
ref: core loader package
1 parent 611e1e9 commit 4e3ddac

File tree

19 files changed

+83
-20
lines changed

19 files changed

+83
-20
lines changed

common/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ val modVersion: String by project
1919
val minecraftVersion: String by project
2020
val modId: String by project
2121
val fabricLoaderVersion: String by project
22+
val kotlinVersion: String by project
2223
val kotlinxCoroutinesVersion: String by project
2324
val discordIPCVersion: String by project
2425

@@ -47,6 +48,7 @@ dependencies {
4748

4849
// Add Kotlin
4950
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
51+
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
5052

5153
// Baritone
5254
modImplementation("baritone-api:baritone-unoptimized-fabric:1.10.2") { isTransitive = false }

common/src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.lambda.config.serializer.*
2323
import com.lambda.config.serializer.gui.CustomModuleWindowSerializer
2424
import com.lambda.config.serializer.gui.ModuleTagSerializer
2525
import com.lambda.config.serializer.gui.TagWindowSerializer
26-
import com.lambda.core.Loader
26+
import com.lambda.core.loader.Loader
2727
import com.lambda.gui.impl.clickgui.windows.tag.CustomModuleWindow
2828
import com.lambda.gui.impl.clickgui.windows.tag.TagWindow
2929
import com.lambda.module.tag.ModuleTag

common/src/main/kotlin/com/lambda/command/CommandRegistry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.lambda.command
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.config.configurations.LambdaConfig
22-
import com.lambda.core.Loadable
22+
import com.lambda.core.loader.Loadable
2323
import com.lambda.util.reflections.getInstances
2424

2525
/**

common/src/main/kotlin/com/lambda/core/PingManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.core
1919

20+
import com.lambda.core.loader.Loadable
2021
import com.lambda.event.events.PacketEvent
2122
import com.lambda.event.events.TickEvent
2223
import com.lambda.event.listener.SafeListener.Companion.listener

common/src/main/kotlin/com/lambda/core/TimerManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.core
1919

20+
import com.lambda.core.loader.Loadable
2021
import com.lambda.event.EventFlow.post
2122
import com.lambda.event.events.ClientEvent
2223

common/src/main/kotlin/com/lambda/core/Loadable.kt renamed to common/src/main/kotlin/com/lambda/core/loader/Loadable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.core
18+
package com.lambda.core.loader
1919

2020
/**
2121
* Represents a loadable object.

common/src/main/kotlin/com/lambda/core/Loader.kt renamed to common/src/main/kotlin/com/lambda/core/loader/Loader.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.core
18+
package com.lambda.core.loader
1919

2020
import com.lambda.Lambda
2121
import com.lambda.Lambda.LOG
22+
import com.lambda.graphics.renderer.gui.font.FontRenderer
2223
import com.lambda.util.Communication.ascii
2324
import com.lambda.util.reflections.getInstances
25+
import kotlin.reflect.full.findAnnotation
2426
import kotlin.system.measureTimeMillis
2527
import kotlin.time.DurationUnit
2628
import kotlin.time.toDuration
@@ -31,16 +33,22 @@ object Loader {
3133
val runtime: String
3234
get() = "${(System.currentTimeMillis() - started).toDuration(DurationUnit.MILLISECONDS)}"
3335

34-
private val loadables = getInstances<Loadable> { forPackages("com.lambda") }
36+
private val loadables =
37+
getInstances<Loadable> { forPackages("com.lambda") }
38+
.associateWith { it::class.findAnnotation<LoaderOrder>() }
39+
.toList()
40+
.sortedBy { (_, annotation) -> annotation?.phase }
41+
.sortedByDescending { (_, annotation) -> annotation?.priority }
42+
.map { it.first }
3543

3644
fun initialize() {
3745
ascii.split("\n").forEach { LOG.info(it) }
3846
LOG.info("Initializing ${Lambda.MOD_NAME} ${Lambda.VERSION}")
3947

40-
val initTime = measureTimeMillis {
48+
val time = measureTimeMillis {
4149
loadables.forEach { LOG.info(it.load()) }
4250
}
4351

44-
LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized (${initTime}ms)")
52+
LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized in $time ms")
4553
}
4654
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.core.loader
19+
20+
import kotlin.annotation.AnnotationTarget.CLASS
21+
22+
/**
23+
* Defines the order of execution for the loader, must be paired with an object that
24+
* implements [Loadable]
25+
*/
26+
@Target(CLASS)
27+
annotation class LoaderOrder(val phase: Phase, val priority: Int = 0)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.core.loader
19+
20+
enum class Phase {
21+
Pre,
22+
Config,
23+
Modules,
24+
Resources,
25+
Render,
26+
Post;
27+
}

common/src/main/kotlin/com/lambda/friend/FriendManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.lambda.friend
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.config.configurations.FriendConfig
22-
import com.lambda.core.Loadable
22+
import com.lambda.core.loader.Loadable
2323
import com.mojang.authlib.GameProfile
2424
import net.minecraft.client.network.OtherClientPlayerEntity
2525
import java.util.*

0 commit comments

Comments
 (0)