Skip to content

Commit

Permalink
♻️ Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nlkomaru committed Jan 31, 2022
1 parent 2196fd7 commit 976bf7a
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 115 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {
val exposedVersion: String by project
dependencies {
compileOnly("io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT")
implementation("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT")
implementation("net.kyori:adventure-platform-bukkit:4.0.1")
Expand All @@ -50,8 +50,8 @@ dependencies {
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
implementation("com.google.api-client:google-api-client:1.33.0")
implementation("com.google.oauth-client:google-oauth-client-jetty:1.32.1")
implementation("com.google.api-client:google-api-client:1.33.1")
implementation("com.google.oauth-client:google-oauth-client-jetty:1.33.0")
implementation("com.google.apis:google-api-services-sheets:v4-rev20210629-1.32.1")
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright © 2022 Nikomaru <[email protected]>
# Copyright © 2022 Nikomaru <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -14,4 +14,4 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
kotlin.code.style=official
exposedVersion=0.37.2
exposedVersion=0.37.3
7 changes: 3 additions & 4 deletions src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class RaceAssist : SuspendingJavaPlugin() {
registerEvents()

if (!VaultAPI.setupEconomy()) {
plugin!!.logger.info(Lang.getText("no-economy-plugin-found-disabling-vault", Locale.getDefault()))
plugin.logger.info(Lang.getText("no-economy-plugin-found-disabling-vault", Locale.getDefault()))
server.pluginManager.disablePlugin(this)
return
}
}

private fun settingDatabase() {
org.jetbrains.exposed.sql.Database.connect(
url = "jdbc:sqlite:${plugin!!.dataFolder}${File.separator}RaceAssist.db",
url = "jdbc:sqlite:${plugin.dataFolder}${File.separator}RaceAssist.db",
driver = "org.sqlite.JDBC"
)
transaction {
Expand Down Expand Up @@ -97,8 +97,7 @@ class RaceAssist : SuspendingJavaPlugin() {
}

companion object {
var plugin: RaceAssist? = null

lateinit var plugin: RaceAssist
val raceID = mutableListOf<String>()

fun setRaceID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import java.security.GeneralSecurityException

object GoogleAuthorizeUtil {

private val credentialsFilePath = File(plugin!!.dataFolder, "credentials.json")
private val credentialsFilePath = File(plugin.dataFolder, "credentials.json")

@Throws(IOException::class, GeneralSecurityException::class)
fun authorize(spreadsheetId: String): Credential {
val tokensDirectoryPath = File(File(plugin!!.dataFolder, "tokens"), "${spreadsheetId}_tokens")
val tokensDirectoryPath = File(File(plugin.dataFolder, "tokens"), "${spreadsheetId}_tokens")
if (!tokensDirectoryPath.exists()) {
tokensDirectoryPath.mkdirs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OpenBetGuiCommand : BaseCommand() {
@Subcommand("bet open")
@CommandCompletion("@RaceID")
fun openVending(player: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SetBetCommand : BaseCommand() {
@Subcommand("can")
@CommandCompletion("@RaceID on|off")
fun setCanBet(player: Player, @Single raceID: String, @Single type: String) {
plugin!!.launch {
plugin.launch {
if (!raceExist(raceID)) {
player.sendMessage(MessageFormat.format(Lang.getText("no-exist-this-raceid-race", player.locale()), raceID))
return@launch
Expand Down Expand Up @@ -77,7 +77,7 @@ class SetBetCommand : BaseCommand() {
@Subcommand("rate")
@CommandCompletion("@RaceID")
fun setRate(player: Player, @Single raceID: String, @Single rate: Int) {
plugin!!.launch {
plugin.launch {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@launch
Expand All @@ -97,12 +97,13 @@ class SetBetCommand : BaseCommand() {
}
}
player.sendMessage(MessageFormat.format(Lang.getText("change-bet-rate-message", player.locale()), raceID, rate))

}

@Subcommand("delete")
@CommandCompletion("@RaceID")
fun delete(player: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
Expand Down Expand Up @@ -132,7 +133,7 @@ class SetBetCommand : BaseCommand() {
@CommandCompletion("@RaceID")
fun revert(player: Player, @Single raceID: String) {
val eco: Economy = VaultAPI.getEconomy()!!
plugin!!.launch {
plugin.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
Expand Down Expand Up @@ -199,7 +200,7 @@ class SetBetCommand : BaseCommand() {
@Subcommand("sheet")
@CommandCompletion("@RaceID")
fun sheet(player: Player, @Single raceID: String, @Single sheetId: String) {
plugin!!.launch {
plugin.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
Expand All @@ -221,7 +222,7 @@ class SetBetCommand : BaseCommand() {
@Subcommand("list")
@CommandCompletion("@RaceID")
fun list(player: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BetChestGui {
val players: ArrayList<UUID> = ArrayList()
val odds: HashMap<UUID, Double> = HashMap()
var sum = 0
plugin!!.launch {
plugin.launch {
val rate: Int = newSuspendedTransaction(Dispatchers.IO) {
BetSetting.select { BetSetting.raceID eq raceID }.first()[BetSetting.returnPercent]
}
Expand Down
12 changes: 1 addition & 11 deletions src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,15 @@ import org.bukkit.configuration.file.FileConfiguration
object Config {
var config: FileConfiguration? = null

var host: String? = null
var port = 0
var database: String? = null
var username: String? = null
var password: String? = null
var threshold: Int? = null
var discordWebHook: String? = null
var betUnit: Int = 0

fun load() {
if (config != null) {
plugin!!.reloadConfig()
plugin.reloadConfig()
}

host = config!!.getString("SQLSettings.host")
port = config!!.getInt("SQLSetting.port")
database = config!!.getString("SQLSetting.database")
username = config!!.getString("SQLSetting.username")
password = config!!.getString("SQLSetting.password")
threshold = config!!.getInt("RaceSetting.threshold")
betUnit = config!!.getInt("RaceSetting.bet")
discordWebHook = config!!.getString("NetworkSettings.discord")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AudiencesCommand : BaseCommand() {
@Subcommand("join")
@CommandCompletion("@RaceID")
private fun join(sender: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (!getRaceExist(raceID)) {
sender.sendMessage(text(Lang.getText("not-found-this-race", sender.locale()), TextColor.color(RED)))
return@launch
Expand Down Expand Up @@ -77,7 +77,7 @@ class AudiencesCommand : BaseCommand() {
@Subcommand("list")
@CommandCompletion("@RaceID")
private fun list(sender: CommandSender, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
val player = sender as Player
if (RaceCommand.getRaceCreator(raceID) != player.uniqueId) {
player.sendMessage(text(Lang.getText("only-race-creator-can-display", sender.locale()), TextColor.color(RED)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PlaceCommands : BaseCommand() {
@Subcommand("reverse")
@CommandCompletion("@RaceID")
fun reverse(sender: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != sender.uniqueId) {
sender.sendMessage(text(Lang.getText("only-race-creator-can-setting", sender.locale()), TextColor.color(RED)))
return@launch
Expand All @@ -68,7 +68,7 @@ class PlaceCommands : BaseCommand() {
@CommandCompletion("@RaceID")
fun central(sender: CommandSender, @Single raceID: String) {
val player = sender as Player
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != player.uniqueId) {
player.sendMessage(text(Lang.getText("only-race-creator-can-setting", sender.locale()), TextColor.color(RED)))
return@launch
Expand All @@ -82,7 +82,7 @@ class PlaceCommands : BaseCommand() {
@Subcommand("degree")
@CommandCompletion("@RaceID")
fun degree(player: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != player.uniqueId) {
player.sendMessage(text(Lang.getText("only-race-creator-can-setting", player.locale()), TextColor.color(RED)))
return@launch
Expand Down Expand Up @@ -152,7 +152,7 @@ class PlaceCommands : BaseCommand() {
@Syntax("[RaceID] <lap>")
fun setLap(sender: CommandSender, @Single raceID: String, @Single lap: Int) {
val player = sender as Player
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != player.uniqueId) {
player.sendMessage(text(Lang.getText("only-race-creator-can-setting", sender.locale()), TextColor.color(RED)))
return@launch
Expand All @@ -174,7 +174,7 @@ class PlaceCommands : BaseCommand() {
@Subcommand("set")
@CommandCompletion("@RaceID in|out")
fun set(player: Player, @Single raceID: String, @Single type: String) {
plugin!!.launch {
plugin.launch {

if (RaceCommand.getRaceCreator(raceID) == null) {
player.sendMessage(text(Lang.getText("no-exist-race", player.locale()), TextColor.color(RED)))
Expand Down Expand Up @@ -208,7 +208,7 @@ class PlaceCommands : BaseCommand() {

@Subcommand("finish")
fun finish(sender: CommandSender) {
plugin!!.launch {
plugin.launch {
val player = sender as Player
if (Objects.isNull(canSetOutsideCircuit[player.uniqueId]) && Objects.isNull(canSetInsideCircuit[player.uniqueId])) {
player.sendMessage(Lang.getText("now-you-not-setting-mode", sender.locale()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PlayerCommand : BaseCommand() {
@CommandCompletion("@RaceID @players")
private fun addPlayer(player: Player, raceID: String, @Single onlinePlayer: OnlinePlayer) {

plugin!!.launch {
plugin.launch {
val jockey = onlinePlayer.player
if (RaceCommand.getRaceCreator(raceID) != player.uniqueId) {
player.sendMessage(
Expand Down Expand Up @@ -85,7 +85,7 @@ class PlayerCommand : BaseCommand() {
@Subcommand("remove")
@CommandCompletion("@RaceID")
private fun removePlayer(sender: Player, @Single raceID: String, @Single onlinePlayer: OnlinePlayer) {
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != sender.uniqueId) {
sender.sendMessage(Component.text(Lang.getText("only-race-creator-can-delete", sender.locale()), TextColor.color(NamedTextColor.RED)))
return@launch
Expand All @@ -102,7 +102,7 @@ class PlayerCommand : BaseCommand() {
@Subcommand("delete")
@CommandCompletion("@RaceID")
private fun deletePlayer(sender: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != sender.uniqueId) {
sender.sendMessage(Component.text(Lang.getText("only-race-creator-can-delete", sender.locale()), TextColor.color(NamedTextColor.RED)))
return@launch
Expand All @@ -119,7 +119,7 @@ class PlayerCommand : BaseCommand() {
@Subcommand("list")
@CommandCompletion("@RaceID")
private fun displayPlayerList(sender: Player, @Single raceID: String) {
plugin!!.launch {
plugin.launch {
if (RaceCommand.getRaceCreator(raceID) != sender.uniqueId) {
sender.sendMessage(
Component.text(
Expand Down
Loading

0 comments on commit 976bf7a

Please sign in to comment.