Compare commits

...
52 Commits
Author SHA1 Message Date
NotAlexNoyle 3dca9160c7 Sync gradle versions across branches 2025-06-05 11:34:43 -04:00
NotAlexNoyle 2bcc3c6af7 Update gradle 2025-06-02 19:21:32 -04:00
NotAlexNoyle 223b124f5c Merge pull request #12 from SKBotNL/master
Update Shadow to 8.3.6
2025-06-02 19:16:36 -04:00
Sven 9ea3a45341 Update Shadow to 8.3.6 2025-06-01 23:14:00 +02:00
NotAlexNoyle 8a1782804e Merge pull request #10 from SKBotNL/master
API calls are now null if the economy is disabled
2025-05-28 02:46:36 -04:00
Sven 1723dc8c0c Merge branch 'true-og:master' into master 2025-05-27 12:57:20 +02:00
SKBotNL 3db90103e1 API calls are now null if the economy is disabled 2025-05-27 12:57:05 +02:00
NotAlexNoyle 2c5d1ab576 Merge pull request #9 from SKBotNL/master
Change API to use Bukkit's ServiceManager
2025-05-26 08:40:40 -04:00
Sven 63b490ed39 Merge branch 'true-og:master' into master 2025-05-26 14:39:29 +02:00
SKBotNL 31e41cdc5a Change API to use the Bukkit ServicesManager 2025-05-26 14:29:23 +02:00
NotAlexNoyle 5ffb160f25 Merge pull request #8 from SKBotNL/master
Bump org.jetbrains.kotlin.jvm from 2.1.0 to 2.1.21
2025-05-25 07:47:59 -04:00
Sven 5a45860f4c Merge pull request #59 from SKBotNL/dependabot/gradle/org.jetbrains.kotlin.jvm-2.1.21
Bump org.jetbrains.kotlin.jvm from 2.1.0 to 2.1.21
2025-05-25 13:46:56 +02:00
dependabot[bot] 28a674cc6c Bump org.jetbrains.kotlin.jvm from 2.1.0 to 2.1.21
Bumps [org.jetbrains.kotlin.jvm](https://github.com/JetBrains/kotlin) from 2.1.0 to 2.1.21.
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](https://github.com/JetBrains/kotlin/compare/v2.1.0...v2.1.21)

---
updated-dependencies:
- dependency-name: org.jetbrains.kotlin.jvm
  dependency-version: 2.1.21
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-13 14:25:49 +00:00
NotAlexNoyle 0a5c35f057 Merge pull request #7 from SKBotNL/master
Update dependencies (master)
2025-05-05 10:57:57 -04:00
Sven 8997512b46 Update gradle.yml 2025-04-24 20:39:08 +02:00
Sven 5c7ab67726 Merge pull request #40 from SKBotNL/dependabot/gradle/io.sentry-sentry-kotlin-extensions-8.7.0
Bump io.sentry:sentry-kotlin-extensions from 7.20.0 to 8.7.0
2025-04-24 20:37:34 +02:00
Sven f82b20919d Create gradle.yml 2025-04-24 20:36:08 +02:00
dependabot[bot] 2445f1e490 Bump io.sentry:sentry-kotlin-extensions from 7.20.0 to 8.7.0
Bumps [io.sentry:sentry-kotlin-extensions](https://github.com/getsentry/sentry-java) from 7.20.0 to 8.7.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-java/compare/7.20.0...8.7.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry-kotlin-extensions
  dependency-version: 8.7.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-24 18:34:30 +00:00
Sven b25b66b62f Merge pull request #43 from SKBotNL/dependabot/gradle/io.sentry-sentry-8.8.0
Bump io.sentry:sentry from 7.20.0 to 8.8.0
2025-04-24 20:33:28 +02:00
dependabot[bot] 220c1e1bb6 Bump io.sentry:sentry from 7.20.0 to 8.8.0
Bumps [io.sentry:sentry](https://github.com/getsentry/sentry-java) from 7.20.0 to 8.8.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-java/compare/7.20.0...8.8.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry
  dependency-version: 8.8.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-15 14:30:24 +00:00
Sven 80fa951e56 Merge pull request #1 from SKBotNL/dependabot/gradle/io.sentry-sentry-7.20.0
Bump io.sentry:sentry from 7.14.0 to 7.20.0
2025-01-03 19:06:31 +00:00
dependabot[bot] af428263b5 Bump io.sentry:sentry from 7.14.0 to 7.20.0
Bumps [io.sentry:sentry](https://github.com/getsentry/sentry-java) from 7.14.0 to 7.20.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-java/compare/7.14.0...7.20.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-03 19:05:49 +00:00
Sven cee62fbe5c Merge pull request #2 from SKBotNL/dependabot/gradle/io.sentry-sentry-kotlin-extensions-7.20.0
Bump io.sentry:sentry-kotlin-extensions from 7.14.0 to 7.20.0
2025-01-03 19:05:05 +00:00
Sven 404111d5ce Merge pull request #3 from SKBotNL/dependabot/gradle/org.jetbrains.kotlin.jvm-2.1.0
Bump org.jetbrains.kotlin.jvm from 2.0.21 to 2.1.0
2025-01-03 19:04:57 +00:00
Sven 1c9c60aae8 Run Dependabot for the shards branch 2025-01-03 18:51:04 +00:00
dependabot[bot] ac11753844 Bump org.jetbrains.kotlin.jvm from 2.0.21 to 2.1.0
Bumps [org.jetbrains.kotlin.jvm](https://github.com/JetBrains/kotlin) from 2.0.21 to 2.1.0.
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](https://github.com/JetBrains/kotlin/compare/v2.0.21...v2.1.0)

---
updated-dependencies:
- dependency-name: org.jetbrains.kotlin.jvm
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-03 18:50:44 +00:00
dependabot[bot] e5b7697c7f Bump io.sentry:sentry-kotlin-extensions from 7.14.0 to 7.20.0
Bumps [io.sentry:sentry-kotlin-extensions](https://github.com/getsentry/sentry-java) from 7.14.0 to 7.20.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-java/compare/7.14.0...7.20.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry-kotlin-extensions
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-03 18:50:06 +00:00
NotAlexNoyle 337fc3f2b8 Update kotlin 2024-11-01 12:20:36 +00:00
NotAlexNoyle ad0a0ad2d4 Merge pull request #5 from true-og/baltop-fixes
Baltop fixes
2024-09-14 10:21:25 -04:00
SKBotNL 69e5fa2f64 Fix casting Long to Int error 2024-09-14 16:19:03 +02:00
SKBotNL 8fbb70bedf Add missing MiniMessage deserialization 2024-09-14 16:18:03 +02:00
NotAlexNoyle c816383e12 Merge pull request #4 from true-og/totalbalance-api
Add getPlayerTotalBalance() to the API
2024-09-14 08:42:40 -04:00
SKBotNL 29c4d46dd5 Add getPlayerTotalBalance() to the API 2024-09-14 14:37:06 +02:00
Sven e051856b7a Merge pull request #3 from true-og/fix/gradle
Fix build and remove unneeded repository
2024-09-14 14:16:41 +02:00
SKBotNL a9f0985398 Fix build and remove unneeded repository 2024-09-14 14:13:56 +02:00
NotAlexNoyle 25f66ba41f Merge pull request #2 from s0me0ne-coder/new
initial implementation of migration
2024-09-14 07:59:48 -04:00
SKBotNL 1293994911 Rewrite migration 2024-09-14 13:55:12 +02:00
Sven e9195e9573 Change migrated message 2024-09-14 12:18:16 +02:00
Sven 291a96f505 Change disablePlugin function 2024-09-14 12:15:39 +02:00
NotAlexNoyle 8ba2b53ba7 Merge pull request #1 from SKBotNL/master
Update dependencies
2024-09-14 06:00:19 -04:00
Sven a874878fb4 Merge pull request #3 from SKBotNL/dependabot/gradle/org.jetbrains.kotlin.jvm-2.0.20
Bump org.jetbrains.kotlin.jvm from 1.9.23 to 2.0.20
2024-09-14 11:52:46 +02:00
Sven 4561ffa3d2 Merge pull request #4 from SKBotNL/dependabot/gradle/io.sentry-sentry-7.14.0
Bump io.sentry:sentry from 7.8.0 to 7.14.0
2024-09-14 11:52:27 +02:00
s0me0ne-coder 4b6c64fabd initial implementation of migration 2024-09-12 14:42:48 +03:00
dependabot[bot] 9754218e85 Bump io.sentry:sentry from 7.8.0 to 7.14.0
Bumps [io.sentry:sentry](https://github.com/getsentry/sentry-java) from 7.8.0 to 7.14.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-java/compare/7.8.0...7.14.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-26 18:17:49 +00:00
dependabot[bot] 0d3b285111 Bump org.jetbrains.kotlin.jvm from 1.9.23 to 2.0.20
Bumps [org.jetbrains.kotlin.jvm](https://github.com/JetBrains/kotlin) from 1.9.23 to 2.0.20.
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](https://github.com/JetBrains/kotlin/compare/v1.9.23...v2.0.20)

---
updated-dependencies:
- dependency-name: org.jetbrains.kotlin.jvm
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-26 18:17:44 +00:00
Sven c366bccb66 Create dependabot.yml 2024-08-26 19:55:22 +02:00
Sven 09a14a7c85 Fix indentation 2024-07-02 21:56:06 +02:00
Sven bcc0a70d2e Merge pull request #1 from NotAlexNoyle/master
Update to gradle 8.8
2024-07-02 20:34:17 +02:00
NotAlexNoyle 8068f50d19 Update to gradle 8.8 2024-07-02 14:30:41 -04:00
SKBotNL 6962ab1a6c Update build.gradle.kts 2024-04-17 19:01:04 +02:00
Sven 1987d30f18 Update README.md 2024-04-10 21:16:04 +02:00
SKBotNL 322dd3f71b Change from Long to Int 2024-04-10 19:24:40 +02:00
19 changed files with 268 additions and 117 deletions

No files matched your search

+16
View File
@@ -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"
+67
View File
@@ -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
+2
View File
@@ -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
View File
@@ -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")
}
Binary file not shown.
+1 -1
View File
@@ -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
Vendored
+7 -5
View File
@@ -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
View File
@@ -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
}