Merge pull request #11 from SKBotNL/main
Use new DiamondBank-OG API
This commit was merged in pull request #11.
This commit is contained in:
9 files changed
+40
-68
No files matched your search
+1
-1
Submodule libs/DiamondBank-OG updated: 677ce502e0...0a642bb496.
+1
-1
Submodule libs/Utilities-OG updated: ed7f99d354...fc93c2ed4f.
@@ -3,24 +3,26 @@ package net.trueog.questsOG
|
||||
import java.io.File
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
|
||||
class Config {
|
||||
class Config private constructor() {
|
||||
lateinit var redisUrl: String
|
||||
|
||||
/** @return True if successful */
|
||||
fun load(): Boolean {
|
||||
val file = File(QuestsOG.plugin.dataFolder, "config.yml")
|
||||
if (!file.exists()) {
|
||||
QuestsOG.plugin.saveDefaultConfig()
|
||||
}
|
||||
val config = YamlConfiguration.loadConfiguration(file)
|
||||
companion object {
|
||||
fun create(): Config? {
|
||||
val config = Config()
|
||||
val file = File(QuestsOG.plugin.dataFolder, "config.yml")
|
||||
if (!file.exists()) {
|
||||
QuestsOG.plugin.saveDefaultConfig()
|
||||
}
|
||||
val yamlConfig = YamlConfiguration.loadConfiguration(file)
|
||||
|
||||
try {
|
||||
redisUrl = config.get("redisUrl") as String
|
||||
} catch (_: Exception) {
|
||||
QuestsOG.plugin.logger.severe("Failed to parse config option \"redisUrl\" as a string")
|
||||
return false
|
||||
}
|
||||
try {
|
||||
config.redisUrl = yamlConfig.get("redisUrl") as String
|
||||
} catch (_: Exception) {
|
||||
QuestsOG.plugin.logger.severe("Failed to parse config option \"redisUrl\" as a string")
|
||||
return null
|
||||
}
|
||||
|
||||
return true
|
||||
return config
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,16 +26,19 @@ class QuestsOG : JavaPlugin() {
|
||||
MiniMessage.builder()
|
||||
.tags(TagResolver.builder().resolver(StandardTags.color()).resolver(StandardTags.reset()).build())
|
||||
.build()
|
||||
|
||||
fun isRedisInitialized() = ::redis.isInitialized
|
||||
}
|
||||
|
||||
override fun onEnable() {
|
||||
plugin = this
|
||||
|
||||
Companion.config = Config()
|
||||
if (!Companion.config.load()) {
|
||||
Bukkit.getPluginManager().disablePlugin(this)
|
||||
return
|
||||
}
|
||||
Companion.config =
|
||||
Config.create()
|
||||
?: run {
|
||||
Bukkit.getPluginManager().disablePlugin(this)
|
||||
return
|
||||
}
|
||||
|
||||
redis = Redis()
|
||||
if (!redis.testConnection()) {
|
||||
@@ -81,7 +84,9 @@ class QuestsOG : JavaPlugin() {
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
redis.shutdown()
|
||||
if (isRedisInitialized()) {
|
||||
redis.shutdown()
|
||||
}
|
||||
|
||||
scope.cancel()
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.trueog.questsOG.quests
|
||||
|
||||
import net.luckperms.api.node.types.PermissionNode
|
||||
import net.trueog.diamondbankog.PostgreSQL
|
||||
import net.trueog.questsOG.BooleanRequirement
|
||||
import net.trueog.questsOG.MainThreadBlock.runOnMainThread
|
||||
import net.trueog.questsOG.ProgressRequirement
|
||||
@@ -54,16 +53,10 @@ class HomesFive : Quest {
|
||||
}
|
||||
|
||||
private suspend fun fetchRequirements(player: Player): Requirements? {
|
||||
val playerShardsResult = QuestsOG.diamondBankAPI.getPlayerShards(player.uniqueId, PostgreSQL.ShardType.ALL)
|
||||
val playerShards =
|
||||
playerShardsResult.getOrElse {
|
||||
val totalShards =
|
||||
QuestsOG.diamondBankAPI.getTotalShards(player.uniqueId).getOrElse {
|
||||
return null
|
||||
}
|
||||
if (playerShards.isNeededShardTypeNull(PostgreSQL.ShardType.ALL)) {
|
||||
return null
|
||||
}
|
||||
val totalShards =
|
||||
playerShards.shardsInBank!! + playerShards.shardsInInventory!! + playerShards.shardsInEnderChest!!
|
||||
|
||||
val ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.trueog.questsOG.quests
|
||||
|
||||
import net.luckperms.api.node.types.PermissionNode
|
||||
import net.trueog.diamondbankog.PostgreSQL
|
||||
import net.trueog.questsOG.BooleanRequirement
|
||||
import net.trueog.questsOG.MainThreadBlock.runOnMainThread
|
||||
import net.trueog.questsOG.ProgressRequirement
|
||||
@@ -33,16 +32,10 @@ class HomesFour : Quest {
|
||||
}
|
||||
|
||||
private suspend fun fetchRequirements(player: Player): Requirements? {
|
||||
val playerShardsResult = QuestsOG.diamondBankAPI.getPlayerShards(player.uniqueId, PostgreSQL.ShardType.ALL)
|
||||
val playerShards =
|
||||
playerShardsResult.getOrElse {
|
||||
val totalShards =
|
||||
QuestsOG.diamondBankAPI.getTotalShards(player.uniqueId).getOrElse {
|
||||
return null
|
||||
}
|
||||
if (playerShards.isNeededShardTypeNull(PostgreSQL.ShardType.ALL)) {
|
||||
return null
|
||||
}
|
||||
val totalShards =
|
||||
playerShards.shardsInBank!! + playerShards.shardsInInventory!! + playerShards.shardsInEnderChest!!
|
||||
|
||||
val ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.trueog.questsOG.quests
|
||||
|
||||
import net.luckperms.api.node.types.PermissionNode
|
||||
import net.trueog.diamondbankog.PostgreSQL
|
||||
import net.trueog.questsOG.MainThreadBlock.runOnMainThread
|
||||
import net.trueog.questsOG.ProgressRequirement
|
||||
import net.trueog.questsOG.QuestsOG
|
||||
@@ -46,16 +45,10 @@ class HomesSix : Quest {
|
||||
)
|
||||
|
||||
private suspend fun fetchRequirements(player: Player): Requirements? {
|
||||
val playerShardsResult = QuestsOG.diamondBankAPI.getPlayerShards(player.uniqueId, PostgreSQL.ShardType.ALL)
|
||||
val playerShards =
|
||||
playerShardsResult.getOrElse {
|
||||
val totalShards =
|
||||
QuestsOG.diamondBankAPI.getTotalShards(player.uniqueId).getOrElse {
|
||||
return null
|
||||
}
|
||||
if (playerShards.isNeededShardTypeNull(PostgreSQL.ShardType.ALL)) {
|
||||
return null
|
||||
}
|
||||
val totalShards =
|
||||
playerShards.shardsInBank!! + playerShards.shardsInInventory!! + playerShards.shardsInEnderChest!!
|
||||
|
||||
val ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.trueog.questsOG.quests
|
||||
|
||||
import net.luckperms.api.node.types.PermissionNode
|
||||
import net.trueog.diamondbankog.PostgreSQL
|
||||
import net.trueog.questsOG.BooleanRequirement
|
||||
import net.trueog.questsOG.MainThreadBlock.runOnMainThread
|
||||
import net.trueog.questsOG.ProgressRequirement
|
||||
@@ -27,16 +26,10 @@ class HomesThree : Quest {
|
||||
}
|
||||
|
||||
private suspend fun fetchRequirements(player: Player): Requirements? {
|
||||
val playerShardsResult = QuestsOG.diamondBankAPI.getPlayerShards(player.uniqueId, PostgreSQL.ShardType.ALL)
|
||||
val playerShards =
|
||||
playerShardsResult.getOrElse {
|
||||
val totalShards =
|
||||
QuestsOG.diamondBankAPI.getTotalShards(player.uniqueId).getOrElse {
|
||||
return null
|
||||
}
|
||||
if (playerShards.isNeededShardTypeNull(PostgreSQL.ShardType.ALL)) {
|
||||
return null
|
||||
}
|
||||
val totalShards =
|
||||
playerShards.shardsInBank!! + playerShards.shardsInInventory!! + playerShards.shardsInEnderChest!!
|
||||
|
||||
val ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.trueog.questsOG.quests
|
||||
|
||||
import net.luckperms.api.node.types.PermissionNode
|
||||
import net.trueog.diamondbankog.PostgreSQL
|
||||
import net.trueog.questsOG.MainThreadBlock.runOnMainThread
|
||||
import net.trueog.questsOG.ProgressRequirement
|
||||
import net.trueog.questsOG.QuestsOG
|
||||
@@ -19,16 +18,10 @@ class HomesTwo : Quest {
|
||||
)
|
||||
|
||||
private suspend fun fetchRequirements(player: Player): Requirements? {
|
||||
val playerShardsResult = QuestsOG.diamondBankAPI.getPlayerShards(player.uniqueId, PostgreSQL.ShardType.ALL)
|
||||
val playerShards =
|
||||
playerShardsResult.getOrElse {
|
||||
val totalShards =
|
||||
QuestsOG.diamondBankAPI.getTotalShards(player.uniqueId).getOrElse {
|
||||
return null
|
||||
}
|
||||
if (playerShards.isNeededShardTypeNull(PostgreSQL.ShardType.ALL)) {
|
||||
return null
|
||||
}
|
||||
val totalShards =
|
||||
playerShards.shardsInBank!! + playerShards.shardsInInventory!! + playerShards.shardsInEnderChest!!
|
||||
|
||||
val ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE)
|
||||
|
||||
|
||||
Reference in new issue
Block a user