diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b155595 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,71 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser \ No newline at end of file diff --git a/.idea/artifacts/MongoDBPlayer_jar.xml b/.idea/artifacts/MongoDBPlayer_jar.xml new file mode 100644 index 0000000..914e8e5 --- /dev/null +++ b/.idea/artifacts/MongoDBPlayer_jar.xml @@ -0,0 +1,17 @@ + + + $PROJECT_DIR$/../../Buildtools/Testing Enviroment (Latest)/plugins + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e3a35bf --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..4b14bf8 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f6a4583 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/MongoDBPlayer.main.iml b/.idea/modules/MongoDBPlayer.main.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/.idea/modules/MongoDBPlayer.main.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer.main.xml b/.idea/modules/module_mongodbplayer.main.xml new file mode 100644 index 0000000..01abd6b --- /dev/null +++ b/.idea/modules/module_mongodbplayer.main.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer.main_Thu_Jan_28_21-47-45_EST_2021.xml b/.idea/modules/module_mongodbplayer.main_Thu_Jan_28_21-47-45_EST_2021.xml new file mode 100644 index 0000000..01abd6b --- /dev/null +++ b/.idea/modules/module_mongodbplayer.main_Thu_Jan_28_21-47-45_EST_2021.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer.test.xml b/.idea/modules/module_mongodbplayer.test.xml new file mode 100644 index 0000000..b5fcfa5 --- /dev/null +++ b/.idea/modules/module_mongodbplayer.test.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer.test_Thu_Jan_28_21-47-45_EST_2021.xml b/.idea/modules/module_mongodbplayer.test_Thu_Jan_28_21-47-45_EST_2021.xml new file mode 100644 index 0000000..b5fcfa5 --- /dev/null +++ b/.idea/modules/module_mongodbplayer.test_Thu_Jan_28_21-47-45_EST_2021.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer.xml b/.idea/modules/module_mongodbplayer.xml new file mode 100644 index 0000000..b3660aa --- /dev/null +++ b/.idea/modules/module_mongodbplayer.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/module_mongodbplayer_Thu_Jan_28_21-47-45_EST_2021.xml b/.idea/modules/module_mongodbplayer_Thu_Jan_28_21-47-45_EST_2021.xml new file mode 100644 index 0000000..b3660aa --- /dev/null +++ b/.idea/modules/module_mongodbplayer_Thu_Jan_28_21-47-45_EST_2021.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/0/5/05efc8b1657769a27696d478ded1e95f38737233 b/.idea/sonarlint/issuestore/0/5/05efc8b1657769a27696d478ded1e95f38737233 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/0/7/0770c5700e0742cf1e00378d1fb47536431e6a28 b/.idea/sonarlint/issuestore/0/7/0770c5700e0742cf1e00378d1fb47536431e6a28 new file mode 100644 index 0000000..2389213 --- /dev/null +++ b/.idea/sonarlint/issuestore/0/7/0770c5700e0742cf1e00378d1fb47536431e6a28 @@ -0,0 +1,2 @@ + +t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(ͤ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/5/f/5f0f68bc285c15b426f28f5177d49e92734fa224 b/.idea/sonarlint/issuestore/5/f/5f0f68bc285c15b426f28f5177d49e92734fa224 new file mode 100644 index 0000000..3cf6ef5 --- /dev/null +++ b/.idea/sonarlint/issuestore/5/f/5f0f68bc285c15b426f28f5177d49e92734fa224 @@ -0,0 +1,24 @@ + +o java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(͙ +D +java:S1128".Remove this unused import 'org.bson.Document'.(ˮ +F +java:S1128"+Remove this unused import 'lombok.NonNull'.( +P +java:S1128 "5Remove this unused import 'org.bukkit.entity.Player'.(Ω +L +java:S1128"6Remove this unused import 'java.io.InputStreamReader'.( +G +java:S1128",Remove this unused import 'javax.print.Doc'.( +S +java:S1128"=Remove this unused import 'com.mongodb.client.model.Filters'.( +Q +java:S1128 "6Remove this unused import 'org.bson.conversions.Bson'.( +O +java:S1128"4Remove this unused import 'java.beans.EventHandler'.( +^ +java:S1128"CRemove this unused import 'com.mongodb.client.result.UpdateResult'.( +g +java:S1128 "LRemove this unused import 'org.bukkit.configuration.file.YamlConfiguration'.( +^ +java:S1128"CRemove this unused import 'com.mongodb.client.model.UpdateOptions'.(׷ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/6/e/6eabe8324ae3b5d46313e8948d8c24186eddd53c b/.idea/sonarlint/issuestore/6/e/6eabe8324ae3b5d46313e8948d8c24186eddd53c new file mode 100644 index 0000000..fb24f12 --- /dev/null +++ b/.idea/sonarlint/issuestore/6/e/6eabe8324ae3b5d46313e8948d8c24186eddd53c @@ -0,0 +1,20 @@ + +j +java:S2637"T"mongoClient" is marked "lombok.NonNull" but is not initialized in this constructor.( +o java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(ɀ +b +java:S1128"GRemove this unused import 'org.bukkit.util.io.BukkitObjectInputStream'.( +D +java:S1128 ".Remove this unused import 'org.bukkit.Bukkit'.(؍ + +java:S1186"Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.( +P +java:S1133B"5Do not forget to remove this deprecated code someday.(뮜 +C +java:S1123B"(Add the missing @deprecated Javadoc tag.(뮜 +F +java:S1905C"+Remove this unnecessary cast to "Document".( +F +java:S1905R"+Remove this unnecessary cast to "Document".( +F +java:S1905]"+Remove this unnecessary cast to "Document".( \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/8/9/89f919f2aa258720449f0172e73dbebfbb79cc4d b/.idea/sonarlint/issuestore/8/9/89f919f2aa258720449f0172e73dbebfbb79cc4d new file mode 100644 index 0000000..7274e54 --- /dev/null +++ b/.idea/sonarlint/issuestore/8/9/89f919f2aa258720449f0172e73dbebfbb79cc4d @@ -0,0 +1,5 @@ + +g java:S101 "MRename this class name to match the regular expression '^[A-Z][a-zA-Z0-9]*$'.( +t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(ͤ +\ +java:S1128"ARemove this unused import 'org.bukkit.scheduler.BukkitScheduler'.(Ѥ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/b/e/be9826b3d9cad2d893f9be0f20d66984a3e87506 b/.idea/sonarlint/issuestore/b/e/be9826b3d9cad2d893f9be0f20d66984a3e87506 new file mode 100644 index 0000000..59cd580 --- /dev/null +++ b/.idea/sonarlint/issuestore/b/e/be9826b3d9cad2d893f9be0f20d66984a3e87506 @@ -0,0 +1,5 @@ + +t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.( +\ java:S899"BDo something with the "boolean" value returned by "createNewFile".(А +T +java:S4719."9Replace charset name argument with StandardCharsets.UTF_8( \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/b/f/bf4bde6894f84ac94d4ce1701377f12cc739e25a b/.idea/sonarlint/issuestore/b/f/bf4bde6894f84ac94d4ce1701377f12cc739e25a new file mode 100644 index 0000000..188dca9 --- /dev/null +++ b/.idea/sonarlint/issuestore/b/f/bf4bde6894f84ac94d4ce1701377f12cc739e25a @@ -0,0 +1,8 @@ + +f +java:S2637"KThis method's return value is marked "lombok.NonNull" but null is returned.(ᤋ +t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(Ԉ +P +java:S1118 ":Add a private constructor to hide the implicit public one.( +< +java:S1168 "&Return an empty array instead of null.( \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/e/a/ead6ee1a580dab1d8eb807b074b0f246514d4f6c b/.idea/sonarlint/issuestore/e/a/ead6ee1a580dab1d8eb807b074b0f246514d4f6c new file mode 100644 index 0000000..d644ca6 --- /dev/null +++ b/.idea/sonarlint/issuestore/e/a/ead6ee1a580dab1d8eb807b074b0f246514d4f6c @@ -0,0 +1,4 @@ + +t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(Ԉ +F +java:S1128"+Remove this unused import 'lombok.NonNull'.( \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35 b/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..9cfad56 --- /dev/null +++ b/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,19 @@ + +z +Jsrc/main/java/xyz/rockcrafts/mc/MDBPlayer/configuration/ConfigManager.java,b\e\be9826b3d9cad2d893f9be0f20d66984a3e87506 +< + build.gradle,f\0\f07866736216be0ee2aba49e392191aeae700a35 +? +settings.gradle,0\5\05efc8b1657769a27696d478ded1e95f38737233 +n +>src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/PlayerData.java,e\a\ead6ee1a580dab1d8eb807b074b0f246514d4f6c +h +8src/main/java/xyz/rockcrafts/mc/MDBPlayer/MDBPlayer.java,5\f\5f0f68bc285c15b426f28f5177d49e92734fa224 +n +>src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/saveTask.java,8\9\89f919f2aa258720449f0172e73dbebfbb79cc4d +u +Esrc/main/java/xyz/rockcrafts/mc/MDBPlayer/mongodb/MongoDBStorage.java,6\e\6eabe8324ae3b5d46313e8948d8c24186eddd53c +x +Hsrc/main/java/xyz/rockcrafts/mc/MDBPlayer/data/SerializationManager.java,b\f\bf4bde6894f84ac94d4ce1701377f12cc739e25a +p +@src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerJoin.java,0\7\0770c5700e0742cf1e00378d1fb47536431e6a28 \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..a68f343 --- /dev/null +++ b/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'java' +} + +group 'xyz.rockcrafts.mc' +version '1.0' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() + maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } + maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } + mavenLocal() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + compileOnly "org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT" + compile 'org.mongodb:mongodb-driver-sync:4.2.0' + compileOnly 'org.projectlombok:lombok:1.18.16' + annotationProcessor 'org.projectlombok:lombok:1.18.16' + testCompileOnly 'org.projectlombok:lombok:1.18.16' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.16' + +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..94336fc Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..290541c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + 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. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +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. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..bb7e02d --- /dev/null +++ b/plugin.yml @@ -0,0 +1,6 @@ +name: MongoDBPlayer +author: RockCrafts +version: 1.0 +api-version: 1.16 +main: xyz.rockcrafts.mc.MDBPlayer.MDBPlayer +description: Plugin for saving locaiton, inventory & Enderchest accross servers through MongoDB \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..747b2b9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'MongoDBPlayer' + diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..bab105b --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: S:\Plugins\MongoDBPlayer\src\main\java\xyz\rockcrafts\mc\MDBPlayer\MDBPlayer.java + diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/MDBPlayer.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/MDBPlayer.java new file mode 100644 index 0000000..015c6da --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/MDBPlayer.java @@ -0,0 +1,89 @@ +package xyz.rockcrafts.mc.MDBPlayer; + +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.UpdateOptions; +import com.mongodb.client.result.UpdateResult; +import lombok.Getter; +import lombok.NonNull; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import xyz.rockcrafts.mc.MDBPlayer.configuration.ConfigManager; +import xyz.rockcrafts.mc.MDBPlayer.data.PlayerData; +import xyz.rockcrafts.mc.MDBPlayer.events.EventManager; +import xyz.rockcrafts.mc.MDBPlayer.events.saveTask; +import xyz.rockcrafts.mc.MDBPlayer.mongodb.MongoDBStorage; + +import javax.print.Doc; +import java.beans.EventHandler; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static com.mongodb.client.model.Filters.eq; + +public class MDBPlayer extends JavaPlugin { + @Getter private MongoDBStorage mS; + @Getter private ConfigManager cM; + @Getter private EventManager eM; + @Getter private PluginManager pM; + + @Override + public void onEnable() { + disableMongoLogger(); + initalizeManagers(); + if(mS.isConencted()) { + setupEM(); + startTasks(); + } + } + + @Override + public void onDisable() { + PlayerData.sendAllPlayerData(getMS()); + } + /* + * + * Methods for plugin setup + * + */ + private void initalizeManagers(){ + cM = new ConfigManager(this); + mS = new MongoDBStorage(); + pM = Bukkit.getPluginManager(); + cM.makePluginFolder(); + setupConfig(); + } + + private void setupConfig(){ + Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "Trying to connect to Database.."); + cM.getConfig("config.yml"); + if(mS.connectViaConfig(cM.getConfig("mongodb.yml"))){ + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Connected to MongoDB via Config"); + return; + } + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "!!Error!! when to MongoDB via Config"); + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "!!Error!! SHUTTING DOWN."); + getPM().disablePlugin(this); + } + private void setupEM(){ + eM = new EventManager(this); + } + private void startTasks(){ + + new saveTask(this.getMS()).start(this); + } + private void disableMongoLogger(){ + Logger.getLogger( "org.mongodb.driver" ).setLevel(Level.OFF); + } + + + + + +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/configuration/ConfigManager.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/configuration/ConfigManager.java new file mode 100644 index 0000000..b86f4d7 --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/configuration/ConfigManager.java @@ -0,0 +1,71 @@ +package xyz.rockcrafts.mc.MDBPlayer.configuration; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import xyz.rockcrafts.mc.MDBPlayer.MDBPlayer; + +import java.io.File; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; + +import static com.google.common.io.Resources.getResource; + +public class ConfigManager { + private MDBPlayer plugin; + + public ConfigManager(MDBPlayer plugin) { + this.plugin = plugin; + } + + + private YamlConfiguration getYamlConfig(String name){ + File file = new File(this.plugin.getDataFolder(), name); + + if(!file.exists()) { + try { + file.createNewFile(); + return getDefaultValues(file); + + } + catch (Exception e){ + e.printStackTrace(); + } + } + return YamlConfiguration.loadConfiguration(file); + + } + public FileConfiguration getConfig(String name) { + return getYamlConfig((name)); + } + public YamlConfiguration getDefaultValues(File file){ + YamlConfiguration newYaml = new YamlConfiguration(); + Reader defConfigStream = null; + // Get File from jar + try { + defConfigStream = new InputStreamReader(this.plugin.getResource(file.getName()), "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + if (defConfigStream != null) { + YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); + newYaml.setDefaults(defConfig); + //Copy default values + newYaml.options().copyDefaults(true); + try { + newYaml.save(file); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + return newYaml; + } + public void makePluginFolder(){ + if(!this.plugin.getDataFolder().exists()) this.plugin.getDataFolder().mkdir(); + } + + +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/PlayerData.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/PlayerData.java new file mode 100644 index 0000000..bf2d0f6 --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/PlayerData.java @@ -0,0 +1,64 @@ +package xyz.rockcrafts.mc.MDBPlayer.data; + +import lombok.Data; +import lombok.NonNull; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import xyz.rockcrafts.mc.MDBPlayer.mongodb.MongoDBStorage; + +@Data +public class PlayerData { + private String uuid; + private String items; + private String ec; + private String location; + private String world; + + public PlayerData(String uuid, String items, String world, String ec, String loc){ + this.uuid = uuid; + this.items = items; + this.location = loc; + this.world = world; + this.ec = ec; + } + public PlayerData(Player player){ + this.uuid = player.getUniqueId().toString(); + this.items = SerializationManager.bSE(player.getInventory().getContents()); + this.world = player.getLocation().getWorld().getName(); + this.ec = SerializationManager.bSE((player.getEnderChest().getContents())); + this.location = SerializationManager.bSE(player.getLocation()); + } + /* + * + * Move Stored data to an online Player. + * + * @param player the player to apply to + * + * + */ + public static void applyAll(Player player, PlayerData pd){ + //Loads the World/Creates it if not found. + WorldCreator.name(pd.getWorld()).createWorld(); + if(pd.getLocation()!=null) + player.teleport((Location) SerializationManager.bDD(pd.getLocation())); + applyItems(player, pd); + } + public static void applyItems(Player player, PlayerData pd){ + if(pd.getItems()!=null) + player.getInventory().setContents(( + ItemStack[]) SerializationManager.bDD(pd.getItems())); + if(pd.getEc()!=null) + player.getEnderChest().setContents(( + ItemStack[]) SerializationManager.bDD(pd.getEc())); + } + public static void sendAllPlayerData(MongoDBStorage mS){ + for(Player p: Bukkit.getOnlinePlayers()){ + mS.sendPlayerData(p); + } + } + +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/SerializationManager.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/SerializationManager.java new file mode 100644 index 0000000..86121d9 --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/data/SerializationManager.java @@ -0,0 +1,53 @@ +package xyz.rockcrafts.mc.MDBPlayer.data; + +import lombok.NonNull; +import org.bukkit.util.io.BukkitObjectInputStream; +import org.bukkit.util.io.BukkitObjectOutputStream; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Base64; + +public class SerializationManager { + + public static @NonNull String bSE(Object object){ + return encode(bukkitSerialize(object)); + } + public static @NonNull Object bDD(String toDecode){ + return bukkitDeserialize(decode(toDecode)); + } + public static byte[] bukkitSerialize(Object object) { + try { + ByteArrayOutputStream io = new ByteArrayOutputStream(); + BukkitObjectOutputStream os = new BukkitObjectOutputStream(io); + //Write to ObjectOutput, flush to Byte array output + os.writeObject(object); + os.flush(); + return io.toByteArray(); + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + public static Object bukkitDeserialize(byte[] bytes) { + try { + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + BukkitObjectInputStream is = new BukkitObjectInputStream(in); + //Write to ObjectOutput, flush to Byte array output + return is.readObject(); + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public static String encode(byte[] bytes){ + return Base64.getEncoder().encodeToString(bytes); + } + public static byte[] decode(String encoded){ + return Base64.getDecoder().decode(encoded); + } + +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/EventManager.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/EventManager.java new file mode 100644 index 0000000..d28c6ce --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/EventManager.java @@ -0,0 +1,21 @@ +package xyz.rockcrafts.mc.MDBPlayer.events; + +import jdk.nashorn.internal.objects.annotations.Getter; +import org.bukkit.plugin.PluginManager; +import xyz.rockcrafts.mc.MDBPlayer.MDBPlayer; + +import java.beans.EventHandler; + +public class EventManager { + MDBPlayer pl; + PluginManager pm; + public EventManager(MDBPlayer pl){ + this.pl = pl; + this.pm = pl.getPM(); + registerEvents(); + } + private void registerEvents(){ + pm.registerEvents(new PlayerJoin(this.pl), this.pl); + pm.registerEvents(new PlayerLeave(this.pl), this.pl); + } +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerJoin.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerJoin.java new file mode 100644 index 0000000..c0778d7 --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerJoin.java @@ -0,0 +1,29 @@ +package xyz.rockcrafts.mc.MDBPlayer.events; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import xyz.rockcrafts.mc.MDBPlayer.MDBPlayer; +import xyz.rockcrafts.mc.MDBPlayer.data.PlayerData; + +import java.util.logging.Level; + +@RequiredArgsConstructor +public class PlayerJoin implements Listener { + + @NonNull MDBPlayer plugin; + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event){ + PlayerData pd = plugin.getMS().getPlayerData(event.getPlayer()); + if(plugin.getMS().contains(event.getPlayer().getUniqueId().toString())) + + PlayerData.applyAll(event.getPlayer(), pd); + else { + plugin.getMS().sendPlayerData(event.getPlayer()); + plugin.getLogger().log(Level.INFO,"Sent Data"); + } + } +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerLeave.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerLeave.java new file mode 100644 index 0000000..207b46c --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/PlayerLeave.java @@ -0,0 +1,24 @@ +package xyz.rockcrafts.mc.MDBPlayer.events; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerBedLeaveEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import xyz.rockcrafts.mc.MDBPlayer.MDBPlayer; +import xyz.rockcrafts.mc.MDBPlayer.data.PlayerData; + +@RequiredArgsConstructor +public class PlayerLeave implements Listener { + @NonNull MDBPlayer plugin; + + @EventHandler + public void onPlayerJoin(PlayerQuitEvent event){ + plugin.getMS().sendPlayerData( + event.getPlayer()); + + } + +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/saveTask.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/saveTask.java new file mode 100644 index 0000000..ce32e7a --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/events/saveTask.java @@ -0,0 +1,21 @@ +package xyz.rockcrafts.mc.MDBPlayer.events; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitScheduler; +import xyz.rockcrafts.mc.MDBPlayer.MDBPlayer; +import xyz.rockcrafts.mc.MDBPlayer.data.PlayerData; +import xyz.rockcrafts.mc.MDBPlayer.mongodb.MongoDBStorage; + +@AllArgsConstructor +public class saveTask extends BukkitRunnable { + @NonNull MongoDBStorage mongoDBStorage; + @Override + public void run() { + PlayerData.sendAllPlayerData(mongoDBStorage); + } + public void start(MDBPlayer pl){ + this.runTaskTimer(pl,0L, pl.getCM().getConfig("config.yml").getInt("auto-save")); + } +} diff --git a/src/main/java/xyz/rockcrafts/mc/MDBPlayer/mongodb/MongoDBStorage.java b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/mongodb/MongoDBStorage.java new file mode 100644 index 0000000..7463fc3 --- /dev/null +++ b/src/main/java/xyz/rockcrafts/mc/MDBPlayer/mongodb/MongoDBStorage.java @@ -0,0 +1,117 @@ +package xyz.rockcrafts.mc.MDBPlayer.mongodb; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import lombok.Data; +import lombok.*; +import org.bson.BsonDocument; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.util.io.BukkitObjectInputStream; +import xyz.rockcrafts.mc.MDBPlayer.data.PlayerData; + +@Data +public class MongoDBStorage { + private @NonNull MongoClient mongoClient; + private @NonNull MongoDatabase database; + private @NonNull MongoCollection playerCollection; + private boolean conencted; + public MongoDBStorage(){ + } + public boolean connect(String uri, String db, String collection){ + try { + this.conencted = false; + if(uri.equals("mongodb://{user1}:{pwd1}@{host1}/{db}")){ + return false; + } + mongoClient = MongoClients.create(uri); + database = mongoClient.getDatabase(db); + database.runCommand(new Document("ping", 1)); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + this.conencted = true; + playerCollection = database.getCollection(collection); + return true; + } + public Document getDocument(String uuid){ + return getPlayerCollection().find(new Document("uuid",uuid)).first(); + } + public boolean connectViaConfig(FileConfiguration config){ + return connect(config.getString("uri"), + config.getString("db"), + config.getString("collection")); + } + + private Bson getPDBson(String uuid, PlayerData pd){ + return new Document("uuid", uuid).append( + "world", pd.getWorld()).append( + "enderchest",pd.getEc()).append( + "items", pd.getItems()).append( + "location", pd.getLocation() + ); + } + /* + * Sends Player data to a UUID in DB. + * + */ + @Deprecated + public void sendPlayerData(String uuid, PlayerData pd){ + Document found = (Document) getDocument(uuid); + Bson updatedValue = getPDBson(uuid, pd); + Bson updateOperation = new Document("$set", updatedValue); + if(found != null) + this.getPlayerCollection().updateOne(found, updateOperation); + else + this.getPlayerCollection().insertOne((Document) updatedValue); + + } + /* + * Sends Player's data, to their uuid in DB. + * + */ + public void sendPlayerData(Player player){ + PlayerData pd = new PlayerData(player); + Document found = (Document) getDocument(player.getUniqueId().toString()); + Bson updatedValue = getPDBson(player.getUniqueId().toString(), pd); + Bson updateOperation = new Document("$set", updatedValue); + if(found != null) { + this.getPlayerCollection().updateOne(found, updateOperation); + } + else + this.getPlayerCollection().insertOne((Document) updatedValue); + + } + public PlayerData getPlayerData(Player player){ + Document found = (Document) getDocument(player.getUniqueId().toString()); + if(found != null) { + return new PlayerData( + found.getString("uuid"), + found.getString("items"), + found.getString("world"), + found.getString("enderchest"), + found.getString("location") + ); + } + else{ + return new PlayerData(player); + } + } + public boolean contains(String uuid){ + return getPlayerCollection().find(Filters.eq("uuid", uuid)) + .first() != null; + } + public boolean contains(PlayerData pd){ + return getPlayerCollection().find(Filters.eq("uuid", pd.getUuid())) + .first() != null; + } + +} + diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..e104e6b --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,3 @@ +# Set how long you want the plugin to wait until +# auto-saving all players data. (ticks) +auto-save: 100 \ No newline at end of file diff --git a/src/main/resources/mongodb.yml b/src/main/resources/mongodb.yml new file mode 100644 index 0000000..f056fea --- /dev/null +++ b/src/main/resources/mongodb.yml @@ -0,0 +1,4 @@ +# Example URI Format: mongodb://{user1}:{pwd1}@{host1}/{db} +uri: mongodb://{user1}:{pwd1}@{host1}/{db} +db: "server" +collection: "player_data" \ No newline at end of file