Merge pull request #11 from SKBotNL/master

Config improvements
This commit was merged in pull request #11.
This commit is contained in:
NotAlexNoyle authored and GitHub committed 2025-07-23 15:43:51 -04:00
commit 7425337115
22 files changed
+270 -250

No files matched your search

@@ -2,6 +2,7 @@ package net.trueog.diamondbankog
import kotlin.math.abs
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.InventoryExtensions.countDiamondBlocks
import net.trueog.diamondbankog.InventoryExtensions.countDiamonds
import net.trueog.diamondbankog.InventoryExtensions.countShards
@@ -21,7 +22,7 @@ internal object AutoCompress {
if (!player.hasPermission("diamondbank-og.compress")) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to compress."
"${config.prefix}<reset>: <red>You do not have permission to compress."
)
)
return@launch
@@ -64,7 +65,7 @@ internal object AutoCompress {
if (changeInDiamonds > emptySlots + leftOverSpaceDiamonds) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."
"${config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."
)
)
return@runOnMainThread
@@ -82,7 +83,7 @@ internal object AutoCompress {
if (changeInDiamondBlocks > emptySlots + leftOverSpaceDiamondBlocks) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."
"${config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."
)
)
return@runOnMainThread
@@ -94,7 +95,7 @@ internal object AutoCompress {
if (removeMap.isNotEmpty()) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
)
)
return@runOnMainThread
@@ -106,7 +107,7 @@ internal object AutoCompress {
if (addMap.isNotEmpty()) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
)
)
return@runOnMainThread
@@ -116,7 +117,7 @@ internal object AutoCompress {
if (removeMap.isNotEmpty()) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
)
)
return@runOnMainThread
@@ -128,7 +129,7 @@ internal object AutoCompress {
if (addMap.isNotEmpty()) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
)
)
return@runOnMainThread
@@ -139,7 +140,7 @@ internal object AutoCompress {
if (removeMap.isNotEmpty()) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."
)
)
return@runOnMainThread
@@ -1,6 +1,7 @@
package net.trueog.diamondbankog
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.PostgreSQL.ShardType
import org.bukkit.Material
@@ -16,7 +17,7 @@ internal object AutoDeposit {
if (!player.hasPermission("diamondbank-og.deposit")) {
player.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have permission to deposit.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>You do not have permission to deposit.")
)
return
}
@@ -42,7 +43,7 @@ internal object AutoDeposit {
handleError(player.uniqueId, shards, null)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@withLockSuspend
@@ -4,7 +4,7 @@ import java.io.File
import kotlin.properties.Delegates
import org.bukkit.configuration.file.YamlConfiguration
internal object Config {
internal class Config private constructor() {
lateinit var prefix: String
lateinit var postgresUrl: String
lateinit var postgresUser: String
@@ -14,76 +14,76 @@ internal object Config {
var postgresLogLimit by Delegates.notNull<Int>()
lateinit var redisUrl: String
/** @return True if failed */
fun load(): Boolean {
val file = File(DiamondBankOG.plugin.dataFolder, "config.yml")
if (!file.exists()) {
DiamondBankOG.plugin.saveDefaultConfig()
}
val config = YamlConfiguration.loadConfiguration(file)
try {
prefix = config.get("prefix") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"prefix\" as a string")
return true
}
try {
postgresUrl = config.get("postgresUrl") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresUrl\" as a string")
return true
}
try {
postgresUser = config.get("postgresUser") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresUser\" as a string")
return true
}
try {
postgresPassword = config.get("postgresPassword") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresPassword\" as a string")
return true
}
try {
postgresTable = config.get("postgresTable") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresTable\" as a string")
return true
}
try {
postgresLogTable = config.get("postgresLogTable") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresLogTable\" as a string")
return true
}
try {
postgresLogLimit = config.get("postgresLogLimit") as Int
if (postgresLogLimit < 1) {
DiamondBankOG.plugin.logger.severe("\"postgresLogLimit\" cannot be less than 1")
return true
companion object {
fun create(): Config? {
val config = Config()
val file = File(DiamondBankOG.plugin.dataFolder, "config.yml")
if (!file.exists()) {
DiamondBankOG.plugin.saveDefaultConfig()
}
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe(
"Failed to parse config option \"postgresLogLimit\" as an unsigned integer"
)
return true
}
val yamlConfig = YamlConfiguration.loadConfiguration(file)
try {
redisUrl = config.get("redisUrl") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"redisUrl\" as a string")
return true
}
try {
config.prefix = yamlConfig.get("prefix") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"prefix\" as a string")
return null
}
return false
try {
config.postgresUrl = yamlConfig.get("postgresUrl") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresUrl\" as a string")
return null
}
try {
config.postgresUser = yamlConfig.get("postgresUser") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresUser\" as a string")
return null
}
try {
config.postgresPassword = yamlConfig.get("postgresPassword") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresPassword\" as a string")
return null
}
try {
config.postgresTable = yamlConfig.get("postgresTable") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresTable\" as a string")
return null
}
try {
config.postgresLogTable = yamlConfig.get("postgresLogTable") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresLogTable\" as a string")
return null
}
try {
config.postgresLogLimit = yamlConfig.get("postgresLogLimit") as Int
if (config.postgresLogLimit < 1) {
DiamondBankOG.plugin.logger.severe("\"postgresLogLimit\" cannot be less than 1")
return null
}
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"postgresLogLimit\" as an integer")
return null
}
try {
config.redisUrl = yamlConfig.get("redisUrl") as String
} catch (_: Exception) {
DiamondBankOG.plugin.logger.severe("Failed to parse config option \"redisUrl\" as a string")
return null
}
return config
}
}
}
@@ -17,11 +17,14 @@ internal class DiamondBankOG : JavaPlugin() {
val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
lateinit var plugin: DiamondBankOG
lateinit var config: Config
lateinit var postgreSQL: PostgreSQL
lateinit var redis: Redis
lateinit var luckPerms: LuckPerms
fun isPostgreSQLInitialised() = ::postgreSQL.isInitialized
fun isRedisInitialized() = ::redis.isInitialized
fun isPostgreSQLInitialized() = ::postgreSQL.isInitialized
var mm =
MiniMessage.builder()
@@ -42,10 +45,12 @@ internal class DiamondBankOG : JavaPlugin() {
override fun onEnable() {
plugin = this
if (Config.load()) {
Bukkit.getPluginManager().disablePlugin(this)
return
}
Companion.config =
Config.create()
?: run {
Bukkit.getPluginManager().disablePlugin(this)
return
}
postgreSQL = PostgreSQL()
try {
@@ -112,9 +117,13 @@ internal class DiamondBankOG : JavaPlugin() {
}
override fun onDisable() {
redis.shutdown()
if (isRedisInitialized()) {
redis.shutdown()
}
if (isPostgreSQLInitialised()) postgreSQL.pool.disconnect().get()
if (isPostgreSQLInitialized()) {
postgreSQL.pool.disconnect().get()
}
scope.cancel()
@@ -4,6 +4,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.AutoCompress.compress
import net.trueog.diamondbankog.AutoDeposit.deposit
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.InventoryExtensions.countTotal
import net.trueog.diamondbankog.MainThreadBlock.runOnMainThread
@@ -31,7 +32,7 @@ internal class Events : Listener {
if (DiamondBankOG.economyDisabled) {
event.player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return
@@ -80,7 +81,7 @@ internal class Events : Listener {
if (DiamondBankOG.economyDisabled) {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot pick up any economy-related items while the economy is disabled."
"${config.prefix}<reset>: <red>You cannot pick up any economy-related items while the economy is disabled."
)
)
event.isCancelled = true
@@ -134,7 +135,7 @@ internal class Events : Listener {
event.isCancelled = true
event.player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot drop any economy-related items while the economy is disabled."
"${config.prefix}<reset>: <red>You cannot drop any economy-related items while the economy is disabled."
)
)
return
@@ -184,7 +185,7 @@ internal class Events : Listener {
event.isCancelled = true
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot move any economy-related items while the economy is disabled."
"${config.prefix}<reset>: <red>You cannot move any economy-related items while the economy is disabled."
)
)
return
@@ -230,7 +231,7 @@ internal class Events : Listener {
event.isCancelled = true
event.player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."
"${config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."
)
)
return
@@ -273,7 +274,7 @@ internal class Events : Listener {
event.isCancelled = true
event.player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."
"${config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."
)
)
return
@@ -3,6 +3,7 @@ package net.trueog.diamondbankog
import kotlin.math.ceil
import kotlin.math.floor
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.MainThreadBlock.runOnMainThread
import net.trueog.diamondbankog.PostgreSQL.ShardType
@@ -85,7 +86,7 @@ internal object InventoryExtensions {
val result = DiamondBankOG.postgreSQL.addToPlayerShards(player.uniqueId, leftOver, ShardType.BANK)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: The change of $leftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been deposited into your bank."
"${config.prefix}<reset>: The change of $leftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been deposited into your bank."
)
)
return result.isFailure
@@ -111,14 +112,14 @@ internal object InventoryExtensions {
}
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: The change of ${leftOver - inventoryLeftOver} <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been added to your inventory, and the remaining $inventoryLeftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset> has been deposited into your bank."
"${config.prefix}<reset>: The change of ${leftOver - inventoryLeftOver} <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been added to your inventory, and the remaining $inventoryLeftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset> has been deposited into your bank."
)
)
return false
}
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: The change of $leftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been added to your inventory."
"${config.prefix}<reset>: The change of $leftOver <aqua>Diamond ${if (leftOver == 1) "Shard" else "Shards"} <reset>has been added to your inventory."
)
)
return false
@@ -152,7 +153,7 @@ internal object InventoryExtensions {
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: The change of $leftOver <aqua>Diamond${if (leftOver != 1) "s" else ""} <reset>has been added to your inventory."
"${config.prefix}<reset>: The change of $leftOver <aqua>Diamond${if (leftOver != 1) "s" else ""} <reset>has been added to your inventory."
)
)
return 0
@@ -202,7 +203,7 @@ internal object InventoryExtensions {
handleError(player.uniqueId, inventoryShards, null)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to recount the <aqua>Diamonds<red> amount in your inventory, try opening and closing your inventory to force a recount."
"${config.prefix}<reset>: <red>Something went wrong while trying to recount the <aqua>Diamonds<red> amount in your inventory, try opening and closing your inventory to force a recount."
)
)
}
@@ -8,6 +8,7 @@ import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
import java.sql.SQLException
import java.util.*
import kotlinx.coroutines.future.await
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
class PostgreSQL {
lateinit var pool: ConnectionPool<PostgreSQLConnection>
@@ -32,22 +33,22 @@ class PostgreSQL {
try {
pool =
PostgreSQLConnectionBuilder.createConnectionPool(
"${Config.postgresUrl}?user=${Config.postgresUser}&password=${Config.postgresPassword}"
"${config.postgresUrl}?user=${config.postgresUser}&password=${config.postgresPassword}"
)
val createTable =
pool.sendPreparedStatement(
"CREATE TABLE IF NOT EXISTS ${Config.postgresTable}(uuid UUID PRIMARY KEY, bank_shards INTEGER, inventory_shards INTEGER, ender_chest_shards INTEGER, total_shards INTEGER GENERATED ALWAYS AS ( COALESCE(bank_shards, 0) + COALESCE(inventory_shards, 0) + COALESCE(ender_chest_shards, 0) ) STORED)"
"CREATE TABLE IF NOT EXISTS ${config.postgresTable}(uuid UUID PRIMARY KEY, bank_shards INTEGER, inventory_shards INTEGER, ender_chest_shards INTEGER, total_shards INTEGER GENERATED ALWAYS AS ( COALESCE(bank_shards, 0) + COALESCE(inventory_shards, 0) + COALESCE(ender_chest_shards, 0) ) STORED)"
)
createTable.join()
val createTotalShardsIndex =
pool.sendPreparedStatement(
"CREATE INDEX IF NOT EXISTS idx_total_shards ON ${Config.postgresTable}(total_shards DESC)"
"CREATE INDEX IF NOT EXISTS idx_total_shards ON ${config.postgresTable}(total_shards DESC)"
)
createTotalShardsIndex.join()
val createLogTable =
pool.sendPreparedStatement(
"CREATE TABLE IF NOT EXISTS ${Config.postgresLogTable}(id SERIAL PRIMARY KEY, player_uuid UUID NOT NULL, transferred_shards INTEGER NOT NULL, player_to_uuid UUID, transaction_reason TEXT, notes TEXT, timestamp TIMESTAMPTZ DEFAULT NOW())"
"CREATE TABLE IF NOT EXISTS ${config.postgresLogTable}(id SERIAL PRIMARY KEY, player_uuid UUID NOT NULL, transferred_shards INTEGER NOT NULL, player_to_uuid UUID, transaction_reason TEXT, notes TEXT, timestamp TIMESTAMPTZ DEFAULT NOW())"
)
createLogTable.join()
// @formatter:off
@@ -55,11 +56,11 @@ class PostgreSQL {
pool.sendPreparedStatement(
"CREATE OR REPLACE FUNCTION fifo_limit_trigger() RETURNS TRIGGER AS $$" +
"DECLARE " +
"max_rows CONSTANT INTEGER := ${Config.postgresLogLimit};" +
"max_rows CONSTANT INTEGER := ${config.postgresLogLimit};" +
"BEGIN " +
"DELETE FROM ${Config.postgresLogTable} " +
"DELETE FROM ${config.postgresLogTable} " +
"WHERE id <= (" +
"SELECT id FROM ${Config.postgresLogTable} " +
"SELECT id FROM ${config.postgresLogTable} " +
"ORDER BY id DESC " +
"OFFSET max_rows LIMIT 1" +
");" +
@@ -72,7 +73,7 @@ class PostgreSQL {
val createTrigger =
pool.sendPreparedStatement(
"CREATE OR REPLACE TRIGGER fifo_limit_trigger\n" +
"AFTER INSERT ON ${Config.postgresLogTable}\n" +
"AFTER INSERT ON ${config.postgresLogTable}\n" +
"FOR EACH STATEMENT\n" +
"EXECUTE FUNCTION fifo_limit_trigger();"
)
@@ -95,7 +96,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"INSERT INTO ${Config.postgresTable}(uuid, ${type.string}) VALUES(?, ?) ON CONFLICT (uuid) DO UPDATE SET ${type.string} = excluded.${type.string}",
"INSERT INTO ${config.postgresTable}(uuid, ${type.string}) VALUES(?, ?) ON CONFLICT (uuid) DO UPDATE SET ${type.string} = excluded.${type.string}",
listOf(uuid, shards),
)
preparedStatement.await()
@@ -147,7 +148,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"SELECT bank_shards, inventory_shards, ender_chest_shards FROM ${Config.postgresTable} WHERE uuid = ? LIMIT 1",
"SELECT bank_shards, inventory_shards, ender_chest_shards FROM ${config.postgresTable} WHERE uuid = ? LIMIT 1",
listOf(uuid),
)
val result = preparedStatement.await()
@@ -189,7 +190,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"SELECT bank_shards, inventory_shards, ender_chest_shards FROM ${Config.postgresTable} WHERE uuid = ? LIMIT 1",
"SELECT bank_shards, inventory_shards, ender_chest_shards FROM ${config.postgresTable} WHERE uuid = ? LIMIT 1",
listOf(uuid),
)
val result = preparedStatement.await()
@@ -228,7 +229,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"SELECT ${type.string} FROM ${Config.postgresTable} WHERE uuid = ? LIMIT 1",
"SELECT ${type.string} FROM ${config.postgresTable} WHERE uuid = ? LIMIT 1",
listOf(uuid),
)
val result = preparedStatement.await()
@@ -256,7 +257,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"SELECT uuid, total_shards " +
"FROM ${Config.postgresTable} " +
"FROM ${config.postgresTable} " +
"ORDER BY total_shards DESC, uuid DESC OFFSET ? LIMIT 9",
listOf(offset),
)
@@ -295,7 +296,7 @@ class PostgreSQL {
"WITH ranked AS (" +
"SELECT " +
"uuid, total_shards, ROW_NUMBER() OVER (ORDER BY total_shards DESC, uuid DESC) AS rn " +
"FROM ${Config.postgresTable}" +
"FROM ${config.postgresTable}" +
"), " +
"target AS (" +
"SELECT rn, ((rn - 1) / 9) * 9 AS page_offset FROM ranked WHERE uuid = ?), " +
@@ -340,7 +341,7 @@ class PostgreSQL {
try {
val connection = pool.asSuspending.connect()
val preparedStatement =
connection.sendPreparedStatement("SELECT count(*) AS exact_count FROM ${Config.postgresTable}")
connection.sendPreparedStatement("SELECT count(*) AS exact_count FROM ${config.postgresTable}")
val result = preparedStatement.await()
if (result.rows.isNotEmpty()) {
@@ -371,7 +372,7 @@ class PostgreSQL {
val preparedStatement =
connection.sendPreparedStatement(
"INSERT INTO ${Config.postgresLogTable}(player_uuid, transferred_shards, player_to_uuid, transaction_reason, notes) " +
"INSERT INTO ${config.postgresLogTable}(player_uuid, transferred_shards, player_to_uuid, transaction_reason, notes) " +
"VALUES(?, ?, ?, ?, ?)",
listOf(playerUuid, transferredShards, playerToUuid, transactionReason, notes),
)
@@ -2,9 +2,10 @@ package net.trueog.diamondbankog
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisConnectionException
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
internal class Redis {
private val redisClient: RedisClient = RedisClient.create(Config.redisUrl)
private val redisClient: RedisClient = RedisClient.create(config.redisUrl)
/** @return True if failed */
fun testConnection(): Boolean {
@@ -1,6 +1,7 @@
package net.trueog.diamondbankog
import kotlin.math.floor
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.InventoryExtensions.withdraw
import org.bukkit.entity.Player
@@ -19,7 +20,7 @@ internal object WithdrawHelper {
handleError(player.uniqueId, shards, playerShards)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return -1
@@ -40,7 +41,7 @@ internal object WithdrawHelper {
)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Cannot use <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <red>in a transaction because you only have <yellow>$totalDiamonds <aqua>Diamond${if (totalDiamonds != "1.0") "s" else ""}<red>."
"${config.prefix}<reset>: <red>Cannot use <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <red>in a transaction because you only have <yellow>$totalDiamonds <aqua>Diamond${if (totalDiamonds != "1.0") "s" else ""}<red>."
)
)
return -1
@@ -51,7 +52,7 @@ internal object WithdrawHelper {
handleError(player.uniqueId, shards, playerShards)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return -1
@@ -64,7 +65,7 @@ internal object WithdrawHelper {
handleError(player.uniqueId, shards, playerShards)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return -1
@@ -78,7 +79,7 @@ internal object WithdrawHelper {
handleError(player.uniqueId, shards, playerShards)
player.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return -1
@@ -1,7 +1,7 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@@ -12,7 +12,7 @@ internal class AutoCompress : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return true
@@ -26,7 +26,7 @@ internal class AutoCompress : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.compress")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return true
@@ -36,21 +36,21 @@ internal class AutoCompress : CommandExecutor {
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autocompress", "false")
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully turned auto-compress <red>off<green>."
"${config.prefix}<reset>: <green>Successfully turned auto-compress <red>off<green>."
)
)
} else {
if (DiamondBankOG.redis.getValue("diamondbankog:${sender.uniqueId}:autodeposit") == "true") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <#FFA500>You cannot have both auto-compress and auto-deposit on at the same time, so auto-deposit has been turned <red>off<#FFA500>."
"${config.prefix}<reset>: <#FFA500>You cannot have both auto-compress and auto-deposit on at the same time, so auto-deposit has been turned <red>off<#FFA500>."
)
)
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autodeposit", "false")
}
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autocompress", "true")
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully turned auto-compress on.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <green>Successfully turned auto-compress on.")
)
}
return true
@@ -1,7 +1,7 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@@ -12,7 +12,7 @@ internal class AutoDeposit : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return true
@@ -26,7 +26,7 @@ internal class AutoDeposit : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.deposit")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return true
@@ -36,21 +36,21 @@ internal class AutoDeposit : CommandExecutor {
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autodeposit", "false")
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully turned auto-deposit <red>off<green>."
"${config.prefix}<reset>: <green>Successfully turned auto-deposit <red>off<green>."
)
)
} else {
if (DiamondBankOG.redis.getValue("diamondbankog:${sender.uniqueId}:autocompress") == "true") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <#FFA500>You cannot have both auto-deposit and auto-compress on at the same time, so auto-compress has been turned <red>off<#FFA500>."
"${config.prefix}<reset>: <#FFA500>You cannot have both auto-deposit and auto-compress on at the same time, so auto-compress has been turned <red>off<#FFA500>."
)
)
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autocompress", "false")
}
DiamondBankOG.redis.setValue("diamondbankog:${sender.uniqueId}:autodeposit", "true")
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully turned auto-deposit on.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <green>Successfully turned auto-deposit on.")
)
}
return true
@@ -4,8 +4,8 @@ import java.util.*
import kotlin.math.floor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.PlayerPrefix.getPrefix
import org.bukkit.Bukkit
import org.bukkit.command.Command
@@ -20,7 +20,7 @@ internal class Balance : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -29,7 +29,7 @@ internal class Balance : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.balance")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -41,7 +41,7 @@ internal class Balance : CommandExecutor {
if (args.isEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Please provide that name or UUID of the player that you want to check the balance of."
"${config.prefix}<reset>: <red>Please provide that name or UUID of the player that you want to check the balance of."
)
)
return@launch
@@ -55,7 +55,7 @@ internal class Balance : CommandExecutor {
}
if (!otherPlayer.hasPlayedBefore()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>That player doesn't exist.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>That player doesn't exist.")
)
return@launch
}
@@ -64,7 +64,7 @@ internal class Balance : CommandExecutor {
DiamondBankOG.postgreSQL.getAllShards(otherPlayer.uniqueId).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get their balance."
"${config.prefix}<reset>: <red>Something went wrong while trying to get their balance."
)
)
return@launch
@@ -94,7 +94,7 @@ internal class Balance : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.balance.others")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command in that way."
"${config.prefix}<reset>: <red>You do not have permission to use this command in that way."
)
)
return@launch
@@ -109,7 +109,7 @@ internal class Balance : CommandExecutor {
}
if (!otherPlayer.hasPlayedBefore()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>That player doesn't exist.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>That player doesn't exist.")
)
return@launch
}
@@ -119,7 +119,7 @@ internal class Balance : CommandExecutor {
DiamondBankOG.postgreSQL.getAllShards(balancePlayer.uniqueId).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get ${
"${config.prefix}<reset>: <red>Something went wrong while trying to get ${
if (balancePlayer.uniqueId != sender.uniqueId) "their" else "your"
} balance."
)
@@ -134,7 +134,7 @@ internal class Balance : CommandExecutor {
val enderChestDiamonds = String.format("%.1f", floor((balance.enderChest / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>${
"${config.prefix}<reset>: <green>${
if (balancePlayer.uniqueId == sender.uniqueId) "Your Balance" else "Balance of ${
getPrefix(
balancePlayer.uniqueId
@@ -5,8 +5,8 @@ import kotlin.math.ceil
import kotlin.math.floor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.PlayerPrefix.getPrefix
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
@@ -21,7 +21,7 @@ internal class Balancetop : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -30,7 +30,7 @@ internal class Balancetop : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.balancetop")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -40,7 +40,7 @@ internal class Balancetop : CommandExecutor {
if (args.size > 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Please (only) optionally provide the page number or the name or UUID of the player you want to see the position of."
"${config.prefix}<reset>: <red>Please (only) optionally provide the page number or the name or UUID of the player you want to see the position of."
)
)
return@launch
@@ -64,7 +64,7 @@ internal class Balancetop : CommandExecutor {
if (!player.hasPlayedBefore()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>That player doesn't exist or hasn't joined this server before."
"${config.prefix}<reset>: <red>That player doesn't exist or hasn't joined this server before."
)
)
return@launch
@@ -77,20 +77,20 @@ internal class Balancetop : CommandExecutor {
DiamondBankOG.postgreSQL.getBaltopWithUuid(player.uniqueId).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
"${config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
)
)
return@launch
}
val (baltop, offset) = baltopWithUuid
var baltopMessage = "${Config.prefix} <aqua>Top Balances:<reset>"
var baltopMessage = "${config.prefix} <aqua>Top Balances:<reset>"
baltop.forEach {
val uuid = it.key
if (uuid == null) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
"${config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
)
)
return@launch
@@ -115,7 +115,7 @@ internal class Balancetop : CommandExecutor {
DiamondBankOG.postgreSQL.getBaltop(offset).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
"${config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
)
)
return@launch
@@ -125,7 +125,7 @@ internal class Balancetop : CommandExecutor {
DiamondBankOG.postgreSQL.getNumberOfRows().getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
"${config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
)
)
return@launch
@@ -134,7 +134,7 @@ internal class Balancetop : CommandExecutor {
if (index > ceil(numberOfRows / 9.0)) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The amount of pages only goes up to and including ${
"${config.prefix}<reset>: <red>The amount of pages only goes up to and including ${
ceil(
numberOfRows / 9.0
).toLong()
@@ -144,13 +144,13 @@ internal class Balancetop : CommandExecutor {
return@launch
}
var baltopMessage =
"${Config.prefix} <aqua>Top Balances <#2ec2ae>(Page $index/${ceil(numberOfRows / 9.0).toLong()})<aqua>:<reset>"
"${config.prefix} <aqua>Top Balances <#2ec2ae>(Page $index/${ceil(numberOfRows / 9.0).toLong()})<aqua>:<reset>"
baltop.forEach {
val uuid = it.key
if (uuid == null) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
"${config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."
)
)
return@launch
@@ -2,8 +2,8 @@ package net.trueog.diamondbankog.commands
import kotlin.math.abs
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.InventoryExtensions.countDiamondBlocks
import net.trueog.diamondbankog.InventoryExtensions.countDiamonds
import net.trueog.diamondbankog.InventoryExtensions.countShards
@@ -32,7 +32,7 @@ internal class Compress : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -47,7 +47,7 @@ internal class Compress : CommandExecutor {
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot use /compress when in a minigame."
"${config.prefix}<reset>: <red>You cannot use /compress when in a minigame."
)
)
return@launch
@@ -56,7 +56,7 @@ internal class Compress : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.compress")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -71,14 +71,14 @@ internal class Compress : CommandExecutor {
if (args.size > 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Do not provide more arguments than \"yes\" if you want to compress the items in the shulker box you're holding."
"${config.prefix}<reset>: <red>Do not provide more arguments than \"yes\" if you want to compress the items in the shulker box you're holding."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
}
if (args[0] != "yes") {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>Invalid argument.")
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
}
@@ -87,7 +87,7 @@ internal class Compress : CommandExecutor {
if (itemInMainHand.type != Material.SHULKER_BOX) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You are not holding a shulker box."
"${config.prefix}<reset>: <red>You are not holding a shulker box."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -104,7 +104,7 @@ internal class Compress : CommandExecutor {
if (sender.inventory.itemInMainHand.type == Material.SHULKER_BOX && !isShulkerBox) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <#FFA500>Are you sure you want to compress the Diamond currency items in the shulker box you're holding? If so, run \"/compress yes\""
"${config.prefix}<reset>: <#FFA500>Are you sure you want to compress the Diamond currency items in the shulker box you're holding? If so, run \"/compress yes\""
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -145,7 +145,7 @@ internal class Compress : CommandExecutor {
if (changeInDiamonds > emptySlots + leftOverSpaceDiamonds) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."
"${config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -163,7 +163,7 @@ internal class Compress : CommandExecutor {
if (changeInDiamondBlocks > emptySlots + leftOverSpaceDiamondBlocks) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."
"${config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -175,7 +175,7 @@ internal class Compress : CommandExecutor {
if (removeMap.isNotEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -187,7 +187,7 @@ internal class Compress : CommandExecutor {
if (addMap.isNotEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -197,7 +197,7 @@ internal class Compress : CommandExecutor {
if (removeMap.isNotEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -209,7 +209,7 @@ internal class Compress : CommandExecutor {
if (addMap.isNotEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -220,7 +220,7 @@ internal class Compress : CommandExecutor {
if (removeMap.isNotEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
"${config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."
)
)
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
@@ -244,7 +244,7 @@ internal class Compress : CommandExecutor {
is TransactionLock.LockResult.Failed -> {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You are currently blocked from using /deposit."
"${config.prefix}<reset>: <red>You are currently blocked from using /deposit."
)
)
RunOnMainThreadResult(true, null, null, null)
@@ -255,14 +255,14 @@ internal class Compress : CommandExecutor {
if (changeInShards == null || changeInDiamonds == null || changeInDiamondBlocks == null) return@launch
if (changeInShards == 0 && changeInDiamonds == 0 && changeInDiamondBlocks == 0) {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <#FFA500>Nothing found to compress.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <#FFA500>Nothing found to compress.")
)
return@launch
}
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully compressed all the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}!"
"${config.prefix}<reset>: <green>Successfully compressed all the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}!"
)
)
@@ -296,7 +296,7 @@ internal class Compress : CommandExecutor {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
buildString {
append("${Config.prefix}<reset>: Compression Summary:\n")
append("${config.prefix}<reset>: Compression Summary:\n")
if (shardsLine.isNotEmpty()) append(shardsLine)
if (diamondsLine.isNotEmpty()) append(diamondsLine)
if (diamondBlocksLine.isNotEmpty()) append(diamondBlocksLine)
@@ -3,8 +3,8 @@ package net.trueog.diamondbankog.commands
import kotlin.math.floor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.InventoryExtensions.withdraw
import net.trueog.diamondbankog.PostgreSQL.PlayerShards
@@ -22,7 +22,7 @@ internal class Deposit : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -37,7 +37,7 @@ internal class Deposit : CommandExecutor {
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot use /deposit when in a minigame."
"${config.prefix}<reset>: <red>You cannot use /deposit when in a minigame."
)
)
return@launch
@@ -46,7 +46,7 @@ internal class Deposit : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.deposit")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -55,7 +55,7 @@ internal class Deposit : CommandExecutor {
if (args == null || args.isEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You did not provide the amount of <aqua>Diamonds <red>that you want to deposit."
"${config.prefix}<reset>: <red>You did not provide the amount of <aqua>Diamonds <red>that you want to deposit."
)
)
return@launch
@@ -63,7 +63,7 @@ internal class Deposit : CommandExecutor {
if (args.size != 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Please (only) provide the amount of <aqua>Diamonds <red>you want to deposit. Either a number or \"all\"."
"${config.prefix}<reset>: <red>Please (only) provide the amount of <aqua>Diamonds <red>you want to deposit. Either a number or \"all\"."
)
)
return@launch
@@ -73,7 +73,7 @@ internal class Deposit : CommandExecutor {
DiamondBankOG.postgreSQL.getInventoryShards(sender.uniqueId).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get your balance."
"${config.prefix}<reset>: <red>Something went wrong while trying to get your balance."
)
)
return@launch
@@ -81,7 +81,7 @@ internal class Deposit : CommandExecutor {
if (playerInventoryShards == 0) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You don't have any <aqua>Diamonds <red>to deposit."
"${config.prefix}<reset>: <red>You don't have any <aqua>Diamonds <red>to deposit."
)
)
return@launch
@@ -95,20 +95,20 @@ internal class Deposit : CommandExecutor {
if (amount <= 0) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot deposit a negative or zero amount."
"${config.prefix}<reset>: <red>You cannot deposit a negative or zero amount."
)
)
return@launch
}
} catch (_: Exception) {
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument."))
sender.sendMessage(DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>Invalid argument."))
return@launch
}
val split = amount.toString().split(".")
if (split[1].length > 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return@launch
@@ -118,7 +118,7 @@ internal class Deposit : CommandExecutor {
if (shards > playerInventoryShards) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have <yellow>${args[0]} <aqua>Diamond${if (args[0] != "1.0") "s" else ""} <red>in your inventory."
"${config.prefix}<reset>: <red>You do not have <yellow>${args[0]} <aqua>Diamond${if (args[0] != "1.0") "s" else ""} <red>in your inventory."
)
)
return@launch
@@ -136,7 +136,7 @@ internal class Deposit : CommandExecutor {
handleError(sender.uniqueId, shards, PlayerShards(-1, playerInventoryShards, -1))
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -146,7 +146,7 @@ internal class Deposit : CommandExecutor {
val diamondsContinuing = String.format("%.1f", floor((shards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <#FFA500>Something went wrong while trying to remove <yellow>$notRemovedDiamonds <aqua>Diamond${if (notRemovedDiamonds != "1.0") "s" else ""}<#FFA500> from your inventory, proceeding with <yellow>$diamondsContinuing <aqua>Diamond${if (diamondsContinuing != "1.0") "s" else ""}<#FFA500>."
"${config.prefix}<reset>: <#FFA500>Something went wrong while trying to remove <yellow>$notRemovedDiamonds <aqua>Diamond${if (notRemovedDiamonds != "1.0") "s" else ""}<#FFA500> from your inventory, proceeding with <yellow>$diamondsContinuing <aqua>Diamond${if (diamondsContinuing != "1.0") "s" else ""}<#FFA500>."
)
)
}
@@ -155,7 +155,7 @@ internal class Deposit : CommandExecutor {
handleError(sender.uniqueId, shards, PlayerShards(-1, playerInventoryShards, -1))
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -172,7 +172,7 @@ internal class Deposit : CommandExecutor {
is TransactionLock.LockResult.Failed -> {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You are currently blocked from using /deposit."
"${config.prefix}<reset>: <red>You are currently blocked from using /deposit."
)
)
return@launch
@@ -182,7 +182,7 @@ internal class Deposit : CommandExecutor {
val diamondsDeposited = String.format("%.1f", floor((shards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully deposited <yellow>$diamondsDeposited <aqua>Diamond${if (diamondsDeposited != "1.0") "s" else ""} <green>into your bank account."
"${config.prefix}<reset>: <green>Successfully deposited <yellow>$diamondsDeposited <aqua>Diamond${if (diamondsDeposited != "1.0") "s" else ""} <green>into your bank account."
)
)
@@ -1,7 +1,7 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@@ -10,7 +10,7 @@ internal class DiamondBankHelp : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"<gray>---- ${Config.prefix}<reset> Help <gray>----<reset>\n" +
"<gray>---- ${config.prefix}<reset> Help <gray>----<reset>\n" +
"<bold>How does the <aqua>Diamonds<white> currency work?<reset>\n" +
"The currency on TrueOG Network is based on Diamonds. The smallest form is Diamond Shards, followed by Diamonds, and the largest form is Diamond Blocks. 1 Diamond Block equals 9 Diamonds, and 1 Diamond equals 9 Diamond Shards. When converting Diamond Shards to Diamonds, any amount ending with .9 is rounded up to the next whole Diamond. Some examples:\n" +
"- 1.8 Diamonds = 1 Diamond + 8 Shards\n" +
@@ -2,6 +2,7 @@ package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.PostgreSQL
import org.bukkit.Bukkit
import org.bukkit.command.Command
@@ -10,15 +11,17 @@ import org.bukkit.command.CommandSender
internal class DiamondBankReload : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean {
if (Config.load()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"<red>Failed to reload the config. Check the console for more information."
)
)
Bukkit.getPluginManager().disablePlugin(DiamondBankOG.plugin)
return true
}
config =
Config.create()
?: run {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"<red>Failed to reload the config. Check the console for more information."
)
)
Bukkit.getPluginManager().disablePlugin(DiamondBankOG.plugin)
return true
}
DiamondBankOG.postgreSQL = PostgreSQL()
try {
@@ -35,7 +38,7 @@ internal class DiamondBankReload : CommandExecutor {
}
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully reloaded the config.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <green>Successfully reloaded the config.")
)
return true
}
@@ -1,7 +1,7 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@@ -11,7 +11,7 @@ internal class DisableEconomy : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.admin")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return true
@@ -20,7 +20,7 @@ internal class DisableEconomy : CommandExecutor {
DiamondBankOG.economyDisabled = true
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully <red>disabled <green>the economy."
"${config.prefix}<reset>: <green>Successfully <red>disabled <green>the economy."
)
)
return true
@@ -1,7 +1,7 @@
package net.trueog.diamondbankog.commands
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@@ -11,7 +11,7 @@ internal class EnableEconomy : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.admin")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return true
@@ -19,7 +19,7 @@ internal class EnableEconomy : CommandExecutor {
DiamondBankOG.economyDisabled = false
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully enabled the economy.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <green>Successfully enabled the economy.")
)
return true
}
@@ -4,8 +4,8 @@ import java.util.*
import kotlin.math.floor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.PlayerPrefix.getPrefix
import net.trueog.diamondbankog.PostgreSQL.ShardType
@@ -24,7 +24,7 @@ internal class Pay : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -39,7 +39,7 @@ internal class Pay : CommandExecutor {
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot use /pay when in a minigame."
"${config.prefix}<reset>: <red>You cannot use /pay when in a minigame."
)
)
return@launch
@@ -48,7 +48,7 @@ internal class Pay : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.pay")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -57,7 +57,7 @@ internal class Pay : CommandExecutor {
if (args == null || args.isEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You did not provide the name or the UUID of a player and the amount of <aqua>Diamonds<red>."
"${config.prefix}<reset>: <red>You did not provide the name or the UUID of a player and the amount of <aqua>Diamonds<red>."
)
)
return@launch
@@ -65,7 +65,7 @@ internal class Pay : CommandExecutor {
if (args.size != 2) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Please (only) provide the name or the UUID of a player and the amount of <aqua>Diamonds<red>."
"${config.prefix}<reset>: <red>Please (only) provide the name or the UUID of a player and the amount of <aqua>Diamonds<red>."
)
)
return@launch
@@ -80,7 +80,7 @@ internal class Pay : CommandExecutor {
if (sender.uniqueId == receiver.uniqueId) {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot pay yourself.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>You cannot pay yourself.")
)
return@launch
}
@@ -88,7 +88,7 @@ internal class Pay : CommandExecutor {
if (!receiver.hasPlayedBefore()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>That player doesn't exist or hasn't joined this server before."
"${config.prefix}<reset>: <red>That player doesn't exist or hasn't joined this server before."
)
)
return@launch
@@ -102,20 +102,20 @@ internal class Pay : CommandExecutor {
if (amount <= 0) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot pay a negative or zero amount."
"${config.prefix}<reset>: <red>You cannot pay a negative or zero amount."
)
)
return@launch
}
} catch (_: Exception) {
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument."))
sender.sendMessage(DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>Invalid argument."))
return@launch
}
val split = amount.toString().split(".")
if (split[1].length > 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return@launch
@@ -134,7 +134,7 @@ internal class Pay : CommandExecutor {
handleError(sender.uniqueId, shards, null, receiver.uniqueId)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -144,7 +144,7 @@ internal class Pay : CommandExecutor {
val diamondsContinuing = String.format("%.1f", floor((shards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <#FFA500>Something went wrong while trying to remove <yellow>$notRemovedDiamonds <aqua>Diamond${if (notRemovedDiamonds != "1.0") "s" else ""}<#FFA500> from your inventory and/or ender chest, proceeding with <yellow>$diamondsContinuing <aqua>Diamond${if (diamondsContinuing != "1.0") "s" else ""}<#FFA500>."
"${config.prefix}<reset>: <#FFA500>Something went wrong while trying to remove <yellow>$notRemovedDiamonds <aqua>Diamond${if (notRemovedDiamonds != "1.0") "s" else ""}<#FFA500> from your inventory and/or ender chest, proceeding with <yellow>$diamondsContinuing <aqua>Diamond${if (diamondsContinuing != "1.0") "s" else ""}<#FFA500>."
)
)
}
@@ -155,7 +155,7 @@ internal class Pay : CommandExecutor {
handleError(sender.uniqueId, shards, null, receiver.uniqueId)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -172,7 +172,7 @@ internal class Pay : CommandExecutor {
is TransactionLock.LockResult.Failed -> {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You are currently blocked from using /pay."
"${config.prefix}<reset>: <red>You are currently blocked from using /pay."
)
)
return@launch
@@ -183,7 +183,7 @@ internal class Pay : CommandExecutor {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully paid <yellow>$diamondsPaid <aqua>Diamond${if (diamondsPaid != "1.0") "s" else ""} <green>to ${
"${config.prefix}<reset>: <green>Successfully paid <yellow>$diamondsPaid <aqua>Diamond${if (diamondsPaid != "1.0") "s" else ""} <green>to ${
getPrefix(
receiver.uniqueId
)
@@ -195,7 +195,7 @@ internal class Pay : CommandExecutor {
val receiverPlayer = receiver.player ?: return@launch
receiverPlayer.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>${
"${config.prefix}<reset>: <green>${
getPrefix(
sender.uniqueId
)
@@ -3,8 +3,8 @@ package net.trueog.diamondbankog.commands
import java.util.*
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.Config
import net.trueog.diamondbankog.DiamondBankOG
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.PlayerPrefix.getPrefix
import net.trueog.diamondbankog.PostgreSQL.ShardType
@@ -21,7 +21,7 @@ internal class SetBankBalance : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -30,7 +30,7 @@ internal class SetBankBalance : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.setbankbalance")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -39,7 +39,7 @@ internal class SetBankBalance : CommandExecutor {
if (args == null || args.isEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You did not provide the name or the UUID of a player and the amount of <aqua>Shards<red>."
"${config.prefix}<reset>: <red>You did not provide the name or the UUID of a player and the amount of <aqua>Shards<red>."
)
)
return@launch
@@ -47,7 +47,7 @@ internal class SetBankBalance : CommandExecutor {
if (args.size != 2) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Incorrect syntax. Usage: /setbankbal(ance) <player name or player uuid> <shards>."
"${config.prefix}<reset>: <red>Incorrect syntax. Usage: /setbankbal(ance) <player name or player uuid> <shards>."
)
)
return@launch
@@ -61,7 +61,7 @@ internal class SetBankBalance : CommandExecutor {
}
if (!player.hasPlayedBefore()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>That player doesn't exist.")
DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>That player doesn't exist.")
)
return@launch
}
@@ -70,14 +70,14 @@ internal class SetBankBalance : CommandExecutor {
try {
balance = args[1].toInt()
} catch (_: Exception) {
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument."))
sender.sendMessage(DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>Invalid argument."))
return@launch
}
DiamondBankOG.postgreSQL.setPlayerShards(player.uniqueId, balance, ShardType.BANK).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to set that player's balance."
"${config.prefix}<reset>: <red>Something went wrong while trying to set that player's balance."
)
)
return@launch
@@ -85,7 +85,7 @@ internal class SetBankBalance : CommandExecutor {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully set the balance of ${
"${config.prefix}<reset>: <green>Successfully set the balance of ${
getPrefix(
player.uniqueId
)
@@ -5,6 +5,7 @@ import kotlin.math.floor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.launch
import net.trueog.diamondbankog.*
import net.trueog.diamondbankog.DiamondBankOG.Companion.config
import net.trueog.diamondbankog.ErrorHandler.handleError
import net.trueog.diamondbankog.InventoryExtensions.countTotal
import net.trueog.diamondbankog.MainThreadBlock.runOnMainThread
@@ -23,7 +24,7 @@ internal class Withdraw : CommandExecutor {
if (DiamondBankOG.economyDisabled) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
"${config.prefix}<reset>: <red>The economy is disabled. Please notify a staff member."
)
)
return@launch
@@ -38,7 +39,7 @@ internal class Withdraw : CommandExecutor {
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot use /withdraw when in a minigame."
"${config.prefix}<reset>: <red>You cannot use /withdraw when in a minigame."
)
)
return@launch
@@ -47,7 +48,7 @@ internal class Withdraw : CommandExecutor {
if (!sender.hasPermission("diamondbank-og.withdraw")) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You do not have permission to use this command."
"${config.prefix}<reset>: <red>You do not have permission to use this command."
)
)
return@launch
@@ -56,7 +57,7 @@ internal class Withdraw : CommandExecutor {
if (args == null || args.isEmpty()) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You did not provide the amount of <aqua>Diamonds <red>that you want to withdraw."
"${config.prefix}<reset>: <red>You did not provide the amount of <aqua>Diamonds <red>that you want to withdraw."
)
)
return@launch
@@ -64,7 +65,7 @@ internal class Withdraw : CommandExecutor {
if (args.size != 1 && args.size != 2) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Please provide the amount of <aqua>Diamonds <red>you want to withdraw. Either a number or \"all\"."
"${config.prefix}<reset>: <red>Please provide the amount of <aqua>Diamonds <red>you want to withdraw. Either a number or \"all\"."
)
)
return@launch
@@ -78,20 +79,20 @@ internal class Withdraw : CommandExecutor {
if (amount <= 0) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You cannot withdraw a negative or zero amount."
"${config.prefix}<reset>: <red>You cannot withdraw a negative or zero amount."
)
)
return@launch
}
} catch (_: Exception) {
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument."))
sender.sendMessage(DiamondBankOG.mm.deserialize("${config.prefix}<reset>: <red>Invalid argument."))
return@launch
}
val split = amount.toString().split(".")
if (split[1].length > 1) {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
"${config.prefix}<reset>: <red><aqua>Diamonds<red> can only have one decimal digit. Issue /diamondbankhelp for more information."
)
)
return@launch
@@ -105,7 +106,7 @@ internal class Withdraw : CommandExecutor {
DiamondBankOG.postgreSQL.getAllShards(sender.uniqueId).getOrElse {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to get your balance."
"${config.prefix}<reset>: <red>Something went wrong while trying to get your balance."
)
)
return@tryWithLockSuspend true
@@ -121,7 +122,7 @@ internal class Withdraw : CommandExecutor {
val bankDiamonds = String.format("%.1f", floor((playerBankShards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Cannot withdraw <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <red>because your bank only contains <yellow>$bankDiamonds <aqua>Diamond${if (bankDiamonds != "1.0") "s" else ""}<red>."
"${config.prefix}<reset>: <red>Cannot withdraw <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <red>because your bank only contains <yellow>$bankDiamonds <aqua>Diamond${if (bankDiamonds != "1.0") "s" else ""}<red>."
)
)
return@tryWithLockSuspend true
@@ -154,7 +155,7 @@ internal class Withdraw : CommandExecutor {
val diamonds = String.format("%.1f", floor((shards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You don't have enough inventory space to withdraw <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""}<red>."
"${config.prefix}<reset>: <red>You don't have enough inventory space to withdraw <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""}<red>."
)
)
return@tryWithLockSuspend true
@@ -164,7 +165,7 @@ internal class Withdraw : CommandExecutor {
handleError(sender.uniqueId, shards, PostgreSQL.PlayerShards(playerBankShards, -1, -1))
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -184,7 +185,7 @@ internal class Withdraw : CommandExecutor {
handleError(sender.uniqueId, shards, playerShards)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
"${config.prefix}<reset>: <red>A severe error has occurred. Please notify a staff member."
)
)
return@tryWithLockSuspend true
@@ -194,7 +195,7 @@ internal class Withdraw : CommandExecutor {
handleError(sender.uniqueId, shards, playerShards)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>Something went wrong while trying to recount the <aqua>Diamonds<red> amount in your inventory, try opening and closing your inventory to force a recount."
"${config.prefix}<reset>: <red>Something went wrong while trying to recount the <aqua>Diamonds<red> amount in your inventory, try opening and closing your inventory to force a recount."
)
)
return@tryWithLockSuspend true
@@ -211,7 +212,7 @@ internal class Withdraw : CommandExecutor {
is TransactionLock.LockResult.Failed -> {
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <red>You are currently blocked from using /withdraw."
"${config.prefix}<reset>: <red>You are currently blocked from using /withdraw."
)
)
return@launch
@@ -221,7 +222,7 @@ internal class Withdraw : CommandExecutor {
val diamonds = String.format("%.1f", floor((shards / 9.0) * 10) / 10.0)
sender.sendMessage(
DiamondBankOG.mm.deserialize(
"${Config.prefix}<reset>: <green>Successfully withdrew <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <green>from your bank account."
"${config.prefix}<reset>: <green>Successfully withdrew <yellow>$diamonds <aqua>Diamond${if (diamonds != "1.0") "s" else ""} <green>from your bank account."
)
)