Compare commits
9
Commits
53f68e973e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae5bc8a0f0 | ||
|
|
47e202a613 | ||
|
|
302575fb29 | ||
|
|
f61c95f3ab | ||
|
|
3be9a59370 | ||
|
|
f497ef1ee2 | ||
|
|
5f805ad0a7 | ||
|
|
55f5a95d73 | ||
|
|
2e9f984bd4 |
+3
-22
@@ -1,23 +1,4 @@
|
|||||||
# ---> Gradle
|
.direnv
|
||||||
|
.kotlin
|
||||||
.gradle
|
.gradle
|
||||||
**/build/
|
build
|
||||||
!src/**/build/
|
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
|
||||||
gradle-app.setting
|
|
||||||
|
|
||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
|
||||||
!gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Avoid ignore Gradle wrappper properties
|
|
||||||
!gradle-wrapper.properties
|
|
||||||
|
|
||||||
# Cache of project
|
|
||||||
.gradletasknamecache
|
|
||||||
|
|
||||||
# Eclipse Gradle plugin generated files
|
|
||||||
# Eclipse Core
|
|
||||||
.project
|
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
|
||||||
.classpath
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[submodule "kommand-lib"]
|
||||||
|
path = kommand-lib
|
||||||
|
url = git@gitea.hareworks.net:Hare/kommand-lib.git
|
||||||
|
branch=master
|
||||||
@@ -1,2 +1,7 @@
|
|||||||
# Simply-minecraft-db
|
# Simply-minecraft-db
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- [x] Configurable sharing options
|
||||||
|
- [x] Store config to database
|
||||||
|
- [x] Sync settings across multiple servers via a database
|
||||||
|
|||||||
+29
-67
@@ -1,22 +1,26 @@
|
|||||||
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
import net.minecrell.pluginyml.paper.PaperPluginDescription
|
||||||
|
|
||||||
group = "net.hareworks"
|
group = "net.hareworks"
|
||||||
version = "1.0"
|
version = "1.2"
|
||||||
|
|
||||||
val exposedVersion = "0.54.0"
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "2.0.20"
|
kotlin("jvm") version "2.2.21"
|
||||||
kotlin("plugin.serialization") version "2.0.20"
|
kotlin("plugin.serialization") version "2.2.21"
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
id("de.eldoria.plugin-yml.paper") version "0.8.0"
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
id("com.gradleup.shadow") version "9.2.2"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://repo.papermc.io/repository/maven-public/")
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
|
maven("https://repo.codemc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val exposedVersion = "0.54.0"
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib")
|
||||||
|
implementation("net.hareworks:kommand-lib:1.1")
|
||||||
implementation("net.kyori:adventure-api:4.17.0")
|
implementation("net.kyori:adventure-api:4.17.0")
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.17.0")
|
implementation("net.kyori:adventure-text-minimessage:4.17.0")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
|
||||||
@@ -26,74 +30,32 @@ dependencies {
|
|||||||
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
|
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")
|
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")
|
||||||
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion")
|
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion")
|
||||||
|
implementation("de.tr7zw:item-nbt-api:2.15.3")
|
||||||
}
|
}
|
||||||
tasks {
|
tasks {
|
||||||
shadowJar {
|
withType<Jar> {
|
||||||
archiveBaseName.set("SimplyMCDB")
|
archiveBaseName.set("SimplyMCDB")
|
||||||
archiveClassifier.set("")
|
}
|
||||||
|
shadowJar {
|
||||||
|
minimize {
|
||||||
|
exclude(dependency("org.jetbrains.exposed:exposed-core"))
|
||||||
|
exclude(dependency("org.jetbrains.exposed:exposed-dao"))
|
||||||
|
exclude(dependency("org.jetbrains.exposed:exposed-jdbc"))
|
||||||
|
exclude(dependency("org.jetbrains.exposed:exposed-kotlin-datetime"))
|
||||||
|
exclude(dependency("org.postgresql:postgresql"))
|
||||||
|
}
|
||||||
|
archiveClassifier.set("min")
|
||||||
|
relocate("de.tr7zw.changeme.nbtapi", "net.hareworks.simplymcdb.libs.nbtapi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bukkit {
|
paper {
|
||||||
main = "net.hareworks.simplymcdb.App"
|
main = "net.hareworks.simplymcdb.App"
|
||||||
name = "Simply-Minecraft-DB"
|
name = "Simply-Minecraft-DB"
|
||||||
description = "It provides a simple way to manage player data through a database."
|
description = "It provides a simple way to manage player data through a database."
|
||||||
version = getVersion().toString()
|
version = getVersion().toString()
|
||||||
apiVersion = "1.21.1"
|
apiVersion = "1.21.10"
|
||||||
authors =
|
authors = listOf(
|
||||||
listOf(
|
"Hare-K02"
|
||||||
"Hare-K02",
|
|
||||||
)
|
)
|
||||||
permissions {
|
|
||||||
register("simplydb.*") {
|
|
||||||
children = listOf("simplydb.command", "simplydb.admin")
|
|
||||||
}
|
|
||||||
register("simplydb.command") {
|
|
||||||
description = "Allows access to the /simplydb command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.TRUE
|
|
||||||
}
|
|
||||||
register("simplydb.command.*") {
|
|
||||||
children = listOf(
|
|
||||||
"simplydb.command.config",
|
|
||||||
"simplydb.command.config.*",
|
|
||||||
"simplydb.command.on",
|
|
||||||
"simplydb.command.off",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
register("simplydb.command.config") {
|
|
||||||
description = "Allows access to the /simplydb config command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.command.config.*") {
|
|
||||||
children = listOf(
|
|
||||||
"simplydb.command.config.reload",
|
|
||||||
"simplydb.command.config.fetch",
|
|
||||||
"simplydb.command.config.upload",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
register("simplydb.command.config.reload") {
|
|
||||||
description = "Allows access to the /simplydb config reload command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.command.config.fetch") {
|
|
||||||
description = "Allows access to the /simplydb config fetch command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.command.config.upload") {
|
|
||||||
description = "Allows access to the /simplydb config upload command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.command.on") {
|
|
||||||
description = "Allows access to the /simplydb on command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.command.off") {
|
|
||||||
description = "Allows access to the /simplydb off command"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
register("simplydb.admin") {
|
|
||||||
description = "Allows configration/manage simplydb"
|
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+61
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1764173365,
|
||||||
|
"narHash": "sha256-JaNFPy3nywPNxSDpEgFFqvngQww5Igb6twG4NhMo8oc=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "2fecba9952096ba043c16b9ef40b92851ff3e5d9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-25.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
description = "Minecraft dev environment with JDK 21 and Gradle";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
jdk21
|
||||||
|
gradle
|
||||||
|
kotlin
|
||||||
|
git
|
||||||
|
unzip
|
||||||
|
];
|
||||||
|
|
||||||
|
# 必要に応じて環境変数を設定
|
||||||
|
shellHook = ''
|
||||||
|
export JAVA_HOME=${pkgs.jdk21}/lib/openjdk
|
||||||
|
export PATH="$JAVA_HOME/bin:$PATH"
|
||||||
|
|
||||||
|
export GRADLE_USER_HOME="$PWD/.gradle"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
org.gradle.configuration-cache=true
|
||||||
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
|
|
||||||
|
kotlin.stdlib.default.dependency=false
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# This file was generated by the Gradle 'init' task.
|
||||||
|
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
|
||||||
Vendored
BIN
Binary file not shown.
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (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.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -83,10 +85,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -114,7 +114,7 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -133,10 +133,13 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
@@ -144,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -152,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -197,16 +200,20 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * 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.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-classpath "$CLASSPATH" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# 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 See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@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
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
rootProject.name = "simply-mcdb"
|
||||||
|
|
||||||
|
includeBuild("kommand-lib")
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
package net.hareworks.kommandlib
|
|
||||||
|
|
||||||
import kotlin.collections.listOf
|
|
||||||
import org.bukkit.Bukkit
|
|
||||||
import org.bukkit.command.CommandMap
|
|
||||||
import org.bukkit.command.CommandSender
|
|
||||||
import org.bukkit.command.PluginCommand
|
|
||||||
import org.bukkit.command.TabCompleter
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
|
||||||
|
|
||||||
class KommandLib(plugin: JavaPlugin, vararg routes: Pair<String, Argument>) {
|
|
||||||
val routes = routes.toMap()
|
|
||||||
init {
|
|
||||||
val f = Bukkit.getServer().javaClass.getDeclaredField("commandMap")
|
|
||||||
f.isAccessible = true
|
|
||||||
val commandMap = f.get(Bukkit.getServer()) as CommandMap
|
|
||||||
for ((name, _) in routes) {
|
|
||||||
commandMap.register(
|
|
||||||
plugin.getName(),
|
|
||||||
(PluginCommand::class
|
|
||||||
.java
|
|
||||||
.declaredConstructors
|
|
||||||
.first()
|
|
||||||
.apply { isAccessible = true }
|
|
||||||
.newInstance(name, plugin) as
|
|
||||||
PluginCommand)
|
|
||||||
.apply {
|
|
||||||
this.name = name
|
|
||||||
this.setExecutor { sender, _, alias, args ->
|
|
||||||
val route = getLastRoute(arrayOf(alias, *args))
|
|
||||||
if (route.size == args.size + 1) route.last().onCommand(sender, args)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
this.tabCompleter = TabCompleter { sender, _, alias, args ->
|
|
||||||
val route = getLastRoute(arrayOf(alias, *args))
|
|
||||||
if (route.size == args.size) route.last().getCompletList(sender, args)
|
|
||||||
else listOf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLastRoute(args: Array<String>): List<Argument> {
|
|
||||||
val list = mutableListOf<Argument>(routes[args[0]] ?: throw Exception("Invalid command"))
|
|
||||||
var i = 1
|
|
||||||
while (i + 1 <= args.size) {
|
|
||||||
if (list.last().routes.isEmpty()) break
|
|
||||||
val route =
|
|
||||||
list.last().routes.values.sortedBy { it.priority }.find { it.typeCheck(args[i]) } ?: break
|
|
||||||
list.add(route)
|
|
||||||
i += route.unit
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unregister() {
|
|
||||||
val f = Bukkit.getServer().javaClass.getDeclaredField("commandMap")
|
|
||||||
f.isAccessible = true
|
|
||||||
val commandMap = f.get(Bukkit.getServer()) as CommandMap
|
|
||||||
for ((name, _) in routes) {
|
|
||||||
commandMap.getCommand(name)?.unregister(commandMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Argument(
|
|
||||||
vararg routes: Pair<String, Argument>,
|
|
||||||
val execute: (CommandSender, Array<Any>) -> Unit
|
|
||||||
) {
|
|
||||||
val routes = routes.toMap()
|
|
||||||
var name: String = ""
|
|
||||||
var permission: String = ""
|
|
||||||
set(value) {
|
|
||||||
field = value
|
|
||||||
if (value.isEmpty()) return
|
|
||||||
for ((_, route) in routes) {
|
|
||||||
route.permission = value + "." + route.name
|
|
||||||
}
|
|
||||||
println("permission setted to $value")
|
|
||||||
}
|
|
||||||
var condition: (CommandSender) -> Boolean = { true }
|
|
||||||
|
|
||||||
init {
|
|
||||||
for ((name, route) in routes) {
|
|
||||||
route.name = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract var priority: Int
|
|
||||||
open var unit: Int = 1
|
|
||||||
abstract fun onCommand(sender: CommandSender, args: Array<String>)
|
|
||||||
abstract fun typeCheck(arg: String): Boolean
|
|
||||||
abstract fun toValue(args: Array<String>): Any
|
|
||||||
|
|
||||||
abstract fun suggest(sender: CommandSender, args: Array<String>): List<String>
|
|
||||||
|
|
||||||
fun getCompletList(sender: CommandSender, args: Array<String>): List<String> {
|
|
||||||
return routes
|
|
||||||
.values
|
|
||||||
.filter { sender.hasPermission(it.permission) && it.condition(sender) }
|
|
||||||
.map { it.suggest(sender, args) }
|
|
||||||
.flatten()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Route(vararg routes: Pair<String, Argument>, execute: (CommandSender, Array<Any>) -> Unit) :
|
|
||||||
Argument(*routes, execute = execute) {
|
|
||||||
override var priority: Int = 2
|
|
||||||
override fun onCommand(sender: CommandSender, args: Array<String>) {
|
|
||||||
execute(sender, args.map { it }.toTypedArray())
|
|
||||||
}
|
|
||||||
override fun typeCheck(arg: String): Boolean {
|
|
||||||
return this.name == arg
|
|
||||||
}
|
|
||||||
override fun toValue(args: Array<String>): Any {
|
|
||||||
return args.joinToString(" ")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun suggest(sender: CommandSender, args: Array<String>): List<String> {
|
|
||||||
return if (sender.hasPermission(this.permission) && this.condition(sender) && this.name.startsWith(args.last()))
|
|
||||||
listOf(this.name)
|
|
||||||
else listOf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Text(vararg routes: Pair<String, Argument>, execute: (CommandSender, Array<Any>) -> Unit) :
|
|
||||||
Argument(*routes, execute = execute) {
|
|
||||||
override var priority: Int = 0
|
|
||||||
override fun typeCheck(arg: String): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
override fun toValue(args: Array<String>): Any {
|
|
||||||
return args.joinToString(" ")
|
|
||||||
}
|
|
||||||
override fun onCommand(sender: CommandSender, args: Array<String>) {
|
|
||||||
execute(sender, args.map { it }.toTypedArray())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun suggest(sender: CommandSender, args: Array<String>): List<String> {
|
|
||||||
return listOf(args.last())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Integer(vararg routes: Pair<String, Argument>, execute: (CommandSender, Array<Any>) -> Unit) :
|
|
||||||
Argument(*routes, execute = execute) {
|
|
||||||
override var priority: Int = 1
|
|
||||||
override fun typeCheck(arg: String): Boolean {
|
|
||||||
return arg.toIntOrNull() != null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCommand(sender: CommandSender, args: Array<String>) {
|
|
||||||
execute(sender, args.map { it.toInt() }.toTypedArray())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toValue(args: Array<String>): Any {
|
|
||||||
return args[0].toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun suggest(sender: CommandSender, args: Array<String>): List<String> {
|
|
||||||
return listOf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Position(
|
|
||||||
vararg routes: Pair<String, Argument>,
|
|
||||||
execute: (CommandSender, Array<Any>) -> Unit
|
|
||||||
) : Argument(*routes, execute = execute) {
|
|
||||||
override var priority: Int = 3
|
|
||||||
override var unit: Int = 3
|
|
||||||
override fun typeCheck(arg: String): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCommand(sender: CommandSender, args: Array<String>) {
|
|
||||||
execute(sender, args.map { it }.toTypedArray())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toValue(args: Array<String>): Any {
|
|
||||||
return Triple(args[0].toDouble(), args[1].toDouble(), args[2].toDouble())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun suggest(sender: CommandSender, args: Array<String>): List<String> {
|
|
||||||
return listOf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package net.hareworks.simplymcdb
|
package net.hareworks.simplymcdb
|
||||||
|
|
||||||
import net.hareworks.simplymcdb.Config
|
import net.hareworks.kommand_lib.KommandLib
|
||||||
|
import net.hareworks.simplymcdb.command.registerCommands
|
||||||
import net.hareworks.simplymcdb.database.Database
|
import net.hareworks.simplymcdb.database.Database
|
||||||
import net.hareworks.simplymcdb.command.smcdb
|
|
||||||
import net.hareworks.kommandlib.KommandLib
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
|
|
||||||
enum class State {
|
enum class State {
|
||||||
ACTIVE,
|
ACTIVE,
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
@@ -18,19 +18,25 @@ public class App : JavaPlugin() {
|
|||||||
field = value
|
field = value
|
||||||
Config.config.set("enabled", !value.equals(State.DISABLED))
|
Config.config.set("enabled", !value.equals(State.DISABLED))
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var instance: App
|
lateinit var instance: App
|
||||||
private set
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var command: KommandLib
|
lateinit var command: KommandLib
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
instance = this
|
instance = this
|
||||||
logger.info("simplymcdb enabled.")
|
|
||||||
|
|
||||||
Config.init()
|
Config.init()
|
||||||
command = KommandLib(this, "smcdb" to smcdb)
|
command = registerCommands(this)
|
||||||
|
|
||||||
|
server.pluginManager.registerEvents(EventListener, this)
|
||||||
|
|
||||||
|
if (Config.check()) enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisable() {
|
override fun onDisable() {
|
||||||
enabled = State.DISABLED
|
enabled = State.DISABLED
|
||||||
Database.disconnect()
|
Database.disconnect()
|
||||||
|
|||||||
@@ -1,119 +1,281 @@
|
|||||||
package net.hareworks.simplymcdb.command
|
package net.hareworks.simplymcdb.command
|
||||||
|
|
||||||
import net.hareworks.kommandlib.*
|
import java.util.UUID
|
||||||
|
import net.hareworks.kommand_lib.KommandLib
|
||||||
|
import net.hareworks.kommand_lib.kommand
|
||||||
import net.hareworks.simplymcdb.App
|
import net.hareworks.simplymcdb.App
|
||||||
|
import net.hareworks.simplymcdb.Config
|
||||||
import net.hareworks.simplymcdb.State
|
import net.hareworks.simplymcdb.State
|
||||||
import net.hareworks.simplymcdb.config.reload as reloadConfig
|
|
||||||
import net.hareworks.simplymcdb.database.Database
|
import net.hareworks.simplymcdb.database.Database
|
||||||
|
import net.hareworks.simplymcdb.fetch
|
||||||
|
import net.hareworks.simplymcdb.findPlayersNeedingMigration
|
||||||
|
import net.hareworks.simplymcdb.isRegistered
|
||||||
|
import net.hareworks.simplymcdb.overwritePlayerData
|
||||||
|
import net.hareworks.simplymcdb.register
|
||||||
|
import net.hareworks.simplymcdb.update
|
||||||
|
import net.hareworks.simplymcdb.PlayerSerializer
|
||||||
|
import net.kyori.adventure.audience.Audience
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
public val smcdb: Route =
|
private val miniMessage = MiniMessage.miniMessage()
|
||||||
Route(
|
private val commandBuffer = mutableMapOf<UUID, String>()
|
||||||
"config" to
|
|
||||||
Route(
|
public fun Audience.sendMM(message: String) {
|
||||||
"reload" to
|
this.sendMessage(miniMessage.deserialize(message))
|
||||||
Route { sender, _ ->
|
}
|
||||||
|
|
||||||
|
private fun Audience.sendConfigHelp() {
|
||||||
|
sendMM(
|
||||||
|
"<red>simplymcdb config help<newline><gray>reload: <green>reload the config from config.yml<newline><gray>fetch: <green>fetch the config from the database<newline><gray>upload: <green>upload the current config to the database")
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun registerCommands(plugin: JavaPlugin): KommandLib =
|
||||||
|
kommand(plugin) {
|
||||||
|
command("smcdb") {
|
||||||
|
description = "Control Simply-Minecraft-DB"
|
||||||
|
permission = "simplydb.command"
|
||||||
|
|
||||||
|
executes {
|
||||||
|
sender.sendMessage("simplymcdb command")
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("config") {
|
||||||
|
requires("simplydb.command.config")
|
||||||
|
executes { sender.sendConfigHelp() }
|
||||||
|
|
||||||
|
literal("reload") {
|
||||||
|
requires("simplydb.command.config.reload")
|
||||||
|
executes {
|
||||||
sender.sendMessage("reloading config...")
|
sender.sendMessage("reloading config...")
|
||||||
reloadConfig()
|
Config.reload()
|
||||||
sender.sendMessage("reloaded.")
|
sender.sendMessage("reloaded.")
|
||||||
}
|
}
|
||||||
.apply {
|
|
||||||
permission =
|
|
||||||
"simplydb.command.config.reload"
|
|
||||||
},
|
|
||||||
"fetch" to
|
|
||||||
Route { sender, _ ->
|
|
||||||
sender.sendMessage("fetching config...")
|
|
||||||
}
|
}
|
||||||
.apply {
|
|
||||||
permission =
|
literal("fetch") {
|
||||||
"simplydb.command.config.fetch"
|
requires("simplydb.command.config.fetch")
|
||||||
},
|
executes { sender.sendMessage("fetching config...") }
|
||||||
"upload" to
|
|
||||||
Route { sender, _ ->
|
|
||||||
sender.sendMessage("uploading config...")
|
|
||||||
}
|
}
|
||||||
.apply {
|
|
||||||
permission =
|
literal("upload") {
|
||||||
"simplydb.command.config.upload"
|
requires("simplydb.command.config.upload")
|
||||||
},
|
executes { sender.sendMessage("uploading config...") }
|
||||||
"help" to
|
|
||||||
Route { sender, _ ->
|
|
||||||
var help =
|
|
||||||
MiniMessage.miniMessage()
|
|
||||||
.deserialize(
|
|
||||||
"<red>simplymcdb config help<newline><gray>reload: <green>reload the config from config.yml<newline><gray>fetch: <green>fetch the config from the database<newline><gray>upload: <green>upload the current config to the database"
|
|
||||||
)
|
|
||||||
sender.sendMessage(help)
|
|
||||||
}
|
}
|
||||||
.apply {
|
|
||||||
permission =
|
literal("help") { executes { sender.sendConfigHelp() } }
|
||||||
"simplydb.command.config"
|
}
|
||||||
},
|
|
||||||
"on" to
|
literal("help") {
|
||||||
Route { sender, _ ->
|
executes {
|
||||||
if (App.instance.enabled == State.ACTIVE
|
sender.sendMM(
|
||||||
) {
|
"<red>simplymcdb help<newline><gray>config: <green>configre the plugin<newline><gray>activate: <green>when the plugin is disabled, activate it<newline><gray>deactivate: <green>when the plugin is enabled, deactivate it")
|
||||||
sender.sendMessage(
|
}
|
||||||
"simplymcdb is already enabled."
|
}
|
||||||
)
|
|
||||||
return@Route
|
literal("activate") {
|
||||||
|
requires("simplydb.command.on")
|
||||||
|
executes {
|
||||||
|
if (App.instance.enabled == State.ACTIVE) {
|
||||||
|
sender.sendMessage("simplymcdb is already enabled.")
|
||||||
|
return@executes
|
||||||
}
|
}
|
||||||
App.instance.enable()
|
App.instance.enable()
|
||||||
sender.sendMessage("simplymcdb enabled.")
|
sender.sendMessage("simplymcdb enabled.")
|
||||||
}
|
}
|
||||||
.apply {
|
}
|
||||||
permission = "simplydb.command.config.on"
|
|
||||||
},
|
literal("deactivate") {
|
||||||
"off" to
|
requires("simplydb.command.off")
|
||||||
Route { sender, _ ->
|
executes {
|
||||||
if (App.instance.enabled != State.ACTIVE
|
if (App.instance.enabled == State.DISABLED) {
|
||||||
) {
|
sender.sendMessage("simplymcdb is already disabled.")
|
||||||
sender.sendMessage(
|
return@executes
|
||||||
"simplymcdb is already disabled."
|
|
||||||
)
|
|
||||||
return@Route
|
|
||||||
}
|
}
|
||||||
App.instance.disable()
|
App.instance.disable()
|
||||||
sender.sendMessage("simplymcdb disabled.")
|
sender.sendMessage("simplymcdb disabled.")
|
||||||
}
|
}
|
||||||
.apply {
|
|
||||||
permission =
|
|
||||||
"simplydb.command.config.off"
|
|
||||||
},
|
|
||||||
) { sender, _ ->
|
|
||||||
(sender as ).performCommand("smcdb config help")
|
|
||||||
}
|
}
|
||||||
.apply { permission = "simplydb.command.config" },
|
|
||||||
"help" to Route { sender, _ ->
|
|
||||||
var help =
|
|
||||||
MiniMessage.miniMessage()
|
|
||||||
.deserialize(
|
|
||||||
"<red>simplymcdb help<newline><gray>config: <green>configre the plugin<newline><gray>activate: <green>when the plugin is disabled, activate it<newline><gray>deactivate: <green>when the plugin is enabled, deactivate it"
|
|
||||||
)
|
|
||||||
sender.sendMessage(help)
|
|
||||||
}
|
|
||||||
.apply { permission = "simplydb.command" },
|
|
||||||
"activate" to Route { sender, _ ->
|
|
||||||
if (App.instance.enabled == State.ACTIVE
|
|
||||||
) {
|
|
||||||
sender.sendMessage(
|
|
||||||
"simplymcdb is already enabled."
|
|
||||||
)
|
|
||||||
return@Route
|
|
||||||
}
|
|
||||||
App.instance.enable()
|
|
||||||
sender.sendMessage("simplymcdb enabled.")
|
|
||||||
}
|
|
||||||
.apply { permission = "simplydb.command.activate" },
|
|
||||||
"initialize" to Route { sender, _ ->
|
|
||||||
sender.sendMessage("database initializing...")
|
|
||||||
Database.initialize()
|
|
||||||
}
|
|
||||||
.apply { permission = "simplydb.command.setup" },
|
|
||||||
"confirm" to Route { sender, _ ->
|
|
||||||
|
|
||||||
|
literal("database") {
|
||||||
|
literal("init") {
|
||||||
|
executes {
|
||||||
|
Database.initialize()
|
||||||
|
sender.sendMessage("database initialized.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
literal("reset") {
|
||||||
|
executes {
|
||||||
|
Database.reset()
|
||||||
|
sender.sendMessage("database reset.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("migrate") {
|
||||||
|
executes {
|
||||||
|
val player = sender as? Player
|
||||||
|
if (player == null) {
|
||||||
|
sender.sendMM("<red>[SMCDB] This command can only be run by players.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
when (App.instance.enabled) {
|
||||||
|
State.DISABLED -> {
|
||||||
|
sender.sendMM("<red>[SMCDB] simplymcdb is disabled.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
State.DISCONNECTED -> {
|
||||||
|
sender.sendMM("<yellow>[SMCDB] Database disconnected. Try again later.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
if (!isRegistered(player.uniqueId)) {
|
||||||
|
sender.sendMM("<red>[SMCDB] You are not registered in the database.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sender.sendMM("<gray>[SMCDB] Applying legacy data...")
|
||||||
|
fetch(player)
|
||||||
|
update(player)
|
||||||
|
sender.sendMM("<green>[SMCDB] Migration complete. Data updated to the latest format.")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
App.instance.logger.warning("Failed to migrate data for ${player.uniqueId}: ${e.message}")
|
||||||
|
sender.sendMM("<red>[SMCDB] Migration failed. Check server logs.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("all") {
|
||||||
|
executes {
|
||||||
|
val executor = sender as? Player
|
||||||
|
if (executor == null) {
|
||||||
|
sender.sendMM("<red>[SMCDB] This command can only be run by players.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
when (App.instance.enabled) {
|
||||||
|
State.DISABLED -> {
|
||||||
|
sender.sendMM("<red>[SMCDB] simplymcdb is disabled.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
State.DISCONNECTED -> {
|
||||||
|
sender.sendMM("<yellow>[SMCDB] Database disconnected. Try again later.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
val targets = findPlayersNeedingMigration()
|
||||||
|
if (targets.isEmpty()) {
|
||||||
|
sender.sendMM("<gray>[SMCDB] No legacy data found.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
sender.sendMM("<gray>[SMCDB] Migrating ${targets.size} legacy profiles... Please wait.")
|
||||||
|
val backup = PlayerSerializer.serialize(executor)
|
||||||
|
var migrated = 0
|
||||||
|
try {
|
||||||
|
targets.forEach { entry ->
|
||||||
|
try {
|
||||||
|
PlayerSerializer.deserialize(executor, entry.serialized)
|
||||||
|
val updatedSnapshot = PlayerSerializer.serialize(executor)
|
||||||
|
overwritePlayerData(entry.uuid, updatedSnapshot)
|
||||||
|
migrated++
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
App.instance.logger.warning("Failed to migrate data for ${entry.uuid}: ${ex.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
PlayerSerializer.deserialize(executor, backup)
|
||||||
|
} catch (restoreEx: Exception) {
|
||||||
|
App.instance.logger.warning("Failed to restore migration executor state: ${restoreEx.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMM("<green>[SMCDB] Migration finished ($migrated/${targets.size}). Check logs for failures.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("check") {
|
||||||
|
executes {
|
||||||
|
val commandSender = sender
|
||||||
|
commandSender.sendMM(
|
||||||
|
"${when (App.instance.enabled) {
|
||||||
|
State.ACTIVE -> "<green>●"
|
||||||
|
State.DISCONNECTED -> "<yellow>■"
|
||||||
|
State.DISABLED -> "<red>○"
|
||||||
|
}}<white> simply-minecraft-database")
|
||||||
|
commandSender.sendMM(
|
||||||
|
"status: ${when (App.instance.enabled) {
|
||||||
|
State.ACTIVE -> "<green>active"
|
||||||
|
State.DISCONNECTED -> "<yellow>disconnected"
|
||||||
|
State.DISABLED -> "<red>disabled"
|
||||||
|
}}")
|
||||||
|
commandSender.sendMM(
|
||||||
|
"<gray>- <white>config test: ${if (Config.config.getBoolean("enabled")) "enabled" else "disabled"}")
|
||||||
|
commandSender.sendMM("<gray>- <white>database test: <yellow>checking...")
|
||||||
|
|
||||||
|
// Run the potentially slow ping off the main thread to avoid freezing the server thread.
|
||||||
|
App.instance.server.scheduler.runTaskAsynchronously(App.instance, Runnable {
|
||||||
|
val pingSuccess = try {
|
||||||
|
Database.ping()
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
App.instance.logger.warning("Database ping failed: ${ex.message}")
|
||||||
|
false
|
||||||
|
}
|
||||||
|
App.instance.server.scheduler.runTask(App.instance, Runnable {
|
||||||
|
commandSender.sendMM(
|
||||||
|
"<gray>- <white>database test result: ${if (pingSuccess) "success" else "failed"}")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("register") {
|
||||||
|
executes {
|
||||||
|
val player = sender as? Player
|
||||||
|
if (player == null) {
|
||||||
|
sender.sendMM("This command is only available for players.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
when (App.instance.enabled) {
|
||||||
|
State.DISABLED -> {
|
||||||
|
sender.sendMM("<red>[SMCDB] simplymcdb is disabled.<br>Run /smcdb check to check the status.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
State.DISCONNECTED -> {
|
||||||
|
sender.sendMM("<red>[SMCDB] simplymcdb is enabled but disconnected.<br>Run /smcdb check to check the status.")
|
||||||
|
return@executes
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
if (!isRegistered(player.uniqueId)) {
|
||||||
|
sender.sendMM(
|
||||||
|
"<gray>[SMCDB] <red>The inventory of the other servers will be overwritten.<newline>" +
|
||||||
|
"Are you sure you want to register?<newline>" +
|
||||||
|
"<green>/smcdb confirm<gray> to confirm.")
|
||||||
|
commandBuffer[player.uniqueId] = "register"
|
||||||
|
} else {
|
||||||
|
sender.sendMM("<gray>[SMCDB] You are already registered.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal("confirm") {
|
||||||
|
executes {
|
||||||
|
val player = sender as? Player ?: return@executes
|
||||||
|
when (commandBuffer[player.uniqueId]) {
|
||||||
|
"register" -> {
|
||||||
|
if (App.instance.enabled == State.ACTIVE) {
|
||||||
|
register(player)
|
||||||
|
sender.sendMM("<gray>[SMCDB] Successfully registered.")
|
||||||
|
} else {
|
||||||
|
sender.sendMM("<red>[SMCDB] simplymcdb is disabled.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> sender.sendMM("<red>[SMCDB] Invalid command.")
|
||||||
|
}
|
||||||
|
commandBuffer.remove(player.uniqueId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.apply { permission = "simplydb.command.confirm" },
|
|
||||||
) { sender, _ -> sender.sendMessage("simplymcdb command") }
|
|
||||||
.apply { name = "simplymcdb" }
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.hareworks.simplymcdb
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration
|
import org.bukkit.configuration.file.YamlConfiguration
|
||||||
import org.jetbrains.exposed.sql.Table
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
|
||||||
|
|
||||||
object ConfigTable : Table() {
|
object ConfigTable : Table() {
|
||||||
val uuid = varchar("uuid", 36)
|
val uuid = varchar("uuid", 36)
|
||||||
val name = varchar("name", 16)
|
val name = varchar("name", 16)
|
||||||
@@ -34,4 +33,8 @@ public object Config {
|
|||||||
config.save(App.instance.dataFolder.resolve("config.yml"))
|
config.save(App.instance.dataFolder.resolve("config.yml"))
|
||||||
App.instance.logger.info("config saved.")
|
App.instance.logger.info("config saved.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun check(): Boolean {
|
||||||
|
return config.getBoolean("enabled")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package net.hareworks.simplymcdb.event
|
package net.hareworks.simplymcdb
|
||||||
|
|
||||||
import net.hareworks.simplymcdb.App
|
|
||||||
import net.hareworks.simplymcdb.State
|
|
||||||
import net.hareworks.simplymcdb.database.Database
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
|
||||||
|
|
||||||
public object EventListener : Listener {
|
public object EventListener : Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -16,27 +13,53 @@ public object EventListener : Listener {
|
|||||||
if (event.player.hasPermission("simplymcdb.admin")) {
|
if (event.player.hasPermission("simplymcdb.admin")) {
|
||||||
when (App.instance.enabled) {
|
when (App.instance.enabled) {
|
||||||
State.DISABLED -> {
|
State.DISABLED -> {
|
||||||
val mm = MiniMessage.miniMessage().deserialize("<red>simplymcdb is disabled.")
|
val mm =
|
||||||
|
MiniMessage.miniMessage()
|
||||||
|
.deserialize(
|
||||||
|
"<red>[SMCDB:admin] simplymcdb is disabled.<br>Run /smcdb check to check the status."
|
||||||
|
)
|
||||||
event.player.sendMessage(mm)
|
event.player.sendMessage(mm)
|
||||||
}
|
}
|
||||||
State.DISCONNECTED -> {
|
State.DISCONNECTED -> {
|
||||||
val mm = MiniMessage.miniMessage().deserialize("<red>simplymcdb is enabled but disconnected.<br><gray>Check the database connection and try /smcdb on.")
|
val mm =
|
||||||
|
MiniMessage.miniMessage()
|
||||||
|
.deserialize(
|
||||||
|
"<red>[SMCDB:admin] simplymcdb is enabled but disconnected.<br>Run /smcdb check to check the status."
|
||||||
|
)
|
||||||
event.player.sendMessage(mm)
|
event.player.sendMessage(mm)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val mm = MiniMessage.miniMessage().deserialize("<green>simplymcdb is enabled.")
|
val mm =
|
||||||
|
MiniMessage.miniMessage()
|
||||||
|
.deserialize("<green>[SMCDB:admin] simplymcdb is enabled.")
|
||||||
event.player.sendMessage(mm)
|
event.player.sendMessage(mm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (App.instance.enabled == State.ACTIVE) {
|
|
||||||
val player = event.player
|
|
||||||
// if player has already registered in the database, load the data
|
|
||||||
Database.instance?.let {
|
|
||||||
transaction(it) {
|
|
||||||
|
|
||||||
|
if (App.instance.enabled !== State.ACTIVE) return
|
||||||
|
|
||||||
|
/*-----------+-------------------+
|
||||||
|
| | played not |
|
||||||
|
+------------+-------------------+
|
||||||
|
| registered | fetch fetch |
|
||||||
|
| not | confirm register |
|
||||||
|
+------------+------------------*/
|
||||||
|
if (isRegistered(event.player.uniqueId)) fetch(event.player)
|
||||||
|
else if (event.player.hasPlayedBefore()) register(event.player)
|
||||||
|
else event.player.sendMessage(
|
||||||
|
MiniMessage.miniMessage()
|
||||||
|
.deserialize(
|
||||||
|
"<gray>[SMCDB] Welcome, ${event.player.name}.<newline>" +
|
||||||
|
"SMCDB is active but you have already played before.<newline>" +
|
||||||
|
"Run <green>/smcdb register<gray> to register yourself."
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
|
fun onQuit(event: PlayerQuitEvent) {
|
||||||
|
if (App.instance.enabled !== State.ACTIVE) return
|
||||||
|
if (isRegistered(event.player.uniqueId)) update(event.player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package net.hareworks.simplymcdb.playerdata
|
|
||||||
|
|
||||||
import net.hareworks.simplymcdb.App
|
|
||||||
import net.hareworks.simplymcdb.database.Database
|
|
||||||
import org.bukkit.entity.Player as BukkitPlayer
|
|
||||||
import org.jetbrains.exposed.sql.*
|
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
|
||||||
|
|
||||||
public object Player : Table() {
|
|
||||||
val uuid = varchar("uuid", 36)
|
|
||||||
val name = varchar("name", 16)
|
|
||||||
val lastLogin = long("last_login")
|
|
||||||
val lastLogout = long("last_logout")
|
|
||||||
val playTime = long("play_time")
|
|
||||||
val firstLogin = long("first_login")
|
|
||||||
val lastIp = varchar("last_ip", 15)
|
|
||||||
|
|
||||||
val data = text("data").nullable()
|
|
||||||
|
|
||||||
override val primaryKey = PrimaryKey(uuid)
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun register(player: BukkitPlayer) {
|
|
||||||
App.instance.logger.info("Registering player data for ${player.name}")
|
|
||||||
Database.instance?.let {
|
|
||||||
transaction {
|
|
||||||
Player.insert {
|
|
||||||
it[uuid] = player.uniqueId.toString()
|
|
||||||
it[name] = player.name
|
|
||||||
it[lastLogin] = System.currentTimeMillis()
|
|
||||||
it[firstLogin] = System.currentTimeMillis()
|
|
||||||
it[lastIp] = player.address?.address?.hostAddress ?: "unknown"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun push(player: BukkitPlayer) {
|
|
||||||
App.instance.logger.info("Creating player data for ${player.name}")
|
|
||||||
Database.instance?.let {
|
|
||||||
transaction {
|
|
||||||
Player.update({ Player.uuid eq player.uniqueId.toString() }) {
|
|
||||||
it[lastLogin] = System.currentTimeMillis()
|
|
||||||
it[lastIp] = player.address?.address?.hostAddress ?: "unknown"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,179 @@
|
|||||||
package net.hareworks.simplymcdb
|
package net.hareworks.simplymcdb
|
||||||
|
|
||||||
|
import de.tr7zw.changeme.nbtapi.NBT
|
||||||
|
import java.util.Base64
|
||||||
|
import java.util.function.Function
|
||||||
|
import io.papermc.paper.registry.RegistryAccess
|
||||||
|
import io.papermc.paper.registry.RegistryKey
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.SerializationException
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.bukkit.NamespacedKey
|
||||||
|
import org.bukkit.Registry
|
||||||
|
import org.bukkit.attribute.Attribute
|
||||||
import org.bukkit.entity.Player as BukkitPlayer
|
import org.bukkit.entity.Player as BukkitPlayer
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import org.bukkit.potion.PotionEffect
|
||||||
|
import org.bukkit.potion.PotionEffectType
|
||||||
|
|
||||||
class PlayerInventory(
|
const val PLAYER_DATA_CURRENT_VERSION = 1
|
||||||
val contents: Array<ItemStack>,
|
|
||||||
val armor: Array<ItemStack>,
|
@Serializable
|
||||||
|
data class PlayerSnapshot(
|
||||||
|
val version: Int = PLAYER_DATA_CURRENT_VERSION,
|
||||||
|
val health: Double,
|
||||||
|
val foodLevel: Int,
|
||||||
|
val xpProgress: Float,
|
||||||
|
val selectedItemSlot: Int,
|
||||||
|
val potionEffects: List<PotionEffectSnapshot>,
|
||||||
|
val inventory: List<ItemStackSnapshot?>,
|
||||||
|
val enderChest: List<ItemStackSnapshot?>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class PotionEffectSnapshot(
|
||||||
|
val type: String,
|
||||||
|
val amplifier: Int,
|
||||||
|
val duration: Int,
|
||||||
|
val ambient: Boolean,
|
||||||
|
val particles: Boolean,
|
||||||
|
val icon: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable data class ItemStackSnapshot(val payload: String)
|
||||||
|
|
||||||
|
private val json =
|
||||||
|
Json {
|
||||||
|
encodeDefaults = true
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
}
|
||||||
|
private val mobEffectRegistry: Registry<PotionEffectType>?
|
||||||
|
get() = RegistryAccess.registryAccess().getRegistry(RegistryKey.MOB_EFFECT)
|
||||||
|
|
||||||
object PlayerSerializer {
|
object PlayerSerializer {
|
||||||
fun serialize(player: BukkitPlayer): String {
|
fun serialize(player: BukkitPlayer): String {
|
||||||
val inv = player.inventory.storageContents
|
val snapshot =
|
||||||
val armor = player.inventory.armorContents
|
PlayerSnapshot(
|
||||||
val enderChest = player.enderChest
|
health = player.health,
|
||||||
|
foodLevel = player.foodLevel,
|
||||||
return "" // base64 encoded string
|
xpProgress = player.exp,
|
||||||
|
selectedItemSlot = player.inventory.heldItemSlot,
|
||||||
|
potionEffects = player.activePotionEffects.map(::serializePotionEffect),
|
||||||
|
inventory = player.inventory.contents.map { it?.let(::serializeItemStack) },
|
||||||
|
enderChest = player.enderChest.contents.map { it?.let(::serializeItemStack) }
|
||||||
|
)
|
||||||
|
return json.encodeToString(PlayerSnapshot.serializer(), snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserialize(data: String): Map<String, Any> {
|
fun deserialize(player: BukkitPlayer, data: String) {
|
||||||
return mapOf()
|
val snapshot =
|
||||||
|
try {
|
||||||
|
json.decodeFromString(PlayerSnapshot.serializer(), data)
|
||||||
|
} catch (ex: SerializationException) {
|
||||||
|
if (LegacySerializer.deserialize(player, data)) return else throw ex
|
||||||
|
} catch (ex: IllegalArgumentException) {
|
||||||
|
if (LegacySerializer.deserialize(player, data)) return else throw ex
|
||||||
|
}
|
||||||
|
applySnapshot(player, migrateIfNeeded(snapshot))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun migrateIfNeeded(snapshot: PlayerSnapshot): PlayerSnapshot {
|
||||||
|
var current = snapshot
|
||||||
|
var version = snapshot.version
|
||||||
|
while (version < PLAYER_DATA_CURRENT_VERSION) {
|
||||||
|
current = migrateOnce(version, current)
|
||||||
|
version++
|
||||||
|
}
|
||||||
|
return current
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun migrateOnce(fromVersion: Int, snapshot: PlayerSnapshot): PlayerSnapshot {
|
||||||
|
return when (fromVersion) {
|
||||||
|
1 -> snapshot
|
||||||
|
else -> snapshot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applySnapshot(player: BukkitPlayer, snapshot: PlayerSnapshot) {
|
||||||
|
val maxHealth = player.getAttribute(Attribute.MAX_HEALTH)?.value ?: player.health
|
||||||
|
player.health = snapshot.health.coerceIn(0.0, maxHealth)
|
||||||
|
player.foodLevel = snapshot.foodLevel.coerceIn(0, 20)
|
||||||
|
player.exp = snapshot.xpProgress.coerceIn(0f, 1f)
|
||||||
|
player.inventory.heldItemSlot =
|
||||||
|
snapshot.selectedItemSlot.coerceIn(0, player.inventory.contents.size - 1)
|
||||||
|
|
||||||
|
player.activePotionEffects.forEach { player.removePotionEffect(it.type) }
|
||||||
|
snapshot.potionEffects.forEach { eff ->
|
||||||
|
val typeKey = NamespacedKey.fromString(eff.type)
|
||||||
|
val type = typeKey?.let { key -> mobEffectRegistry?.get(key) }
|
||||||
|
if (type == null) {
|
||||||
|
App.instance.logger.warning("Unknown potion effect key during restore: ${eff.type}")
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
val potion = PotionEffect(type, eff.duration, eff.amplifier, eff.ambient, eff.particles, eff.icon)
|
||||||
|
player.addPotionEffect(potion)
|
||||||
|
}
|
||||||
|
|
||||||
|
player.inventory.clear()
|
||||||
|
snapshot.inventory.forEachIndexed { index, item ->
|
||||||
|
player.inventory.setItem(index, item?.let(::deserializeItemStack))
|
||||||
|
}
|
||||||
|
|
||||||
|
player.enderChest.clear()
|
||||||
|
snapshot.enderChest.forEachIndexed { index, item ->
|
||||||
|
player.enderChest.setItem(index, item?.let(::deserializeItemStack))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ItemStacksToBase64(item: Array<ItemStack>): String {
|
private fun serializePotionEffect(effect: PotionEffect): PotionEffectSnapshot {
|
||||||
return ""
|
val typeKey = effect.type.key().toString()
|
||||||
|
return PotionEffectSnapshot(
|
||||||
|
type = typeKey,
|
||||||
|
amplifier = effect.amplifier,
|
||||||
|
duration = effect.duration,
|
||||||
|
ambient = effect.isAmbient,
|
||||||
|
particles = effect.hasParticles(),
|
||||||
|
icon = effect.hasIcon()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromBase64(data: String): ByteArray {
|
private fun serializeItemStack(item: ItemStack): ItemStackSnapshot {
|
||||||
return byteArrayOf()
|
val bytes = item.ensureServerConversions().serializeAsBytes()
|
||||||
|
return ItemStackSnapshot(Base64.getEncoder().encodeToString(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deserializeItemStack(snapshot: ItemStackSnapshot): ItemStack {
|
||||||
|
val data = Base64.getDecoder().decode(snapshot.payload)
|
||||||
|
return ItemStack.deserializeBytes(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
private object LegacySerializer {
|
||||||
|
fun deserialize(player: BukkitPlayer, data: String): Boolean {
|
||||||
|
return try {
|
||||||
|
NBT.modify(
|
||||||
|
player,
|
||||||
|
Function { nbt ->
|
||||||
|
val input = NBT.parseNBT(data)
|
||||||
|
nbt.setFloat("Health", input.getFloat("Health"))
|
||||||
|
nbt.setInteger("foodLevel", input.getInteger("foodLevel"))
|
||||||
|
nbt.setFloat("XpP", input.getFloat("XpP"))
|
||||||
|
nbt.setInteger("SelectedItemSlot", input.getInteger("SelectedItemSlot"))
|
||||||
|
val activeEffects = nbt.getCompoundList("active_effects")
|
||||||
|
activeEffects.clear()
|
||||||
|
input.getCompoundList("active_effects").forEach { activeEffects.addCompound(it) }
|
||||||
|
val inventory = nbt.getCompoundList("Inventory")
|
||||||
|
inventory.clear()
|
||||||
|
input.getCompoundList("Inventory").forEach { inventory.addCompound(it) }
|
||||||
|
val enderchest = nbt.getCompoundList("EnderItems")
|
||||||
|
enderchest.clear()
|
||||||
|
input.getCompoundList("EnderItems").forEach { enderchest.addCompound(it) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
App.instance.logger.info("Legacy player data applied; will be migrated on next save.")
|
||||||
|
true
|
||||||
|
} catch (_: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package net.hareworks.simplymcdb
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
import net.hareworks.simplymcdb.database.Database
|
||||||
|
import org.bukkit.entity.Player as BukkitPlayer
|
||||||
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
public object Players : Table() {
|
||||||
|
val id = integer("id").autoIncrement()
|
||||||
|
|
||||||
|
val uuid = varchar("uuid", 36)
|
||||||
|
val name = varchar("name", 16)
|
||||||
|
val firstLogin = long("first_login")
|
||||||
|
val playTime = long("play_time").default(0)
|
||||||
|
val lastOnline = long("last_online").default(0)
|
||||||
|
val lastIp = varchar("last_ip", 15)
|
||||||
|
|
||||||
|
val data = text("data").default("")
|
||||||
|
val dataVersion = integer("data_version").default(0)
|
||||||
|
|
||||||
|
override val primaryKey = PrimaryKey(uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun isRegistered(player: UUID): Boolean {
|
||||||
|
return transaction(Database.instance) {
|
||||||
|
val data =
|
||||||
|
Players.select(Players.uuid).where { Players.uuid eq player.toString() }.map {
|
||||||
|
it[Players.uuid]
|
||||||
|
}
|
||||||
|
data.isNotEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun register(player: BukkitPlayer) {
|
||||||
|
transaction(Database.instance) {
|
||||||
|
Players.insert {
|
||||||
|
it[uuid] = player.uniqueId.toString()
|
||||||
|
it[name] = player.name
|
||||||
|
it[firstLogin] = System.currentTimeMillis()
|
||||||
|
it[lastOnline] = System.currentTimeMillis()
|
||||||
|
it[lastIp] = player.address?.address?.hostAddress ?: "unknown"
|
||||||
|
it[dataVersion] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun update(player: BukkitPlayer) {
|
||||||
|
val dat = PlayerSerializer.serialize(player)
|
||||||
|
transaction(Database.instance) {
|
||||||
|
Players.update({ Players.uuid eq player.uniqueId.toString() }) {
|
||||||
|
it[lastOnline] = System.currentTimeMillis()
|
||||||
|
it[lastIp] = player.address?.address?.hostAddress ?: "unknown"
|
||||||
|
|
||||||
|
// player.sendMessage(dat)
|
||||||
|
it[data] = dat
|
||||||
|
it[dataVersion] = PLAYER_DATA_CURRENT_VERSION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun fetch(player: BukkitPlayer) {
|
||||||
|
val dat =
|
||||||
|
transaction(Database.instance) {
|
||||||
|
Players.select(Players.uuid, Players.data)
|
||||||
|
.where { Players.uuid eq player.uniqueId.toString() }
|
||||||
|
.withDistinct()
|
||||||
|
.map { it[Players.data] }
|
||||||
|
.first()
|
||||||
|
}
|
||||||
|
// player.sendMessage(dat)
|
||||||
|
PlayerSerializer.deserialize(player, dat)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class PlayerDataEntry(val uuid: UUID, val serialized: String, val version: Int)
|
||||||
|
|
||||||
|
public fun findPlayersNeedingMigration(): List<PlayerDataEntry> {
|
||||||
|
return transaction(Database.instance) {
|
||||||
|
Players
|
||||||
|
.selectAll()
|
||||||
|
.where { (Players.dataVersion less PLAYER_DATA_CURRENT_VERSION) and (Players.data neq "") }
|
||||||
|
.map {
|
||||||
|
PlayerDataEntry(UUID.fromString(it[Players.uuid]), it[Players.data], it[Players.dataVersion])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun overwritePlayerData(uuid: UUID, data: String, version: Int = PLAYER_DATA_CURRENT_VERSION) {
|
||||||
|
transaction(Database.instance) {
|
||||||
|
Players.update({ Players.uuid eq uuid.toString() }) {
|
||||||
|
it[Players.data] = data
|
||||||
|
it[Players.dataVersion] = version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.hareworks.simplymcdb.database
|
package net.hareworks.simplymcdb.database
|
||||||
|
|
||||||
import net.hareworks.simplymcdb.App
|
import net.hareworks.simplymcdb.App
|
||||||
import net.hareworks.simplymcdb.config.config
|
import net.hareworks.simplymcdb.Config
|
||||||
import net.hareworks.simplymcdb.playerdata.Player
|
import net.hareworks.simplymcdb.Players
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
@@ -10,7 +10,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
public object Database {
|
public object Database {
|
||||||
public var instance: Database? = null
|
public var instance: Database? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
public fun connect() {
|
public fun connect() {
|
||||||
|
var config = Config.config
|
||||||
val type = config.getString("database.type")
|
val type = config.getString("database.type")
|
||||||
val host = config.getString("database.host")
|
val host = config.getString("database.host")
|
||||||
val port = config.getInt("database.port")
|
val port = config.getInt("database.port")
|
||||||
@@ -49,11 +51,7 @@ public object Database {
|
|||||||
}
|
}
|
||||||
if (instance == null) return
|
if (instance == null) return
|
||||||
App.instance.logger.info("Database connected: $host:$port/$database")
|
App.instance.logger.info("Database connected: $host:$port/$database")
|
||||||
if (!ping()) {
|
transaction(instance) { SchemaUtils.createMissingTablesAndColumns(Players) }
|
||||||
App.instance.logger.warning("Database ping failed")
|
|
||||||
} else {
|
|
||||||
App.instance.logger.info("Database ping successful")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public fun disconnect() {
|
public fun disconnect() {
|
||||||
instance?.let {
|
instance?.let {
|
||||||
@@ -66,20 +64,23 @@ public object Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun ping(): Boolean {
|
public fun ping(): Boolean {
|
||||||
|
val flag = (instance == null)
|
||||||
|
if (flag) connect()
|
||||||
return try {
|
return try {
|
||||||
transaction {
|
transaction(instance) { exec("SELECT 1") }
|
||||||
addLogger(StdOutSqlLogger)
|
|
||||||
exec("SELECT 1")
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
false
|
false
|
||||||
|
} finally {
|
||||||
|
if (flag) disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun initialize() {
|
public fun initialize() {
|
||||||
transaction {
|
transaction(instance) { SchemaUtils.create(Players) }
|
||||||
SchemaUtils.create(Player)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun reset() {
|
||||||
|
transaction(instance) { SchemaUtils.drop(Players) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
enable: false
|
|
||||||
database:
|
database:
|
||||||
type: postgresql
|
type: postgresql # Supported: mysql, postgresql
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 5432
|
port: 5432
|
||||||
|
# You must have created a database and user.
|
||||||
database: smcdb
|
database: smcdb
|
||||||
user: smcdb
|
user: smcdb
|
||||||
password: SaN1m_wk2eh9
|
password: password
|
||||||
playerdata:
|
|
||||||
|
playerdata: # README for more details.
|
||||||
health: true
|
health: true
|
||||||
hunger: true
|
hunger: true
|
||||||
experience: true
|
experience: true
|
||||||
status: true
|
effects: true
|
||||||
inventory: true
|
inventory: true
|
||||||
enderchest: true
|
enderchest: true
|
||||||
# achievements: true
|
# achievements: true
|
||||||
# recipebook: true
|
# recipebook: true
|
||||||
gamemode: true
|
gamemode: true
|
||||||
|
|
||||||
|
|
||||||
|
# Do not change this value manually,
|
||||||
|
# If the plugin settings are OK, enable it with the command.
|
||||||
|
enabled: false
|
||||||
Reference in New Issue
Block a user