Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dca9160c7 | ||
|
|
2bcc3c6af7 | ||
|
|
223b124f5c | ||
|
|
9ea3a45341 | ||
|
|
8a1782804e | ||
|
|
1723dc8c0c | ||
|
|
3db90103e1 | ||
|
|
2c5d1ab576 | ||
|
|
63b490ed39 | ||
|
|
31e41cdc5a | ||
|
|
5ffb160f25 | ||
|
|
5a45860f4c | ||
|
|
28a674cc6c | ||
|
|
0a5c35f057 | ||
|
|
8997512b46 | ||
|
|
5c7ab67726 | ||
|
|
f82b20919d | ||
|
|
2445f1e490 | ||
|
|
b25b66b62f | ||
|
|
220c1e1bb6 | ||
|
|
80fa951e56 | ||
|
|
af428263b5 | ||
|
|
cee62fbe5c | ||
|
|
404111d5ce | ||
|
|
1c9c60aae8 | ||
|
|
ac11753844 | ||
|
|
e5b7697c7f | ||
|
|
337fc3f2b8 | ||
|
|
ad0a0ad2d4 | ||
|
|
69e5fa2f64 | ||
|
|
8fbb70bedf | ||
|
|
c816383e12 | ||
|
|
29c4d46dd5 | ||
|
|
e051856b7a | ||
|
|
a9f0985398 | ||
|
|
25f66ba41f | ||
|
|
1293994911 | ||
|
|
e9195e9573 | ||
|
|
291a96f505 | ||
|
|
8ba2b53ba7 | ||
|
|
a874878fb4 | ||
|
|
4561ffa3d2 | ||
|
|
4b6c64fabd | ||
|
|
9754218e85 | ||
|
|
0d3b285111 | ||
|
|
c366bccb66 | ||
|
|
09a14a7c85 | ||
|
|
bcc0a70d2e | ||
|
|
8068f50d19 | ||
|
|
6962ab1a6c | ||
|
|
1987d30f18 | ||
|
|
322dd3f71b |
No files matched your search
@@ -0,0 +1,16 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
ignore:
|
||||
- dependency-name: "org.purpurmc.purpur:purpur-api"
|
||||
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
target-branch: "shards"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
ignore:
|
||||
- dependency-name: "org.purpurmc.purpur:purpur-api"
|
||||
@@ -0,0 +1,67 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
|
||||
|
||||
name: Java CI with Gradle
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master", "shards" ]
|
||||
pull_request:
|
||||
branches: [ "master", "shards" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
|
||||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||
|
||||
- name: Build with Gradle Wrapper
|
||||
run: ./gradlew build
|
||||
|
||||
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
|
||||
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
|
||||
#
|
||||
# - name: Setup Gradle
|
||||
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||
# with:
|
||||
# gradle-version: '8.9'
|
||||
#
|
||||
# - name: Build with Gradle 8.9
|
||||
# run: gradle build
|
||||
|
||||
dependency-submission:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
|
||||
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
|
||||
- name: Generate and submit dependency graph
|
||||
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||
@@ -1,3 +1,5 @@
|
||||
> [!NOTE]
|
||||
> An experimental branch that implements Shards is available [here](https://github.com/SKBotNL/DiamondBank-OG/tree/shards).
|
||||
# DiamondBank-OG
|
||||
|
||||
A free and open source Diamond Economy plugin for Spigot inspired by [The Diamond Bank](https://www.spigotmc.org/resources/the-diamond-bank.72020/).\
|
||||
|
||||
+7
-7
@@ -1,11 +1,11 @@
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.jvm") version "1.9.22"
|
||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||
id("org.jetbrains.kotlin.jvm") version "2.1.21"
|
||||
id("com.gradleup.shadow") version "8.3.6"
|
||||
id("maven-publish")
|
||||
id("eclipse")
|
||||
}
|
||||
|
||||
group = "net.trueog.diamondbank"
|
||||
group = "net.trueog.diamondbankog"
|
||||
version = "1.1"
|
||||
|
||||
val apiVersion = "1.19"
|
||||
@@ -13,7 +13,7 @@ val apiVersion = "1.19"
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenPublication") {
|
||||
groupId = "net.trueog.diamondbank"
|
||||
groupId = "net.trueog.diamondbankog"
|
||||
artifactId = "DiamondBankOG"
|
||||
version = version
|
||||
}
|
||||
@@ -48,8 +48,8 @@ dependencies {
|
||||
implementation("com.github.christianniehaus:Utilities-OG:e9ebc26c1f")
|
||||
implementation("com.github.jasync-sql:jasync-postgresql:2.2.4")
|
||||
|
||||
implementation("io.sentry:sentry:7.6.0")
|
||||
implementation("io.sentry:sentry-kotlin-extensions:7.6.0")
|
||||
implementation("io.sentry:sentry:8.8.0")
|
||||
implementation("io.sentry:sentry-kotlin-extensions:8.9.0")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ tasks.shadowJar.configure {
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
tasks.build {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -112,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -203,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+14
-12
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -57,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -10,12 +10,16 @@ import java.util.concurrent.CompletableFuture
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
class DiamondBankAPI(private var postgreSQL: PostgreSQL) {
|
||||
@Suppress("unused")
|
||||
fun addToPlayerBankBalance(uuid: UUID, amount: Double): CompletableFuture<Boolean> {
|
||||
fun addToPlayerBankBalance(uuid: UUID, amount: Int): CompletableFuture<Boolean?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
return GlobalScope.future { postgreSQL.addToPlayerBalance(uuid, amount, PostgreSQL.BalanceType.BANK_BALANCE) }
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun subtractFromPlayerBankBalance(uuid: UUID, amount: Double): CompletableFuture<Boolean> {
|
||||
fun subtractFromPlayerBankBalance(uuid: UUID, amount: Int): CompletableFuture<Boolean?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
return GlobalScope.future {
|
||||
postgreSQL.subtractFromPlayerBalance(
|
||||
uuid,
|
||||
@@ -26,12 +30,26 @@ class DiamondBankAPI(private var postgreSQL: PostgreSQL) {
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun getPlayerBalance(uuid: UUID, type: PostgreSQL.BalanceType): CompletableFuture<PostgreSQL.PlayerBalance> {
|
||||
fun getPlayerBalance(uuid: UUID, type: PostgreSQL.BalanceType): CompletableFuture<PostgreSQL.PlayerBalance?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
return GlobalScope.future { postgreSQL.getPlayerBalance(uuid, type) }
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun withdrawFromPlayer(uuid: UUID, amount: Double): CompletableFuture<Boolean> {
|
||||
fun getPlayerTotalBalance(uuid: UUID): CompletableFuture<Int?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
return GlobalScope.future {
|
||||
val balance = postgreSQL.getPlayerBalance(uuid, PostgreSQL.BalanceType.ALL)
|
||||
balance.bankBalance!! + balance.inventoryBalance!! + balance.enderChestBalance!!
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun withdrawFromPlayer(uuid: UUID, amount: Int): CompletableFuture<Boolean?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
val player = Bukkit.getPlayer(uuid) ?: Bukkit.getOfflinePlayer(uuid)
|
||||
if (!player.hasPlayedBefore()) return GlobalScope.future { true }
|
||||
if (!player.isOnline) return GlobalScope.future { true }
|
||||
@@ -41,7 +59,9 @@ class DiamondBankAPI(private var postgreSQL: PostgreSQL) {
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun payPlayer(senderUuid: UUID, receiverUuid: UUID, amount: Double): CompletableFuture<Boolean> {
|
||||
fun payPlayer(senderUuid: UUID, receiverUuid: UUID, amount: Int): CompletableFuture<Boolean?> {
|
||||
if (DiamondBankOG.economyDisabled) return GlobalScope.future { null }
|
||||
|
||||
val sender = Bukkit.getPlayer(senderUuid) ?: Bukkit.getOfflinePlayer(senderUuid)
|
||||
if (!sender.hasPlayedBefore()) return GlobalScope.future { true }
|
||||
if (!sender.isOnline) return GlobalScope.future { true }
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
|
||||
import net.trueog.diamondbankog.commands.*
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.ServicePriority
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import java.util.*
|
||||
|
||||
@@ -26,14 +27,6 @@ class DiamondBankOG : JavaPlugin() {
|
||||
val blockCommandsWithInventoryActionsFor = mutableListOf<UUID>()
|
||||
var sentryEnabled: Boolean = false
|
||||
var economyDisabled: Boolean = false
|
||||
|
||||
// API
|
||||
@JvmStatic
|
||||
@Suppress("unused")
|
||||
fun getApi(): DiamondBankAPI? {
|
||||
if (!isPostgreSQLInitialised()) return null
|
||||
return DiamondBankAPI(postgreSQL)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEnable() {
|
||||
@@ -50,7 +43,7 @@ class DiamondBankOG : JavaPlugin() {
|
||||
options.dsn = Config.sentryDsn
|
||||
}
|
||||
sentryEnabled = true
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
sentryEnabled = false
|
||||
this.logger.severe("Could not initialise Sentry. The Sentry(-compatible) DSN in your config might be invalid.")
|
||||
}
|
||||
@@ -77,10 +70,14 @@ class DiamondBankOG : JavaPlugin() {
|
||||
this.getCommand("balance")?.setExecutor(Balance())
|
||||
this.getCommand("bal")?.setExecutor(Balance())
|
||||
this.getCommand("diamondbankreload")?.setExecutor(DiamondBankReload())
|
||||
|
||||
val diamondBankAPI = DiamondBankAPI(postgreSQL)
|
||||
this.server.servicesManager.register(DiamondBankAPI::class.java, diamondBankAPI, this,
|
||||
ServicePriority.Normal)
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
if (isPostgreSQLInitialised()) postgreSQL.pool.disconnect().get()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.trueog.diamondbankog.Helper.PostgresFunction
|
||||
import net.trueog.diamondbankog.Helper.countDiamonds
|
||||
import net.trueog.diamondbankog.PostgreSQL.BalanceType
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
@@ -16,6 +17,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
import org.bukkit.event.player.PlayerDropItemEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import org.bukkit.scheduler.BukkitRunnable
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@@ -31,6 +33,35 @@ class Events : Listener {
|
||||
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
|
||||
|
||||
GlobalScope.launch {
|
||||
if (!DiamondBankOG.postgreSQL.entryExists(event.player.uniqueId)) {
|
||||
val oldBalance = event.player.persistentDataContainer.get(
|
||||
NamespacedKey.fromString("diamondbank:balance")!!,
|
||||
PersistentDataType.DOUBLE
|
||||
)
|
||||
if (oldBalance != null) {
|
||||
val error = DiamondBankOG.postgreSQL.setPlayerBalance(
|
||||
event.player.uniqueId,
|
||||
oldBalance.toInt(),
|
||||
BalanceType.BANK_BALANCE
|
||||
)
|
||||
if (error) {
|
||||
Helper.handleError(
|
||||
event.player.uniqueId,
|
||||
PostgresFunction.SET_PLAYER_BALANCE,
|
||||
oldBalance.toInt(),
|
||||
BalanceType.BANK_BALANCE,
|
||||
null,
|
||||
"onPlayerJoin"
|
||||
)
|
||||
return@launch
|
||||
}
|
||||
event.player.persistentDataContainer.remove(NamespacedKey.fromString("diamondbank:balance")!!)
|
||||
event.player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Your old balance has successfully been migrated to DiamondBank-OG!"))
|
||||
}
|
||||
|
||||
// We don't need to set the player bank balance when we don't migrate since an entry will be created with the code below
|
||||
}
|
||||
|
||||
val inventoryDiamonds = event.player.inventory.countDiamonds()
|
||||
var error = DiamondBankOG.postgreSQL.setPlayerBalance(
|
||||
event.player.uniqueId,
|
||||
@@ -251,4 +282,4 @@ class Events : Listener {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,10 @@ object Helper {
|
||||
enum class PostgresFunction(val string: String) {
|
||||
SET_PLAYER_BALANCE("setPlayerBalance"),
|
||||
ADD_TO_PLAYER_BALANCE("addToPlayerBalance"),
|
||||
SUBTRACT_FROM_PLAYER_BALANCE("subtractFromPlayerBalance")
|
||||
SUBTRACT_FROM_PLAYER_BALANCE("subtractFromPlayerBalance"),
|
||||
}
|
||||
|
||||
suspend fun withdrawFromPlayer(player: Player, amount: Double): Double? {
|
||||
suspend fun withdrawFromPlayer(player: Player, amount: Int): Int? {
|
||||
val somethingWentWrongMessage =
|
||||
DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong.")
|
||||
|
||||
@@ -33,7 +33,7 @@ object Helper {
|
||||
}
|
||||
|
||||
// Withdraw everything
|
||||
if (amount == -1.0) {
|
||||
if (amount == -1) {
|
||||
var error = DiamondBankOG.postgreSQL.subtractFromPlayerBalance(
|
||||
player.uniqueId,
|
||||
playerBalance.bankBalance,
|
||||
@@ -70,7 +70,7 @@ object Helper {
|
||||
}
|
||||
|
||||
if (amount > playerBalance.bankBalance + playerBalance.inventoryBalance + playerBalance.enderChestBalance) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Cannot withdraw <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"} <red>because you only have <yellow>${playerBalance.bankBalance + playerBalance.inventoryBalance} <aqua>${if (playerBalance.bankBalance + playerBalance.inventoryBalance <= 1.0) "Diamond" else "Diamonds"}<red>."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Cannot withdraw <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"} <red>because you only have <yellow>${playerBalance.bankBalance + playerBalance.inventoryBalance} <aqua>${if (playerBalance.bankBalance + playerBalance.inventoryBalance == 1) "Diamond" else "Diamonds"}<red>."))
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -184,14 +184,14 @@ object Helper {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: You don't have enough inventory space in your shulker box to store <yellow>$change <aqua>${if (change == 1) "Diamond" else "Diamonds"} <reset>of change from converting diamond blocks into <aqua>Diamonds<reset>, so the <aqua>${if (change == 1) "Diamond" else "Diamonds"} <reset>has been deposited into your bank."))
|
||||
val error = DiamondBankOG.postgreSQL.addToPlayerBalance(
|
||||
player.uniqueId,
|
||||
change.toDouble(),
|
||||
change,
|
||||
BalanceType.BANK_BALANCE
|
||||
)
|
||||
if (error) {
|
||||
handleError(
|
||||
player.uniqueId,
|
||||
PostgresFunction.ADD_TO_PLAYER_BALANCE,
|
||||
change.toDouble(),
|
||||
change,
|
||||
balanceType,
|
||||
null,
|
||||
"Inventory.withdrawDiamondBlocks"
|
||||
@@ -208,14 +208,14 @@ object Helper {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: You don't have enough inventory space to store <yellow>$change <aqua>${if (change == 1) "Diamond" else "Diamonds"} <reset>of change from converting diamond blocks into <aqua>Diamonds<reset>, so the <aqua>${if (change == 1) "Diamond" else "Diamonds"} <reset>has been deposited into your bank."))
|
||||
val error = DiamondBankOG.postgreSQL.addToPlayerBalance(
|
||||
player.uniqueId,
|
||||
change.toDouble(),
|
||||
change,
|
||||
BalanceType.BANK_BALANCE
|
||||
)
|
||||
if (error) {
|
||||
handleError(
|
||||
player.uniqueId,
|
||||
PostgresFunction.ADD_TO_PLAYER_BALANCE,
|
||||
change.toDouble(),
|
||||
change,
|
||||
balanceType,
|
||||
null,
|
||||
"Inventory.withdrawDiamondBlocks"
|
||||
@@ -233,7 +233,7 @@ object Helper {
|
||||
}
|
||||
|
||||
suspend fun Inventory.withdraw(
|
||||
amount: Double,
|
||||
amount: Int,
|
||||
playerBalance: PostgreSQL.PlayerBalance
|
||||
): Boolean {
|
||||
if (this.holder !is Player) return true
|
||||
@@ -294,7 +294,7 @@ object Helper {
|
||||
return true
|
||||
}
|
||||
|
||||
val removeMap = this.removeItem(ItemStack(Material.DIAMOND, amount.toInt()))
|
||||
val removeMap = this.removeItem(ItemStack(Material.DIAMOND, amount))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
var toBeRemoved = removeMap[0]!!.amount
|
||||
|
||||
@@ -340,23 +340,22 @@ object Helper {
|
||||
return false
|
||||
}
|
||||
|
||||
fun Inventory.countDiamonds(): Double {
|
||||
val inventoryDiamonds = this.all(Material.DIAMOND).values.sumOf { it.amount }.toDouble()
|
||||
val inventoryDiamondBlocks = this.all(Material.DIAMOND_BLOCK).values.sumOf { it.amount * 9 }.toDouble()
|
||||
|
||||
fun Inventory.countDiamonds(): Int {
|
||||
val inventoryDiamonds = this.all(Material.DIAMOND).values.sumOf { it.amount }
|
||||
val shulkerBoxDiamonds = this.all(Material.SHULKER_BOX).values.sumOf { itemStack ->
|
||||
((itemStack.itemMeta as BlockStateMeta).blockState as ShulkerBox).inventory.all(Material.DIAMOND).values.sumOf { it.amount }
|
||||
}.toDouble()
|
||||
}
|
||||
val inventoryDiamondBlocks = this.all(Material.DIAMOND_BLOCK).values.sumOf { it.amount * 9 }
|
||||
val shulkerBoxDiamondBlocks = this.all(Material.SHULKER_BOX).values.sumOf { itemStack ->
|
||||
((itemStack.itemMeta as BlockStateMeta).blockState as ShulkerBox).inventory.all(Material.DIAMOND_BLOCK).values.sumOf { it.amount * 9 }
|
||||
}.toDouble()
|
||||
}
|
||||
return inventoryDiamonds + shulkerBoxDiamonds + inventoryDiamondBlocks + shulkerBoxDiamondBlocks
|
||||
}
|
||||
|
||||
fun handleError(
|
||||
uuid: UUID,
|
||||
function: PostgresFunction,
|
||||
amount: Double,
|
||||
amount: Int,
|
||||
balanceType: BalanceType,
|
||||
playerBalance: PostgreSQL.PlayerBalance?,
|
||||
inFunction: String
|
||||
@@ -410,4 +409,4 @@ object Helper {
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
|
||||
import kotlinx.coroutines.future.await
|
||||
import org.bukkit.Bukkit
|
||||
import java.math.BigDecimal
|
||||
import java.sql.SQLException
|
||||
import java.util.*
|
||||
|
||||
@@ -24,7 +23,7 @@ class PostgreSQL {
|
||||
pool =
|
||||
PostgreSQLConnectionBuilder.createConnectionPool("${Config.postgresUrl}?user=${Config.postgresUser}&password=${Config.postgresPassword}")
|
||||
val createTable =
|
||||
pool.sendPreparedStatement("CREATE TABLE IF NOT EXISTS ${Config.postgresTable}(uuid TEXT, bank_balance decimal, inventory_balance decimal, ender_chest_balance decimal, unique(uuid))")
|
||||
pool.sendPreparedStatement("CREATE TABLE IF NOT EXISTS ${Config.postgresTable}(uuid TEXT, bank_balance integer, inventory_balance integer, ender_chest_balance integer, unique(uuid))")
|
||||
createTable.join()
|
||||
val createIndex =
|
||||
pool.sendPreparedStatement("CREATE INDEX IF NOT EXISTS idx_balance ON ${Config.postgresTable}(bank_balance, inventory_balance, ender_chest_balance)")
|
||||
@@ -36,7 +35,7 @@ class PostgreSQL {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setPlayerBalance(uuid: UUID, balance: Double, type: BalanceType): Boolean {
|
||||
suspend fun setPlayerBalance(uuid: UUID, balance: Int, type: BalanceType): Boolean {
|
||||
try {
|
||||
val connection = pool.asSuspending.connect()
|
||||
|
||||
@@ -56,21 +55,21 @@ class PostgreSQL {
|
||||
return false
|
||||
}
|
||||
|
||||
suspend fun addToPlayerBalance(uuid: UUID, amount: Double, type: BalanceType): Boolean {
|
||||
suspend fun addToPlayerBalance(uuid: UUID, amount: Int, type: BalanceType): Boolean {
|
||||
val playerBalance = getPlayerBalanceWrapper(uuid, type) ?: return true
|
||||
|
||||
val error = setPlayerBalance(uuid, playerBalance + amount, type)
|
||||
return error
|
||||
}
|
||||
|
||||
suspend fun subtractFromPlayerBalance(uuid: UUID, amount: Double, type: BalanceType): Boolean {
|
||||
suspend fun subtractFromPlayerBalance(uuid: UUID, amount: Int, type: BalanceType): Boolean {
|
||||
val playerBalance = getPlayerBalanceWrapper(uuid, type) ?: return true
|
||||
|
||||
val error = setPlayerBalance(uuid, playerBalance - amount, type)
|
||||
return error
|
||||
}
|
||||
|
||||
private suspend fun getPlayerBalanceWrapper(uuid: UUID, type: BalanceType): Double? {
|
||||
private suspend fun getPlayerBalanceWrapper(uuid: UUID, type: BalanceType): Int? {
|
||||
val playerBalance = getPlayerBalance(uuid, type)
|
||||
|
||||
return when (type) {
|
||||
@@ -81,12 +80,12 @@ class PostgreSQL {
|
||||
}
|
||||
}
|
||||
|
||||
data class PlayerBalance(val bankBalance: Double?, val inventoryBalance: Double?, val enderChestBalance: Double?)
|
||||
data class PlayerBalance(val bankBalance: Int?, val inventoryBalance: Int?, val enderChestBalance: Int?)
|
||||
|
||||
suspend fun getPlayerBalance(uuid: UUID, type: BalanceType): PlayerBalance {
|
||||
var bankBalance: Double? = null
|
||||
var inventoryBalance: Double? = null
|
||||
var enderChestBalance: Double? = null
|
||||
var bankBalance: Int? = null
|
||||
var inventoryBalance: Int? = null
|
||||
var enderChestBalance: Int? = null
|
||||
try {
|
||||
val connection = pool.asSuspending.connect()
|
||||
|
||||
@@ -107,38 +106,38 @@ class PostgreSQL {
|
||||
when (type) {
|
||||
BalanceType.BANK_BALANCE -> {
|
||||
bankBalance = if (rowData.columns[0] != null) {
|
||||
(rowData.columns[0] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[0] as Int
|
||||
} else 0
|
||||
}
|
||||
|
||||
BalanceType.INVENTORY_BALANCE -> {
|
||||
inventoryBalance = if (rowData.columns[0] != null) {
|
||||
(rowData.columns[0] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[0] as Int
|
||||
} else 0
|
||||
}
|
||||
|
||||
BalanceType.ENDER_CHEST_BALANCE -> {
|
||||
enderChestBalance = if (rowData.columns[0] != null) {
|
||||
(rowData.columns[0] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[0] as Int
|
||||
} else 0
|
||||
}
|
||||
|
||||
BalanceType.ALL -> {
|
||||
bankBalance = if (rowData.columns[0] != null) {
|
||||
(rowData.columns[0] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[0] as Int
|
||||
} else 0
|
||||
inventoryBalance = if (rowData.columns[1] != null) {
|
||||
(rowData.columns[1] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[1] as Int
|
||||
} else 0
|
||||
enderChestBalance = if (rowData.columns[2] != null) {
|
||||
(rowData.columns[2] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[2] as Int
|
||||
} else 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bankBalance = 0.0
|
||||
inventoryBalance = 0.0
|
||||
enderChestBalance = 0.0
|
||||
bankBalance = 0
|
||||
inventoryBalance = 0
|
||||
enderChestBalance = 0
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DiamondBankOG.plugin.logger.info(e.toString())
|
||||
@@ -146,24 +145,24 @@ class PostgreSQL {
|
||||
return PlayerBalance(bankBalance, inventoryBalance, enderChestBalance)
|
||||
}
|
||||
|
||||
suspend fun getBaltop(offset: Int): MutableMap<String?, Double>? {
|
||||
suspend fun getBaltop(offset: Int): MutableMap<String?, Int>? {
|
||||
try {
|
||||
val connection = pool.asSuspending.connect()
|
||||
val preparedStatement =
|
||||
connection.sendPreparedStatement("SELECT * FROM ${Config.postgresTable} ORDER BY bank_balance DESC, inventory_balance DESC, ender_chest_balance DESC OFFSET $offset LIMIT 10")
|
||||
val result = preparedStatement.await()
|
||||
val baltop = mutableMapOf<String?, Double>()
|
||||
val baltop = mutableMapOf<String?, Int>()
|
||||
result.rows.forEach {
|
||||
val rowData = it as ArrayRowData
|
||||
val bankBalance = if (rowData.columns[1] != null) {
|
||||
(rowData.columns[1] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[1] as Int
|
||||
} else 0
|
||||
val inventoryBalance = if (rowData.columns[2] != null) {
|
||||
(rowData.columns[2] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[2] as Int
|
||||
} else 0
|
||||
val enderChestBalance = if (rowData.columns[3] != null) {
|
||||
(rowData.columns[3] as BigDecimal).toDouble()
|
||||
} else 0.0
|
||||
rowData.columns[3] as Int
|
||||
} else 0
|
||||
|
||||
val player = Bukkit.getPlayer(UUID.fromString(rowData.columns[0] as String)) ?: Bukkit.getOfflinePlayer(
|
||||
UUID.fromString(rowData.columns[0] as String)
|
||||
@@ -189,11 +188,27 @@ class PostgreSQL {
|
||||
val rowData = result.rows[0] as ArrayRowData
|
||||
number = if (rowData.columns[0] != null) {
|
||||
rowData.columns[0] as Long
|
||||
} else 0L
|
||||
} else 0
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DiamondBankOG.plugin.logger.info(e.toString())
|
||||
}
|
||||
return number
|
||||
}
|
||||
|
||||
suspend fun entryExists(uuid: UUID): Boolean {
|
||||
try {
|
||||
val connection = pool.asSuspending.connect()
|
||||
val preparedStatement =
|
||||
connection.sendPreparedStatement("SELECT 1 FROM ${Config.postgresTable} WHERE uuid = '${uuid}';")
|
||||
val result = preparedStatement.await()
|
||||
|
||||
if (result.rows.size == 1) {
|
||||
return true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DiamondBankOG.plugin.logger.info(e.toString())
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class Balance : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
val totalBalance = balance.bankBalance + balance.inventoryBalance + balance.enderChestBalance
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("<green>Balance of <red>${otherPlayer.name}<green>: <yellow>$totalBalance <aqua>${if (totalBalance <= 1.0) "Diamond" else "Diamonds"} <white>(<red>Bank: <yellow>${balance.bankBalance}<white>, <red>Inventory: <yellow>${balance.inventoryBalance}<white>, <red>Ender Chest: <yellow>${balance.enderChestBalance}<white>)."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("<green>Balance of <red>${otherPlayer.name}<green>: <yellow>$totalBalance <aqua>${if (totalBalance == 1) "Diamond" else "Diamonds"} <white>(<red>Bank: <yellow>${balance.bankBalance}<white>, <red>Inventory: <yellow>${balance.inventoryBalance}<white>, <red>Ender Chest: <yellow>${balance.enderChestBalance}<white>)."))
|
||||
return@launch
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class Balance : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
val totalBalance = balance.bankBalance + balance.inventoryBalance + balance.enderChestBalance
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("<green>Balance${if (balancePlayer.uniqueId != sender.uniqueId) " of <red>${balancePlayer.name}" else ""}<green>: <yellow>$totalBalance <aqua>${if (totalBalance <= 1.0) "Diamond" else "Diamonds"} <white>(<red>Bank: <yellow>${balance.bankBalance}<white>, <red>Inventory: <yellow>${balance.inventoryBalance}<white>, <red>Ender Chest: <yellow>${balance.enderChestBalance}<white>)."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("<green>Balance${if (balancePlayer.uniqueId != sender.uniqueId) " of <red>${balancePlayer.name}" else ""}<green>: <yellow>$totalBalance <aqua>${if (totalBalance == 1) "Diamond" else "Diamonds"} <white>(<red>Bank: <yellow>${balance.bankBalance}<white>, <red>Inventory: <yellow>${balance.inventoryBalance}<white>, <red>Ender Chest: <yellow>${balance.enderChestBalance}<white>)."))
|
||||
return@launch
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -44,12 +44,12 @@ class Balancetop : CommandExecutor {
|
||||
|
||||
val baltop = DiamondBankOG.postgreSQL.getBaltop(offset)
|
||||
if (baltop == null) {
|
||||
sender.sendMessage("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop.")
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."))
|
||||
return@launch
|
||||
}
|
||||
val numberOfRows = DiamondBankOG.postgreSQL.getNumberOfRows()
|
||||
if (numberOfRows == null) {
|
||||
sender.sendMessage("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop.")
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."))
|
||||
return@launch
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class Balancetop : CommandExecutor {
|
||||
("<yellow>---- <gold>Balancetop <yellow>-- <gold>Page <red>$index<gold>/<red>${ceil(numberOfRows / 10.0).toLong()} <yellow>----<reset>")
|
||||
baltop.forEach {
|
||||
if (it.key == null) {
|
||||
sender.sendMessage("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop.")
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to get the information for balancetop."))
|
||||
return@launch
|
||||
}
|
||||
baltopMessage += "\n<red>${baltopMessage.lines().size + (10 * (index - 1))}<reset>. ${if (it.key == sender.name) "<red>" else ""}${it.key}<reset>, ${it.value}"
|
||||
|
||||
@@ -59,7 +59,7 @@ class Deposit : CommandExecutor {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to get your balance."))
|
||||
return@launch
|
||||
}
|
||||
if (playerBalance.inventoryBalance == 0.0) {
|
||||
if (playerBalance.inventoryBalance == 0) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You don't have any <aqua>Diamonds <red>to deposit."))
|
||||
return@launch
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class Deposit : CommandExecutor {
|
||||
var amount = playerBalance.inventoryBalance
|
||||
if (args[0] != "all") {
|
||||
try {
|
||||
amount = args[0].toDouble()
|
||||
amount = args[0].toInt()
|
||||
if (amount < 0) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot deposit a negative amount."))
|
||||
return@launch
|
||||
@@ -78,7 +78,7 @@ class Deposit : CommandExecutor {
|
||||
}
|
||||
|
||||
if (amount > playerBalance.inventoryBalance) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"} <red>in your inventory."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"} <red>in your inventory."))
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ class Deposit : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully deposited <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"} <green>into your bank account."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully deposited <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"} <green>into your bank account."))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ class Pay : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
var amount = -1.0
|
||||
if (args[0] != "all") {
|
||||
var amount = -1
|
||||
if (args[1] != "all") {
|
||||
try {
|
||||
amount = args[1].toDouble()
|
||||
amount = args[1].toInt()
|
||||
if (amount < 0) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot pay a negative amount."))
|
||||
return@launch
|
||||
@@ -94,11 +94,11 @@ class Pay : CommandExecutor {
|
||||
)
|
||||
}
|
||||
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully paid <yellow>$withdrawnAmount <aqua>${if (withdrawnAmount <= 1.0) "Diamond" else "Diamonds"} <green>to <red>${receiver.name}<green>."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully paid <yellow>$withdrawnAmount <aqua>${if (withdrawnAmount == 1) "Diamond" else "Diamonds"} <green>to <red>${receiver.name}<green>."))
|
||||
|
||||
if (receiver.isOnline) {
|
||||
val receiverPlayer = receiver.player ?: return@launch
|
||||
receiverPlayer.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>${sender.name} has paid you <yellow>$withdrawnAmount <aqua>${if (withdrawnAmount <= 1.0) "Diamond" else "Diamonds"}<green>."))
|
||||
receiverPlayer.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>${sender.name} has paid you <yellow>$withdrawnAmount <aqua>${if (withdrawnAmount == 1) "Diamond" else "Diamonds"}<green>."))
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -45,9 +45,9 @@ class SetBankBalance : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
val balance: Double
|
||||
val balance: Int
|
||||
try {
|
||||
balance = args[1].toDouble()
|
||||
balance = args[1].toInt()
|
||||
} catch (_: Exception) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Invalid argument."))
|
||||
return@launch
|
||||
@@ -59,7 +59,7 @@ class SetBankBalance : CommandExecutor {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to set that player's balance."))
|
||||
return@launch
|
||||
}
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully set the balance of <red>${player.name} <green>to <yellow>$balance <aqua>${if (balance == 1.0) "Diamond" else "Diamonds"}<green>."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully set the balance of <red>${player.name} <green>to <yellow>$balance <aqua>${if (balance == 1) "Diamond" else "Diamonds"}<green>."))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -54,10 +54,10 @@ class Withdraw : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
var amount = -1.0
|
||||
var amount = -1
|
||||
if (args[0] != "all") {
|
||||
try {
|
||||
amount = args[0].toDouble()
|
||||
amount = args[0].toInt()
|
||||
if (amount < 0) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot withdraw a negative amount."))
|
||||
return@launch
|
||||
@@ -75,10 +75,10 @@ class Withdraw : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (amount == -1.0) amount = playerBalance.bankBalance
|
||||
if (amount == -1) amount = playerBalance.bankBalance
|
||||
|
||||
if (amount > playerBalance.bankBalance) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Cannot withdraw <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"} <red>because your bank only contains <yellow>${playerBalance.bankBalance} <aqua>${if (playerBalance.bankBalance <= 1.0) "diamond" else "diamonds"}<red>."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Cannot withdraw <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"} <red>because your bank only contains <yellow>${playerBalance.bankBalance} <aqua>${if (playerBalance.bankBalance == 1) "diamond" else "diamonds"}<red>."))
|
||||
return@launch
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class Withdraw : CommandExecutor {
|
||||
val leftOverSpace = sender.inventory.storageContents.filterNotNull().filter { it.type == Material.DIAMOND }
|
||||
.sumOf { 64 - it.amount }
|
||||
if (amount > (emptySlots + leftOverSpace)) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You don't have enough inventory space to withdraw <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"}<red>."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You don't have enough inventory space to withdraw <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"}<red>."))
|
||||
DiamondBankOG.blockInventoryFor.remove(sender.uniqueId)
|
||||
return@launch
|
||||
}
|
||||
@@ -131,9 +131,9 @@ class Withdraw : CommandExecutor {
|
||||
DiamondBankOG.blockInventoryFor.remove(sender.uniqueId)
|
||||
return@launch
|
||||
}
|
||||
sender.inventory.addItem(ItemStack(Material.DIAMOND, amount.toInt()))
|
||||
sender.inventory.addItem(ItemStack(Material.DIAMOND, amount))
|
||||
DiamondBankOG.blockInventoryFor.remove(sender.uniqueId)
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully withdrew <yellow>$amount <aqua>${if (amount <= 1.0) "Diamond" else "Diamonds"} <green>from your bank account."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully withdrew <yellow>$amount <aqua>${if (amount == 1) "Diamond" else "Diamonds"} <green>from your bank account."))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user