Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {

allprojects {
group = "pl.spcode.navauth"
version = "0.1.4-SNAPSHOT"
version = "0.1.5-SNAPSHOT"
}

tasks.register("formatAll") {
Expand Down
6 changes: 3 additions & 3 deletions navauth-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies {
api(project(":navauth-api"))

// EternalCode Multification
api("com.eternalcode:multification-core:1.2.2")
api("com.eternalcode:multification-okaeri:1.2.2")
api("com.eternalcode:multification-core:1.2.3")
api("com.eternalcode:multification-okaeri:1.2.3")

implementation("com.google.inject:guice:7.0.0")
api("com.google.code.gson:gson:2.13.2")
Expand All @@ -17,7 +17,7 @@ dependencies {
api("com.j256.ormlite:ormlite-jdbc:6.1")

// config
api("eu.okaeri:okaeri-configs-yaml-snakeyaml:6.0.0-beta.3")
api("eu.okaeri:okaeri-configs-yaml-snakeyaml:6.0.0-beta.27")

// crypto
implementation("at.favre.lib:bcrypt:0.10.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
"Minecraft login plugin built for speed, security, and seamless player authentication.",
authors = {"Navio1430"})
public class Bootstrap {
@Inject private Logger logger;
@Inject private Injector injector;

@Subscribe
void onProxyInitialization(final ProxyInitializeEvent event) {
private static NavAuthVelocity instance;

@Inject
private Bootstrap(Logger logger, Injector injector) {
logger.info("Bootstrapping velocity plugin...");
NavAuthVelocity instance = injector.getInstance(NavAuthVelocity.class);
instance.init(event, this);
instance = injector.getInstance(NavAuthVelocity.class);
instance.init();
}

@Subscribe
private void onProxyInitializeEvent(ProxyInitializeEvent event) {
instance.onProxyInitializeEvent(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.google.inject.Key
import com.google.inject.Singleton
import com.velocitypowered.api.command.CommandSource
import com.velocitypowered.api.event.Subscribe
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent
import com.velocitypowered.api.plugin.annotation.DataDirectory
import com.velocitypowered.api.proxy.ProxyServer
Expand Down Expand Up @@ -68,26 +67,19 @@ constructor(
val proxyServer: ProxyServer,
@param:DataDirectory val dataDirectory: Path,
val metricsFactory: Metrics.Factory,
) {
) : VelocityPluginProvider {

private val logger: Logger = LoggerFactory.getLogger(NavAuthVelocity::class.java)

lateinit var pluginInstance: Bootstrap
// chicken or egg problem, unfortunately
var pluginInstance: Bootstrap? = null
lateinit var injector: Injector

lateinit var liteCommands: LiteCommands<CommandSource>

fun init(event: ProxyInitializeEvent, pluginInstance: Bootstrap) {
fun init() {
try {
logger.info("Initializing NavAuth plugin...")
this.pluginInstance = pluginInstance

// initialize bstats
val pluginId = 28777
metricsFactory.make(pluginInstance, pluginId)

// register self as listener because of the shutdown event
proxyServer.eventManager.register(pluginInstance, this)

val generalConfigModule =
YamlConfigModule(
Expand All @@ -113,7 +105,7 @@ constructor(
EventsModule(),
VelocityMultificationsModule(velocityViewerProvider),
VelocityCommandsModule(),
SchedulerModule(pluginInstance, proxyServer.scheduler),
SchedulerModule(this, proxyServer.scheduler),
HttpClientModule(),
DataPersistenceModule(),
ServicesModule(),
Expand All @@ -128,6 +120,19 @@ constructor(

val apiImpl = injector.getInstance(NavAuthApiImpl::class.java)
NavAuthAPI.setAPIInstance(apiImpl)
} catch (ex: Exception) {
logger.error("Could not initialize NavAuth plugin, shutting down the server...", ex)
proxyServer.shutdown(Component.text("NavAuth initialization failure"))
}
}

fun onProxyInitializeEvent(pluginInstance: Bootstrap) {
try {
this.pluginInstance = pluginInstance

// initialize bstats
val pluginId = 28777
metricsFactory.make(pluginInstance, pluginId)

registerListeners(injector)
registerCommands(injector)
Expand Down Expand Up @@ -165,16 +170,24 @@ constructor(
}

fun registerListeners(injector: Injector) {
// register self as listener because of the shutdown event
proxyServer.eventManager.register(pluginInstance, this)

val listeners = VelocityListenersRegistry.getWithInjection(injector)
listeners.forEach { proxyServer.eventManager.register(pluginInstance, it) }
}

@Suppress("UNNECESSARY_SAFE_CALL")
@Subscribe
fun shutdown(proxyShutdownEvent: ProxyShutdownEvent) {
fun shutdown(event: ProxyShutdownEvent) {
injector?.getInstance(DatabaseManager::class.java)?.closeConnections()
liteCommands?.unregister()

logger.info("Goodbye!")
}

override fun provideInstance(): Bootstrap {
require(pluginInstance != null) { "plugin was not initialized yet" }
return pluginInstance!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* NavAuth
* Copyright © 2026 Oliwier Fijas (Navio1430)
*
* NavAuth is free software; You can redistribute it and/or modify it under the terms of:
* the GNU Affero General Public License version 3 as published by the Free Software Foundation.
*
* NavAuth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with NavAuth. If not, see <https://www.gnu.org/licenses/>
* and navigate to version 3 of the GNU Affero General Public License.
*
*/

package pl.spcode.navauth.velocity

interface VelocityPluginProvider {
fun provideInstance(): Bootstrap
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ package pl.spcode.navauth.velocity.module

import com.google.inject.AbstractModule
import com.velocitypowered.api.scheduler.Scheduler
import pl.spcode.navauth.velocity.Bootstrap
import pl.spcode.navauth.velocity.VelocityPluginProvider
import pl.spcode.navauth.velocity.scheduler.NavAuthScheduler

class SchedulerModule(val plugin: Bootstrap, val scheduler: Scheduler) : AbstractModule() {
class SchedulerModule(val pluginProvider: VelocityPluginProvider, val scheduler: Scheduler) :
AbstractModule() {

override fun configure() {
bind(NavAuthScheduler::class.java).toInstance(NavAuthScheduler(plugin, scheduler))
bind(NavAuthScheduler::class.java).toInstance(NavAuthScheduler(pluginProvider, scheduler))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ package pl.spcode.navauth.velocity.scheduler
import com.velocitypowered.api.scheduler.ScheduledTask
import com.velocitypowered.api.scheduler.Scheduler
import java.util.function.Consumer
import pl.spcode.navauth.velocity.Bootstrap
import pl.spcode.navauth.velocity.VelocityPluginProvider

class NavAuthScheduler(private val plugin: Bootstrap, private val scheduler: Scheduler) {
class NavAuthScheduler(
private val pluginProvider: VelocityPluginProvider,
private val scheduler: Scheduler,
) {

fun buildTask(runnable: Runnable): Scheduler.TaskBuilder {
return scheduler.buildTask(plugin, runnable)
return scheduler.buildTask(pluginProvider.provideInstance(), runnable)
}

fun buildTask(consumer: Consumer<ScheduledTask>): Scheduler.TaskBuilder {
return scheduler.buildTask(plugin, consumer)
return scheduler.buildTask(pluginProvider.provideInstance(), consumer)
}
}
Loading