Skip to content

Commit

Permalink
Disable the plugin if the server is in online mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru21 committed Aug 23, 2023
1 parent 2d4a9de commit 931f2a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,4 +1,4 @@
kotlin.code.style = official
minecraftVersion = 1.17
pluginName = Authy
pluginVersion = 3.4.2
pluginVersion = 3.5.0
20 changes: 17 additions & 3 deletions src/main/kotlin/me/iru/Authy.kt
Expand Up @@ -28,6 +28,8 @@ class Authy : JavaPlugin() {

val prefix = "${ChatColor.DARK_GRAY}[${ChatColor.GOLD}$pluginName${ChatColor.DARK_GRAY}]"

private var initialized = false

companion object {
lateinit var instance: Authy private set
lateinit var translations: Translations private set
Expand All @@ -40,10 +42,17 @@ class Authy : JavaPlugin() {
override fun onEnable() {
instance = this

translations = Translations()
if(server.onlineMode) {
server.consoleSender.sendMessage("$prefix ${ChatColor.RED}Server is in online mode! Switch to offline mode and restart the server!")
server.pluginManager.disablePlugin(this)
return
}

playerData = PlayerData()
Migration.updateSystem()
DatabaseMigration.tryMigrate()

translations = Translations()
loginProcess = LoginProcess()
authManager = AuthManager()
session = Session()
Expand All @@ -65,6 +74,8 @@ class Authy : JavaPlugin() {

with(commandFilter) { registerFilter() }

initialized = true

server.consoleSender.sendMessage("$prefix ${ChatColor.GREEN}Enabled $version")

val players = server.onlinePlayers
Expand All @@ -84,8 +95,11 @@ class Authy : JavaPlugin() {
}

override fun onDisable() {
DatabaseMigration.saveLastDatabaseType()
playerData.databaseConnection.shutdownConnections()
if(initialized) {
DatabaseMigration.saveLastDatabaseType()
playerData.databaseConnection.shutdownConnections()
initialized = false
}
server.consoleSender.sendMessage("$prefix ${ChatColor.RED}Disabled $version")
}

Expand Down

0 comments on commit 931f2a5

Please sign in to comment.