Skip to content

Commit

Permalink
♻️ Cleanup, bugfixes, new features, dependency bugs, added about 47 n…
Browse files Browse the repository at this point in the history
…ew bugs to fix later

Took 2 hours 0 minutes
  • Loading branch information
itsTyrion committed Oct 22, 2024
1 parent 99e7a57 commit f73c430
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 218 deletions.
85 changes: 34 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id "org.jetbrains.kotlin.jvm" version "1.9.10"
id "org.jetbrains.kotlin.kapt" version "1.9.10"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "net.kyori.blossom" version "2.1.0"
}

configurations {
bungeecord
id "org.jetbrains.kotlin.jvm" version "2.0.21"
id "org.jetbrains.kotlin.kapt" version "2.0.21"
id "com.gradleup.shadow" version "8.3.3"
}

repositories {
Expand All @@ -21,78 +16,66 @@ repositories {
name "PaperMC"
url uri("https://repo.papermc.io/repository/maven-public/")
}
maven { url uri("https://jitpack.io") }
}

dependencies {
implementation "org.xerial:sqlite-jdbc:3.40.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.10"
implementation "org.yaml:snakeyaml:2.0"
bungeecord "org.slf4j:slf4j-api:2.0.5"
bungeecord "org.slf4j:slf4j-simple:2.0.5"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:1.9.10"
compileOnly "net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT"
compileOnly "com.velocitypowered:velocity-api:3.2.0-SNAPSHOT"
kapt "com.velocitypowered:velocity-api:3.2.0-SNAPSHOT"
implementation "org.xerial:sqlite-jdbc:3.46.1.3"
implementation "com.mysql:mysql-connector-j:9.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.21"
implementation "org.yaml:snakeyaml:2.2"
implementation "org.slf4j:slf4j-api:2.0.12"
implementation "org.slf4j:slf4j-simple:2.0.12"
compileOnly "net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT"
compileOnly "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT"
compileOnly "de.itsTyrion:PluginAnnotationProcessor:1.4"
kapt "de.itsTyrion:PluginAnnotationProcessor:1.4"
}

group = "lu.r3flexi0n"
version = "8.4.2"
version = "8.5.0"
description = "BungeeOnlineTime"

tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.release = 17
options.deprecation true
kotlin {
jvmToolchain 17
}

sourceSets {
main.blossom.kotlinSources {
property("version", version)
}
kapt.arguments {
arg "mcPluginVersion", version
}

shadowJar {
minimize() { exclude(dependency("org.xerial:sqlite-jdbc")) }
archiveClassifier = ""
minimize() {
exclude(dependency("org.xerial:sqlite-jdbc"))
exclude(dependency("com.mysql:mysql-connector-j"))
}

relocate "kotlin", "de.itsTyrion.shaded.kotlin"
relocate "org.yaml", "de.itsTyrion.shaded.snakeyaml"

def sqlite = "org/sqlite/native"
exclude "$sqlite/*/ppc64/**", "$sqlite/*/arm*/**", "$sqlite/*/x86/**" // uncommon architectures for MC servers
exclude "$sqlite/Linux-*/**", "$sqlite/Mac/**", "$sqlite/FreeBSD/**" // and uncommon OS' for MC servers
}

tasks.register("bungeecord", ShadowJar) {
from sourceSets.main.output
configurations = [project.configurations.runtimeClasspath, project.configurations.bungeecord]
archiveClassifier = "bungeecord"
minimize() { exclude(dependency("org.xerial:sqlite-jdbc")) }
mergeServiceFiles()

relocate "kotlin", "de.itsTyrion.shaded.kotlin"
relocate "org.yaml", "de.itsTyrion.shaded.snakeyaml"
relocate "org.slf4j", "de.itsTyrion.shaded.slf4j"

def sqlite = "org/sqlite/native"
exclude "$sqlite/*/ppc64/**", "$sqlite/*/arm*/**", "$sqlite/*/x86/**" // uncommon architectures for MC servers
exclude "$sqlite/Linux-*/**", "$sqlite/Mac/**", "$sqlite/FreeBSD/**" // and uncommon OS' for MC servers
def base = "org/sqlite/native"
exclude "$base/*/ppc64/**", "$base/*/riscv64/**", "$base/*/arm*/**", "$base/*/x86/**" // uncommon architectures for MC servers
exclude "$base/Linux-*/**", "$base/Mac/**", "$base/FreeBSD/**" // and uncommon OS' for MC servers
}

tasks.register("fat", ShadowJar) {
from sourceSets.main.output
configurations = [project.configurations.runtimeClasspath]
archiveClassifier = "fat"
minimize() { exclude(dependency("org.xerial:sqlite-jdbc")) }
minimize() {
exclude(dependency("org.xerial:sqlite-jdbc"))
exclude(dependency("com.mysql:mysql-connector-j"))
}

mergeServiceFiles()

relocate "kotlin", "de.itsTyrion.shaded.kotlin"
relocate "org.yaml", "de.itsTyrion.shaded.snakeyaml"
relocate "org.slf4j", "de.itsTyrion.shaded.slf4j"
}

gradle.beforeProject {
generateTemplates
}

build {
dependsOn([shadowJar, bungeecord, fat])
dependsOn([shadowJar, fat])
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kapt.include.compile.classpath=false
3 changes: 0 additions & 3 deletions src/main/kotlin-templates/BuildInfo.kt.peb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,52 +1,41 @@
package lu.r3flexi0n.bungeeonlinetime.bungee

import de.itsTyrion.pluginAnnotation.bungee.BungeePlugin
import lu.r3flexi0n.bungeeonlinetime.common.OnlineTimePlugin
import lu.r3flexi0n.bungeeonlinetime.common.config.Config
import lu.r3flexi0n.bungeeonlinetime.common.config.ConfigLoader
import lu.r3flexi0n.bungeeonlinetime.common.db.Database
import lu.r3flexi0n.bungeeonlinetime.common.db.MySQLDatabase
import lu.r3flexi0n.bungeeonlinetime.common.db.SQLiteDatabase
import lu.r3flexi0n.bungeeonlinetime.common.objects.OnlineTimePlayer
import lu.r3flexi0n.bungeeonlinetime.common.utils.Utils
import lu.r3flexi0n.bungeeonlinetime.common.utils.Messaging
import net.md_5.bungee.api.plugin.Plugin
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import java.io.IOException
import java.nio.file.Path
import java.util.UUID
import java.util.concurrent.TimeUnit

class BungeeOnlineTimePlugin : Plugin() {
@BungeePlugin(name = "BungeeOnlineTime", author = "itsTyrion, R3fleXi0n")
class BungeeOnlineTimePlugin : Plugin(), OnlineTimePlugin {

lateinit var config: Config
override lateinit var config: Config
override lateinit var database: Database
override val dataPath: Path = dataFolder.toPath()

lateinit var database: Database
override val onlineTimePlayers = HashMap<UUID, OnlineTimePlayer>()

val onlineTimePlayers = HashMap<UUID, OnlineTimePlayer>()

val pluginMessageChannel = "bungeeonlinetime:get"

val logger: Logger = LoggerFactory.getLogger(super.getLogger().name)
override val logger: Logger = LoggerFactory.getLogger(super.getLogger().name)

override fun onEnable() {
try {
config = ConfigLoader.load(dataFolder.toPath(), logger)
} catch (ex: IOException) {
logger.error("Error while creating or loading. Disabling plugin...", ex)
logger.error("Error while creating or loading config. Disabling plugin...", ex)
return
}

database = if (config.mySQL.enabled) {
MySQLDatabase(config.mySQL)
} else {
SQLiteDatabase(File(dataFolder, "BungeeOnlineTime.db"))
}

try {
logger.info("Connecting to ${database.dbName}...")
database.openConnection()
database.createTable()
database.createIndex()
logger.info("Successfully connected to ${database.dbName}")
connectDB()
} catch (ex: Exception) {
logger.error("Error while connecting to ${database.dbName}. Disabling plugin...", ex)
return
Expand All @@ -59,17 +48,24 @@ class BungeeOnlineTimePlugin : Plugin() {
proxy.pluginManager.registerListener(this, OnlineTimeListener(this))

if (config.plugin.usePlaceholderApi) {
proxy.registerChannel(pluginMessageChannel)
val timerInterval = config.plugin.placeholderRefreshTimer
proxy.registerChannel(Messaging.CHANNEL_MAIN)
proxy.registerChannel(Messaging.CHANNEL_TOP)
val timerInterval = config.plugin.placeholderRefreshSeconds
if (timerInterval > 0) {
proxy.scheduler.schedule(this, {
for (player in proxy.players) {
val onlineTimePlayer = onlineTimePlayers[player.uniqueId] ?: continue
val arr = Utils.createPluginMessageArr(onlineTimePlayer, player.uniqueId)
val arr = Messaging.createMainArr(onlineTimePlayer, player.uniqueId)
if (arr != null)
player.server?.sendData(pluginMessageChannel, arr)
player.server?.sendData(Messaging.CHANNEL_MAIN, arr)
}
}, 0L, timerInterval.toLong(), TimeUnit.MINUTES)

val arr = Messaging.createTopArr(this)
for ((_, server) in proxy.servers) {
server.sendData(Messaging.CHANNEL_TOP, arr)
}

}, 0L, timerInterval.toLong(), TimeUnit.SECONDS)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.chat.TextComponent
import net.md_5.bungee.api.connection.ProxiedPlayer
import net.md_5.bungee.api.plugin.Command
import kotlin.math.max

class OnlineTimeCommand(private val plugin: BungeeOnlineTimePlugin, cmd: String, aliases: Array<String>) :
Command(cmd, null, *aliases) {
private val config = plugin.config
private val base = OnlineTimeCommandBase(plugin.logger, plugin.config, plugin.database) { plugin.onlineTimePlayers }
private val base = OnlineTimeCommandBase(plugin)

private fun checkPermission(sender: CommandSender, permission: String): Boolean {
if (!sender.hasPermission(permission)) {
send(sender, config.language.noPermission)
send(sender, plugin.config.language.noPermission)
return false
}
return true
}

override fun execute(sender: CommandSender, args: Array<String>) {
if (sender !is ProxiedPlayer) {
send(sender, config.language.onlyPlayer)
send(sender, plugin.config.language.onlyPlayer)
return
}
val arg0 = if (args.isNotEmpty()) args[0].lowercase() else ""
Expand All @@ -43,7 +43,7 @@ class OnlineTimeCommand(private val plugin: BungeeOnlineTimePlugin, cmd: String,
} else if ((size == 1 || size == 2) && arg0 == "top") {

if (checkPermission(sender, "onlinetime.top")) {
val page = (args[1].toIntOrNull() ?: 1).coerceAtLeast(1)
val page = if (size == 1) 1 else max(1, args[1].toIntOrNull() ?: 1)
base.sendTopOnlineTimes(page) { msg, placeholders -> send(sender, msg, placeholders) }
}

Expand All @@ -62,8 +62,15 @@ class OnlineTimeCommand(private val plugin: BungeeOnlineTimePlugin, cmd: String,
if (checkPermission(sender, "onlinetime.resetall"))
base.sendResetAll { msg, placeholders -> send(sender, msg, placeholders) }

} else if (args.size == 1 && arg0 == "reload") {

if (checkPermission(sender, "onlinetime.reload")) {
plugin.reloadConfig()
send(sender, plugin.config.language.configReloaded)
}

} else {
send(sender, config.language.help)
send(sender, plugin.config.language.help)
}
}

Expand All @@ -75,6 +82,6 @@ class OnlineTimeCommand(private val plugin: BungeeOnlineTimePlugin, cmd: String,
message = message.replace(key, value.toString())
}
}
sender.sendMessage(*TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', message)))
sender.sendMessage(TextComponent.fromLegacy(ChatColor.translateAlternateColorCodes('&', message)))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lu.r3flexi0n.bungeeonlinetime.bungee

import lu.r3flexi0n.bungeeonlinetime.common.objects.OnlineTimePlayer
import lu.r3flexi0n.bungeeonlinetime.common.utils.Utils
import lu.r3flexi0n.bungeeonlinetime.common.utils.Messaging
import lu.r3flexi0n.bungeeonlinetime.common.utils.asyncTask
import net.md_5.bungee.api.event.PlayerDisconnectEvent
import net.md_5.bungee.api.event.PostLoginEvent
Expand Down Expand Up @@ -41,9 +41,13 @@ class OnlineTimeListener(private val plugin: BungeeOnlineTimePlugin) : Listener
} else {
onlineTimePlayer.leaveDisabledServer()
}
if (usePlaceholderApi && onlineTimePlayer.savedOnlineTime != null) {
val arr = Utils.createPluginMessageArr(onlineTimePlayer, player.uniqueId)
server.sendData(plugin.pluginMessageChannel, arr)
if (usePlaceholderApi) {
if (onlineTimePlayer.savedOnlineTime != null) {
val arr = Messaging.createMainArr(onlineTimePlayer, player.uniqueId)
server.sendData(Messaging.CHANNEL_MAIN, arr)
}
val arr = Messaging.createTopArr(plugin)
server.sendData(Messaging.CHANNEL_TOP, arr)
}
}

Expand Down
Loading

0 comments on commit f73c430

Please sign in to comment.