├── .gitignore ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── license.md ├── readme.md ├── settings.gradle.kts └── src └── main ├── java └── me │ └── youhavetrouble │ └── serverbasics │ ├── CommandManager.java │ ├── NMSHandler.java │ ├── ServerBasics.java │ ├── chat │ ├── BasicChatRenderer.java │ ├── ChatListener.java │ └── StaffChatRenderer.java │ ├── commands │ ├── BalanceCommand.java │ ├── BaltopCommand.java │ ├── BanCommand.java │ ├── EnchantCommand.java │ ├── ExecuteCommand.java │ ├── FeedCommand.java │ ├── FixCommand.java │ ├── FlyCommand.java │ ├── GamemodeCommand.java │ ├── HatCommand.java │ ├── HealCommand.java │ ├── ItemLoreCommand.java │ ├── ItemNameCommand.java │ ├── KickCommand.java │ ├── MoneyCommand.java │ ├── NicknameCommand.java │ ├── PlayTimeCommand.java │ ├── ServerBasicsCommand.java │ ├── SpawnCommand.java │ ├── TeleportCommand.java │ ├── WarpCommand.java │ └── registration │ │ ├── CommandRegistration.java │ │ └── SyncCommandRegistration.java │ ├── config │ ├── ConfigCache.java │ ├── LanguageCache.java │ └── LocationsCache.java │ ├── economy │ ├── BasicBaltopEntry.java │ ├── BasicEconomy.java │ ├── BasicEconomyAccount.java │ └── BasicVaultHandler.java │ ├── hooks │ ├── Hook.java │ ├── Hooks.java │ └── PlaceholderAPIHook.java │ ├── listeners │ ├── FeatureListener.java │ ├── HatListener.java │ └── SpawnListener.java │ ├── messages │ └── MessageParser.java │ ├── players │ ├── BasicPlayer.java │ └── BasicPlayerCache.java │ ├── storage │ ├── Database.java │ ├── MySQL.java │ └── SQLite.java │ └── util │ ├── BasicUtil.java │ └── BasicWarp.java └── resources ├── config.yml ├── lang └── en_us.yml └── plugin.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | 11 | # Compiled class file 12 | *.class 13 | 14 | # Log file 15 | *.log 16 | 17 | # BlueJ files 18 | *.ctxt 19 | 20 | # Package Files # 21 | *.jar 22 | *.war 23 | *.nar 24 | *.ear 25 | *.zip 26 | *.tar.gz 27 | *.rar 28 | 29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 30 | hs_err_pid* 31 | 32 | *~ 33 | 34 | # temporary files which can be created if a process still has a handle open of a deleted file 35 | .fuse_hidden* 36 | 37 | # KDE directory preferences 38 | .directory 39 | 40 | # Linux trash folder which might appear on any partition or disk 41 | .Trash-* 42 | 43 | # .nfs files are created when an open file is removed but is still being accessed 44 | .nfs* 45 | 46 | # General 47 | .DS_Store 48 | .AppleDouble 49 | .LSOverride 50 | 51 | # Icon must end with two \r 52 | Icon 53 | 54 | # Thumbnails 55 | ._* 56 | 57 | # Files that might appear in the root of a volume 58 | .DocumentRevisions-V100 59 | .fseventsd 60 | .Spotlight-V100 61 | .TemporaryItems 62 | .Trashes 63 | .VolumeIcon.icns 64 | .com.apple.timemachine.donotpresent 65 | 66 | # Directories potentially created on remote AFP share 67 | .AppleDB 68 | .AppleDesktop 69 | Network Trash Folder 70 | Temporary Items 71 | .apdisk 72 | 73 | # Windows thumbnail cache files 74 | Thumbs.db 75 | Thumbs.db:encryptable 76 | ehthumbs.db 77 | ehthumbs_vista.db 78 | 79 | # Dump file 80 | *.stackdump 81 | 82 | # Folder config file 83 | [Dd]esktop.ini 84 | 85 | # Recycle Bin used on file shares 86 | $RECYCLE.BIN/ 87 | 88 | # Windows Installer files 89 | *.cab 90 | *.msi 91 | *.msix 92 | *.msm 93 | *.msp 94 | 95 | # Windows shortcuts 96 | *.lnk 97 | 98 | target/ 99 | 100 | pom.xml.tag 101 | pom.xml.releaseBackup 102 | pom.xml.versionsBackup 103 | pom.xml.next 104 | 105 | release.properties 106 | dependency-reduced-pom.xml 107 | buildNumber.properties 108 | .mvn/timing.properties 109 | .mvn/wrapper/maven-wrapper.jar 110 | .flattened-pom.xml 111 | 112 | # Common working directory 113 | run/ 114 | 115 | # Gradle 116 | !gradle-wrapper.jar 117 | .gradle/ 118 | build/ 119 | */build/ 120 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | id("io.papermc.paperweight.userdev") version "1.3.7" 4 | id("org.jetbrains.kotlin.plugin.lombok") version "1.6.10" 5 | id("com.github.johnrengelman.shadow") version "7.1.2" 6 | } 7 | 8 | group = "me.youhavetrouble.serverbasics" 9 | version = "1.4.0" 10 | description = "Modern non-bloated essentials alternative" 11 | 12 | java { 13 | toolchain.languageVersion.set(JavaLanguageVersion.of(17)) 14 | } 15 | 16 | repositories { 17 | mavenCentral() 18 | maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") 19 | maven("https://oss.sonatype.org/content/groups/public/") 20 | maven("https://jitpack.io") 21 | } 22 | 23 | dependencies { 24 | paperDevBundle("1.19.2-R0.1-SNAPSHOT") 25 | compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") 26 | 27 | compileOnly("me.clip:placeholderapi:2.11.1") 28 | compileOnly("com.github.MilkBowl:VaultAPI:1.7") 29 | 30 | implementation("cloud.commandframework:cloud-paper:1.7.0") 31 | implementation("cloud.commandframework:cloud-minecraft-extras:1.7.0") 32 | implementation("cloud.commandframework:cloud-annotations:1.7.0") 33 | implementation("org.reflections:reflections:0.10.2") 34 | implementation("com.zaxxer:HikariCP:5.0.1") 35 | 36 | compileOnly("org.projectlombok:lombok:1.18.24") 37 | annotationProcessor("org.projectlombok:lombok:1.18.24") 38 | } 39 | 40 | tasks { 41 | compileJava { 42 | options.encoding = Charsets.UTF_8.name() 43 | options.release.set(17) 44 | } 45 | 46 | shadowJar { 47 | relocate("cloud.commandframework", "me.youhavetrouble.serverbasics.cloud.commandframework") 48 | relocate("io.leangen.geantyref", "me.youhavetrouble.serverbasics.io.leangen.geantyref") 49 | relocate("com.zaxxer", "me.youhavetrouble.serverbasics.com.zaxxer") 50 | } 51 | 52 | reobfJar { 53 | outputJar.set(project.layout.buildDirectory.file("libs/${rootProject.name}-${rootProject.version}.jar")) 54 | } 55 | 56 | processResources { 57 | filesMatching("plugin.yml") { 58 | expand( 59 | "name" to rootProject.name, 60 | "group" to project.group, 61 | "version" to project.version, 62 | "description" to project.description, 63 | ) 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouHaveTrouble/ServerBasics/a61de3f4964df8764ca15b3562a3c9227f0459ea/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | # Artistic License 2.0 2 | Copyright (c) 2000-2006, The Perl Foundation. 3 | 4 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 5 | 6 | ## Preamble 7 | This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. 8 | 9 | You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. 10 | 11 | ## Definitions 12 | "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. 13 | 14 | "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. 15 | 16 | "You" and "your" means any person who would like to copy, distribute, or modify the Package. 17 | 18 | "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. 19 | 20 | "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. 21 | 22 | "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. 23 | 24 | "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. 25 | 26 | "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. 27 | 28 | "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. 29 | 30 | "Source" form means the source code, documentation source, and configuration files for the Package. 31 | 32 | "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. 33 | 34 | ## Permission for Use and Modification Without Distribution 35 | (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. 36 | 37 | ## Permissions for Redistribution of the Standard Version 38 | (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. 39 | 40 | (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. 41 | 42 | ## Distribution of Modified Versions of the Package as Source 43 | (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: 44 | 45 | (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. 46 | 47 | (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. 48 | 49 | (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under 50 | 51 | (i) the Original License or 52 | 53 | (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. 54 | 55 | ## Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source 56 | (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. 57 | 58 | (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. 59 | 60 | ## Aggregating or Linking the Package 61 | (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. 62 | 63 | (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. 64 | 65 | ## Items That are Not Considered Part of a Modified Version 66 | (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. 67 | 68 | ## General Provisions 69 | (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. 70 | 71 | (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. 72 | 73 | (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. 74 | 75 | (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. 76 | 77 | (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 78 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

2 | ServerBasics is essentials-like plugin with focus on performance 3 | and vanilla-like look. 4 |

5 |

6 | this is currently extremely work in progress. 7 |

8 | 9 |

Planned features

10 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | maven("https://papermc.io/repo/repository/maven-public/") 5 | } 6 | 7 | } 8 | 9 | rootProject.name = "ServerBasics" 10 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/CommandManager.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics; 2 | 3 | import cloud.commandframework.CommandTree; 4 | import cloud.commandframework.annotations.AnnotationParser; 5 | import cloud.commandframework.arguments.parser.ParserParameters; 6 | import cloud.commandframework.arguments.parser.StandardParameters; 7 | import cloud.commandframework.bukkit.BukkitCommandManager; 8 | import cloud.commandframework.bukkit.CloudBukkitCapabilities; 9 | import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator; 10 | import cloud.commandframework.execution.CommandExecutionCoordinator; 11 | import cloud.commandframework.extra.confirmation.CommandConfirmationManager; 12 | import cloud.commandframework.meta.CommandMeta; 13 | import cloud.commandframework.paper.PaperCommandManager; 14 | import me.youhavetrouble.serverbasics.commands.registration.SyncCommandRegistration; 15 | import me.youhavetrouble.serverbasics.messages.MessageParser; 16 | import org.bukkit.ChatColor; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | import me.youhavetrouble.serverbasics.commands.registration.CommandRegistration; 21 | import org.reflections.Reflections; 22 | 23 | import java.lang.reflect.InvocationTargetException; 24 | import java.util.Set; 25 | import java.util.concurrent.TimeUnit; 26 | import java.util.function.Function; 27 | 28 | public class CommandManager { 29 | 30 | private final ServerBasics plugin = ServerBasics.getInstance(); 31 | 32 | public BukkitCommandManager manager; 33 | public BukkitCommandManager syncManager; 34 | private CommandConfirmationManager confirmationManager; 35 | 36 | public AnnotationParser getAnnotationParser() { 37 | return annotationParser; 38 | } 39 | 40 | private AnnotationParser annotationParser, syncAnnotationParser; 41 | 42 | public void initCommands() { 43 | final Function, CommandExecutionCoordinator> executionCoordinatorFunction = 44 | AsynchronousCommandExecutionCoordinator.newBuilder().build(); 45 | final Function, CommandExecutionCoordinator> syncExecutionCoordinatorFunction = 46 | CommandExecutionCoordinator.simpleCoordinator(); 47 | 48 | final Function mapperFunction = Function.identity(); 49 | try { 50 | manager = new PaperCommandManager<>( 51 | /* Owning plugin */ plugin, 52 | /* Coordinator function */ executionCoordinatorFunction, 53 | /* Command Sender -> C */ mapperFunction, 54 | /* C -> Command Sender */ mapperFunction 55 | ); 56 | syncManager = new PaperCommandManager<>( 57 | /* Owning plugin */ plugin, 58 | /* Coordinator function */ syncExecutionCoordinatorFunction, 59 | /* Command Sender -> C */ mapperFunction, 60 | /* C -> Command Sender */ mapperFunction 61 | ); 62 | } catch (final Exception e) { 63 | plugin.getLogger().severe("Failed to initialize the command manager"); 64 | plugin.getServer().getPluginManager().disablePlugin(plugin); 65 | return; 66 | } 67 | 68 | if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) { 69 | manager.registerBrigadier(); 70 | } 71 | if (syncManager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) { 72 | syncManager.registerBrigadier(); 73 | } 74 | 75 | if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { 76 | ((PaperCommandManager) manager).registerAsynchronousCompletions(); 77 | } 78 | if (syncManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { 79 | ((PaperCommandManager) syncManager).registerAsynchronousCompletions(); 80 | } 81 | 82 | confirmationManager = new CommandConfirmationManager<>( 83 | /* Timeout */ 30L, 84 | /* Timeout unit */ TimeUnit.SECONDS, 85 | /* Action when confirmation is required */ context -> context.getCommandContext().getSender().sendMessage( 86 | ChatColor.RED + "Confirmation required. Confirm using /example confirm."), 87 | /* Action when no confirmation is pending */ sender -> sender.sendMessage( 88 | ChatColor.RED + "You don't have any pending commands.") 89 | ); 90 | final Function commandMetaFunction = p -> 91 | CommandMeta.simple() 92 | .with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "No description")) 93 | .build(); 94 | annotationParser = new AnnotationParser<>( 95 | manager, 96 | CommandSender.class, 97 | commandMetaFunction 98 | ); 99 | syncAnnotationParser = new AnnotationParser<>( 100 | syncManager, 101 | CommandSender.class, 102 | commandMetaFunction 103 | ); 104 | 105 | // Command error messages 106 | manager.registerExceptionHandler(cloud.commandframework.exceptions.NoPermissionException.class, (sender, exception) -> { 107 | if (sender instanceof Player player) { 108 | MessageParser.sendMessage(sender, ServerBasics.getLang(player.locale()).no_permission); 109 | } else { 110 | MessageParser.sendMessage(sender, ServerBasics.getLang(ServerBasics.getConfigCache().default_lang).no_permission); 111 | } 112 | }); 113 | manager.registerExceptionHandler(cloud.commandframework.exceptions.InvalidSyntaxException.class, (sender, exception) -> { 114 | String msg; 115 | if (sender instanceof Player player) { 116 | msg = String.format(ServerBasics.getLang(player.locale()).invalid_syntax, "/"+exception.getCorrectSyntax()); 117 | } else { 118 | msg = String.format(ServerBasics.getLang(ServerBasics.getConfigCache().default_lang).invalid_syntax, exception.getCorrectSyntax()); 119 | } 120 | MessageParser.sendMessage(sender, msg); 121 | }); 122 | manager.registerExceptionHandler(cloud.commandframework.exceptions.ArgumentParseException.class, (sender, exception) -> { 123 | if (sender instanceof Player player) { 124 | MessageParser.sendMessage(sender, ServerBasics.getLang(player.locale()).failed_argument_parse); 125 | } else { 126 | MessageParser.sendMessage(sender, ServerBasics.getLang(ServerBasics.getConfigCache().default_lang).failed_argument_parse); 127 | } 128 | }); 129 | 130 | constructCommands(); 131 | construcSyncCommands(); 132 | } 133 | 134 | 135 | private void constructCommands() { 136 | Reflections reflections = new Reflections((Object) new String[]{"me.youhavetrouble.serverbasics.commands"}); 137 | Set> listenerClasses = reflections.getTypesAnnotatedWith(CommandRegistration.class); 138 | listenerClasses.forEach((command)-> { 139 | try { 140 | annotationParser.parse(command.getConstructor().newInstance()) ; 141 | } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { 142 | e.printStackTrace(); 143 | } 144 | }); 145 | } 146 | private void construcSyncCommands() { 147 | Reflections reflections = new Reflections((Object) new String[]{"me.youhavetrouble.serverbasics.commands"}); 148 | Set> listenerClasses = reflections.getTypesAnnotatedWith(SyncCommandRegistration.class); 149 | listenerClasses.forEach((command)-> { 150 | try { 151 | syncAnnotationParser.parse(command.getConstructor().newInstance()) ; 152 | } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { 153 | e.printStackTrace(); 154 | } 155 | }); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics; 2 | 3 | import net.minecraft.Util; 4 | import net.minecraft.nbt.*; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.world.level.storage.PlayerDataStorage; 7 | import org.bukkit.*; 8 | import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.util.UUID; 13 | 14 | public class NMSHandler { 15 | 16 | 17 | private static final MinecraftServer minecraftServer = MinecraftServer.getServer(); 18 | private static final PlayerDataStorage playerData = minecraftServer.playerDataStorage; 19 | 20 | public static Location getOfflinePlayerPosition(OfflinePlayer offlinePlayer) { 21 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 22 | ListTag coords = nbt.getList("Pos", CraftMagicNumbers.NBT.TAG_DOUBLE); 23 | long worldUuidMost = nbt.getLong("WorldUUIDMost"); 24 | long worldUuidLeast = nbt.getLong("WorldUUIDLeast"); 25 | ListTag rotation = nbt.getList("Rotation", CraftMagicNumbers.NBT.TAG_FLOAT); 26 | float yaw = rotation.getFloat(0); 27 | float pitch = rotation.getFloat(1); 28 | UUID worldUuid = new UUID(worldUuidMost, worldUuidLeast); 29 | World world = Bukkit.getWorld(worldUuid); 30 | double x = coords.getDouble(0); 31 | double y = coords.getDouble(1); 32 | double z = coords.getDouble(2); 33 | return new Location(world, x, y, z, yaw, pitch); 34 | } 35 | 36 | public static void setOfflinePlayerPosition(OfflinePlayer offlinePlayer, Location location) { 37 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 38 | nbt.putLong("WorldUUIDMost", location.getWorld().getUID().getMostSignificantBits()); 39 | nbt.putLong("WorldUUIDLeast", location.getWorld().getUID().getLeastSignificantBits()); 40 | ListTag pos = new ListTag(); 41 | pos.add(DoubleTag.valueOf(location.getX())); 42 | pos.add(DoubleTag.valueOf(location.getY())); 43 | pos.add(DoubleTag.valueOf(location.getZ())); 44 | nbt.put("Pos", pos); 45 | ListTag rotation = new ListTag(); 46 | rotation.add(FloatTag.valueOf(location.getYaw())); 47 | rotation.add(FloatTag.valueOf(location.getPitch())); 48 | nbt.put("Rotation", rotation); 49 | savePlayerData(nbt, offlinePlayer); 50 | } 51 | 52 | public static void setOfflinePlayerGamemode(OfflinePlayer offlinePlayer, GameMode gameMode) { 53 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 54 | switch (gameMode) { 55 | case SURVIVAL -> nbt.putInt("playerGameType", 0); 56 | case CREATIVE -> nbt.putInt("playerGameType", 1); 57 | case ADVENTURE -> nbt.putInt("playerGameType", 2); 58 | case SPECTATOR -> nbt.putInt("playerGameType", 3); 59 | } 60 | savePlayerData(nbt, offlinePlayer); 61 | } 62 | 63 | public static GameMode getOfflinePlayerGamemode(OfflinePlayer offlinePlayer) { 64 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 65 | return switch (nbt.getInt("playerGameType")) { 66 | case 0 -> GameMode.SURVIVAL; 67 | case 1 -> GameMode.CREATIVE; 68 | case 2 -> GameMode.ADVENTURE; 69 | case 3 -> GameMode.SPECTATOR; 70 | default -> null; 71 | }; 72 | } 73 | 74 | public static boolean getOfflinePlayerCanFly(OfflinePlayer offlinePlayer) { 75 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 76 | CompoundTag abilities = nbt.getCompound("abilities"); 77 | return abilities.getByte("mayfly") == 1; 78 | } 79 | 80 | public static void setOfflinePlayerCanFly(OfflinePlayer offlinePlayer, boolean canFly) { 81 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 82 | CompoundTag abilities = nbt.getCompound("abilities"); 83 | if (canFly) 84 | abilities.putByte("mayfly", (byte) 1); 85 | else 86 | abilities.putByte("mayfly", (byte) 0); 87 | nbt.put("abilities", abilities); 88 | savePlayerData(nbt, offlinePlayer); 89 | } 90 | 91 | public static void setOfflinePlayerFallDistance(OfflinePlayer offlinePlayer, float distance) { 92 | CompoundTag nbt = playerData.getPlayerData(offlinePlayer.getUniqueId().toString()); 93 | nbt.putFloat("FallDistance", distance); 94 | savePlayerData(nbt, offlinePlayer); 95 | } 96 | 97 | private static void savePlayerData(CompoundTag nbtTagCompound, OfflinePlayer offlinePlayer) { 98 | try { 99 | File playerDir = playerData.getPlayerDir(); 100 | File file = File.createTempFile(offlinePlayer.getUniqueId() + "-", ".dat", playerDir); 101 | NbtIo.writeCompressed(nbtTagCompound, file); 102 | File file1 = new File(playerDir, offlinePlayer.getUniqueId() + ".dat"); 103 | File file2 = new File(playerDir, offlinePlayer.getUniqueId() + ".dat_old"); 104 | Util.safeReplaceFile(file1, file, file2); 105 | } catch (IOException e) { 106 | Bukkit.getServer().getLogger().severe("Failed to save player data for " + offlinePlayer.getUniqueId()); 107 | } 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/ServerBasics.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics; 2 | 3 | import me.youhavetrouble.serverbasics.economy.BasicEconomy; 4 | import me.youhavetrouble.serverbasics.economy.BasicVaultHandler; 5 | import me.youhavetrouble.serverbasics.hooks.PlaceholderAPIHook; 6 | import me.youhavetrouble.serverbasics.listeners.FeatureListener; 7 | import me.youhavetrouble.serverbasics.listeners.SpawnListener; 8 | import me.youhavetrouble.serverbasics.players.BasicPlayerCache; 9 | import me.youhavetrouble.serverbasics.storage.Database; 10 | import me.youhavetrouble.serverbasics.storage.MySQL; 11 | import me.youhavetrouble.serverbasics.chat.ChatListener; 12 | import me.youhavetrouble.serverbasics.config.ConfigCache; 13 | import me.youhavetrouble.serverbasics.config.LanguageCache; 14 | import me.youhavetrouble.serverbasics.config.LocationsCache; 15 | import me.youhavetrouble.serverbasics.hooks.Hooks; 16 | import me.youhavetrouble.serverbasics.listeners.HatListener; 17 | import me.youhavetrouble.serverbasics.storage.SQLite; 18 | import net.milkbowl.vault.economy.Economy; 19 | import org.bukkit.command.CommandSender; 20 | import org.bukkit.entity.Player; 21 | import org.bukkit.plugin.ServicePriority; 22 | import org.bukkit.plugin.java.JavaPlugin; 23 | import org.reflections.Reflections; 24 | import org.reflections.scanners.Scanners; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.nio.file.Files; 29 | import java.util.HashMap; 30 | import java.util.Locale; 31 | import java.util.Set; 32 | import java.util.regex.Matcher; 33 | import java.util.regex.Pattern; 34 | 35 | public final class ServerBasics extends JavaPlugin { 36 | 37 | private static ServerBasics instance; 38 | private static ConfigCache configCache; 39 | private static LocationsCache locationsCache; 40 | private static HashMap languageCacheMap; 41 | private static BasicPlayerCache basicPlayers; 42 | private static BasicEconomy basicEconomy; 43 | private static Hooks hooks; 44 | private Database database; 45 | 46 | @Override 47 | public void onEnable() { 48 | 49 | String packageName = this.getServer().getClass().getPackage().getName(); 50 | String version = packageName.substring(packageName.lastIndexOf('.') + 1); 51 | 52 | // nms is a bitch and I don't care enough to support multiple versions 53 | if (!version.equals("v1_19_R1")) { 54 | this.getLogger().severe("Could not find support for server version "+version); 55 | this.setEnabled(false); 56 | return; 57 | } 58 | 59 | instance = this; 60 | reloadConfigs(); 61 | reloadLang(); 62 | hooks = new Hooks(); 63 | CommandManager commandManager = new CommandManager(); 64 | commandManager.initCommands(); 65 | 66 | String playerPrefix = configCache.getDatabasePlayerTablePrefix(); 67 | String locationsPrefix = configCache.getDatabaseLocationsTablePrefix(); 68 | 69 | switch (configCache.databaseType) { 70 | case MYSQL -> database = new MySQL(playerPrefix, locationsPrefix); 71 | case SQLITE -> database = new SQLite(playerPrefix, locationsPrefix); 72 | } 73 | 74 | basicPlayers = new BasicPlayerCache(); 75 | reloadLocations(); 76 | 77 | getServer().getPluginManager().registerEvents(new FeatureListener(), this); 78 | getServer().getPluginManager().registerEvents(new ChatListener(), this); 79 | getServer().getPluginManager().registerEvents(new HatListener(), this); 80 | getServer().getPluginManager().registerEvents(new SpawnListener(), this); 81 | 82 | if (hooks.isHooked("PlaceholderAPI")) { 83 | new PlaceholderAPIHook().register(); 84 | } 85 | if (hooks.isHooked("Vault")) { 86 | basicEconomy = new BasicEconomy(this); 87 | getServer().getServicesManager().register(Economy.class, new BasicVaultHandler(), this, ServicePriority.Lowest); 88 | basicEconomy.activateEconomy(); 89 | getLogger().info("Vault economy support enabled!"); 90 | } 91 | 92 | } 93 | 94 | @Override 95 | public void onDisable() { 96 | if (basicEconomy == null || !basicEconomy.isBasicEconomy()) return; 97 | // save the balances before shutdown 98 | basicEconomy.getAccounts().forEach(basicEconomyAccount -> database.saveBalance(basicEconomyAccount.getUuid(), basicEconomyAccount.getBalance())); 99 | } 100 | 101 | public void reloadConfigs() { 102 | saveDefaultConfig(); 103 | reloadConfig(); 104 | configCache = new ConfigCache(); 105 | } 106 | 107 | public void reloadLang() { 108 | languageCacheMap = new HashMap<>(); 109 | try { 110 | File langDirectory = new File(instance.getDataFolder()+ "/lang"); 111 | Files.createDirectories(langDirectory.toPath()); 112 | getDefaultLanguageFiles().forEach((fileName)->{ // ensure default files first (or else we get errors second) 113 | String localeString = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.')); 114 | getLogger().info(String.format("Found language file for %s", localeString)); 115 | LanguageCache langCache = new LanguageCache(localeString); 116 | languageCacheMap.put(localeString, langCache); 117 | }); 118 | Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE); 119 | for (File langFile : langDirectory.listFiles()) { 120 | Matcher langMatcher = langPattern.matcher(langFile.getName()); 121 | if (langMatcher.find()) { 122 | String localeString = langMatcher.group(1).toLowerCase(); 123 | if(!languageCacheMap.containsKey(localeString)) { // make sure it wasn't a default file that we already loaded 124 | getLogger().info(String.format("Found language file for %s", localeString)); 125 | LanguageCache langCache = new LanguageCache(localeString); 126 | languageCacheMap.put(localeString, langCache); 127 | } 128 | } 129 | } 130 | } catch (IOException e) { 131 | e.printStackTrace(); 132 | getLogger().severe("Error loading language files! Language files will not reload to avoid errors, make sure to correct this before restarting the server!"); 133 | } 134 | } 135 | 136 | private Set getDefaultLanguageFiles(){ 137 | Reflections reflections = new Reflections("lang", Scanners.Resources); 138 | return reflections.getResources(Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)")); 139 | } 140 | 141 | public void reloadLocations() { 142 | locationsCache = new LocationsCache(); 143 | } 144 | 145 | public static LanguageCache getLang(String lang) { 146 | lang = lang.replace("-", "_"); 147 | if (configCache.auto_lang) { 148 | return languageCacheMap.getOrDefault(lang, languageCacheMap.get(configCache.default_lang.toString().toLowerCase())); 149 | } else { 150 | return languageCacheMap.get(configCache.default_lang.toString().toLowerCase()); 151 | } 152 | } 153 | 154 | public static LanguageCache getLang(Locale locale) { 155 | return getLang(locale.toString().toLowerCase()); 156 | } 157 | 158 | public static LanguageCache getLang(CommandSender commandSender) { 159 | if (commandSender instanceof Player player) { 160 | return getLang(player.locale()); 161 | } else { 162 | return getLang(configCache.default_lang); 163 | } 164 | } 165 | 166 | public static ServerBasics getInstance() { 167 | return instance; 168 | } 169 | 170 | public static ConfigCache getConfigCache() { 171 | return configCache; 172 | } 173 | 174 | public static LocationsCache getLocationsCache() { 175 | return locationsCache; 176 | } 177 | 178 | public static BasicPlayerCache getBasicPlayers() { 179 | return basicPlayers; 180 | } 181 | 182 | public static BasicEconomy getBasicEconomy() { 183 | return basicEconomy; 184 | } 185 | public static Hooks getHooks() { 186 | return hooks; 187 | } 188 | 189 | public Database getDatabase() { 190 | return database; 191 | } 192 | 193 | } -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/chat/BasicChatRenderer.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.chat; 2 | 3 | import me.youhavetrouble.serverbasics.ServerBasics; 4 | import me.youhavetrouble.serverbasics.messages.MessageParser; 5 | import io.papermc.paper.chat.ChatRenderer; 6 | import me.clip.placeholderapi.PlaceholderAPI; 7 | import net.kyori.adventure.audience.Audience; 8 | import net.kyori.adventure.text.Component; 9 | import net.kyori.adventure.text.TextReplacementConfig; 10 | import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; 11 | import org.bukkit.entity.Player; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | public class BasicChatRenderer implements ChatRenderer { 15 | 16 | /** 17 | * Renderer for default chat format 18 | * @param player source 19 | * @param component sourceDisplayName 20 | * @param component2 message 21 | * @param audience viewer 22 | * @return Rendered message 23 | */ 24 | @Override 25 | public @NotNull Component render(@NotNull Player player, @NotNull Component component, @NotNull Component component2, @NotNull Audience audience) { 26 | String stringMessage = PlainTextComponentSerializer.plainText().serialize(component2); 27 | 28 | String stringFormat = ServerBasics.getConfigCache().chat_format; 29 | 30 | if (ServerBasics.getHooks().isHooked("PlaceholderAPI")) 31 | stringFormat = PlaceholderAPI.setPlaceholders(player, stringFormat); 32 | 33 | Component format = MessageParser.miniMessage.deserialize(stringFormat); 34 | TextReplacementConfig.Builder messageReplacementConfig = TextReplacementConfig.builder() 35 | .match("%message%") 36 | .replacement(MessageParser.miniMessage.deserialize(stringMessage)); 37 | 38 | if (player.hasPermission("serverbasics.chat.color")) { 39 | stringMessage = MessageParser.makeColorsWork('&', stringMessage); 40 | messageReplacementConfig.replacement(MessageParser.miniMessage.deserialize(stringMessage)); 41 | } 42 | format = format.replaceText(messageReplacementConfig.build()); 43 | 44 | TextReplacementConfig nameReplacementConfig = TextReplacementConfig.builder() 45 | .match("%nickname%") 46 | .replacement(player.displayName()) 47 | .build(); 48 | format = format.replaceText(nameReplacementConfig); 49 | return format; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/chat/ChatListener.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.chat; 2 | 3 | import me.youhavetrouble.serverbasics.ServerBasics; 4 | import net.kyori.adventure.text.Component; 5 | import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | 12 | public class ChatListener implements Listener { 13 | 14 | BasicChatRenderer chatRenderer = new BasicChatRenderer(); 15 | StaffChatRenderer staffChatRenderer = new StaffChatRenderer(); 16 | 17 | @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) 18 | public void onChat(io.papermc.paper.event.player.AsyncChatEvent event) { 19 | 20 | Player player = event.getPlayer(); 21 | String stringMessage = PlainTextComponentSerializer.plainText().serialize(event.originalMessage()); 22 | 23 | // Staffchat 24 | if (stringMessage.startsWith("!") && ServerBasics.getConfigCache().staffchat_enabled && player.hasPermission("serverbasics.staffchat.send")) { 25 | // Make sure only players with staffchat perms get the message 26 | event.viewers().removeIf(audience -> audience instanceof CommandSender sender && !sender.hasPermission("serverbasics.chat.staffchat.recieve")); 27 | // Remove the staffchat symbol 28 | stringMessage = stringMessage.substring(1); 29 | event.message(Component.text(stringMessage)); 30 | event.renderer(staffChatRenderer); 31 | return; 32 | } 33 | 34 | // Chat format 35 | if (!ServerBasics.getConfigCache().chat_format_enabled) 36 | return; 37 | event.renderer(chatRenderer); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/chat/StaffChatRenderer.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.chat; 2 | 3 | import me.youhavetrouble.serverbasics.ServerBasics; 4 | import me.youhavetrouble.serverbasics.messages.MessageParser; 5 | import io.papermc.paper.chat.ChatRenderer; 6 | import me.clip.placeholderapi.PlaceholderAPI; 7 | import net.kyori.adventure.audience.Audience; 8 | import net.kyori.adventure.text.Component; 9 | import net.kyori.adventure.text.TextReplacementConfig; 10 | import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; 11 | import org.bukkit.entity.Player; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | public class StaffChatRenderer implements ChatRenderer { 15 | @Override 16 | public @NotNull Component render(@NotNull Player player, @NotNull Component component, @NotNull Component component2, @NotNull Audience audience) { 17 | String stringMessage = PlainTextComponentSerializer.plainText().serialize(component2); 18 | 19 | String stringFormat = ServerBasics.getConfigCache().staffchat_format; 20 | 21 | if (ServerBasics.getHooks().isHooked("PlaceholderAPI")) 22 | stringFormat = PlaceholderAPI.setPlaceholders(player, stringFormat); 23 | 24 | Component format = MessageParser.miniMessage.deserialize(stringFormat); 25 | TextReplacementConfig.Builder messageReplacementConfig = TextReplacementConfig.builder() 26 | .match("%message%"); 27 | 28 | if (player.hasPermission("serverbasics.chat.color")) { 29 | stringMessage = MessageParser.makeColorsWork('&', stringMessage); 30 | messageReplacementConfig.replacement(MessageParser.miniMessage.deserialize(stringMessage)); 31 | } else 32 | messageReplacementConfig.replacement(Component.text(stringMessage)); 33 | format = format.replaceText(messageReplacementConfig.build()); 34 | 35 | TextReplacementConfig nameReplacementConfig = TextReplacementConfig.builder() 36 | .match("%nickname%") 37 | .replacement(component) 38 | .build(); 39 | format = format.replaceText(nameReplacementConfig); 40 | return format; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/commands/BalanceCommand.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.commands; 2 | 3 | import cloud.commandframework.annotations.Argument; 4 | import cloud.commandframework.annotations.CommandDescription; 5 | import cloud.commandframework.annotations.CommandMethod; 6 | import cloud.commandframework.annotations.CommandPermission; 7 | import cloud.commandframework.bukkit.arguments.selector.SinglePlayerSelector; 8 | import me.youhavetrouble.serverbasics.ServerBasics; 9 | import me.youhavetrouble.serverbasics.commands.registration.CommandRegistration; 10 | import me.youhavetrouble.serverbasics.economy.BasicEconomyAccount; 11 | import me.youhavetrouble.serverbasics.messages.MessageParser; 12 | import me.youhavetrouble.serverbasics.players.BasicPlayer; 13 | import net.kyori.adventure.text.Component; 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.OfflinePlayer; 16 | import org.bukkit.command.CommandSender; 17 | import org.bukkit.entity.Player; 18 | 19 | import java.util.HashMap; 20 | import java.util.UUID; 21 | import java.util.concurrent.CompletableFuture; 22 | 23 | @CommandRegistration 24 | public class BalanceCommand { 25 | 26 | @CommandMethod("balance") 27 | @CommandDescription("Check your balance") 28 | @CommandPermission("serverbasics.command.balance") 29 | private void commandBalance( 30 | final Player player 31 | ) { 32 | if (ServerBasics.getBasicEconomy() == null || !ServerBasics.getBasicEconomy().isBasicEconomy()) { 33 | player.sendMessage(MessageParser.parseMessage(player, ServerBasics.getLang(player).econ_disabled)); 34 | return; 35 | } 36 | ServerBasics.getBasicEconomy().getEconomyAccount(player.getUniqueId()).thenAccept(basicEconomyAccount -> { 37 | double balance = basicEconomyAccount.getBalance(); 38 | HashMap placeholders = new HashMap<>(); 39 | placeholders.put("%balance%", Component.text(ServerBasics.getBasicEconomy().formatMoney(balance))); 40 | player.sendMessage(MessageParser.parseMessage(player, ServerBasics.getLang(player.locale()).balance, placeholders)); 41 | }); 42 | } 43 | 44 | @CommandMethod("balance ") 45 | @CommandDescription("Check someone's balance") 46 | @CommandPermission("serverbasics.command.balance.others") 47 | private void commandBalanceOthers( 48 | final CommandSender sender, 49 | final @Argument(value = "player") SinglePlayerSelector singlePlayerSelector 50 | ) { 51 | if (ServerBasics.getBasicEconomy() == null || !ServerBasics.getBasicEconomy().isBasicEconomy()) { 52 | sender.sendMessage(MessageParser.parseMessage(sender, ServerBasics.getLang(sender).econ_disabled)); 53 | return; 54 | } 55 | 56 | if (!singlePlayerSelector.hasAny()) { 57 | String selector = singlePlayerSelector.getSelector(); 58 | OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(selector); 59 | if (!offlinePlayer.hasPlayedBefore()) { 60 | sender.sendMessage(ServerBasics.getLang(sender).havent_played); 61 | return; 62 | } 63 | checkBalance(sender, offlinePlayer.getUniqueId()); 64 | } else { 65 | checkBalance(sender, singlePlayerSelector.getPlayer().getUniqueId()); 66 | } 67 | } 68 | 69 | private void checkBalance(CommandSender feedback, UUID uuid) { 70 | CompletableFuture basicPlayerFuture = ServerBasics.getBasicPlayers().getBasicPlayer(uuid); 71 | CompletableFuture basicEconAccount = ServerBasics.getBasicEconomy().getEconomyAccount(uuid); 72 | CompletableFuture.allOf(basicEconAccount, basicPlayerFuture).thenRun(() -> { 73 | BasicPlayer basicPlayer = basicPlayerFuture.join(); 74 | BasicEconomyAccount economyAccount = basicEconAccount.join(); 75 | HashMap placeholders = new HashMap<>(); 76 | placeholders.put("%balance%", Component.text(ServerBasics.getBasicEconomy().formatMoney(economyAccount.getBalance()))); 77 | placeholders.put("%player%", basicPlayer.getDisplayName()); 78 | feedback.sendMessage(MessageParser.parseMessage(feedback, ServerBasics.getLang(feedback).balance_other, placeholders)); 79 | }); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/commands/BaltopCommand.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.commands; 2 | 3 | import cloud.commandframework.annotations.*; 4 | import me.youhavetrouble.serverbasics.ServerBasics; 5 | import me.youhavetrouble.serverbasics.commands.registration.CommandRegistration; 6 | import me.youhavetrouble.serverbasics.economy.BasicBaltopEntry; 7 | import me.youhavetrouble.serverbasics.messages.MessageParser; 8 | import net.kyori.adventure.text.Component; 9 | import org.bukkit.command.CommandSender; 10 | 11 | import java.util.HashMap; 12 | import java.util.List; 13 | 14 | @CommandRegistration 15 | public class BaltopCommand { 16 | 17 | @CommandMethod("baltop") 18 | @CommandDescription("Display top balances") 19 | @CommandPermission("serverbasics.command.baltop") 20 | private void commandBaltop( 21 | final CommandSender sender 22 | ) { 23 | 24 | if (ServerBasics.getBasicEconomy() == null || !ServerBasics.getBasicEconomy().isBasicEconomy()) { 25 | sender.sendMessage(MessageParser.parseMessage(sender, ServerBasics.getLang(sender).econ_disabled)); 26 | return; 27 | } 28 | 29 | List entries = ServerBasics.getBasicEconomy().getBaltop(); 30 | sender.sendMessage(MessageParser.parseMessage(sender, ServerBasics.getLang(sender).baltop_title)); 31 | if (entries.isEmpty()) { 32 | sender.sendMessage(MessageParser.parseMessage(sender, ServerBasics.getLang(sender).baltop_empty)); 33 | return; 34 | } 35 | int place = 0; 36 | for (BasicBaltopEntry entry : entries) { 37 | HashMap placeholders = new HashMap<>(); 38 | placeholders.put("%place%", Component.text(++place)); 39 | placeholders.put("%name%", entry.getComponentName()); 40 | placeholders.put("%balance%", Component.text(entry.getFormattedMoney())); 41 | sender.sendMessage(MessageParser.parseMessage(sender, ServerBasics.getLang(sender).baltop_format, placeholders)); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/youhavetrouble/serverbasics/commands/BanCommand.java: -------------------------------------------------------------------------------- 1 | package me.youhavetrouble.serverbasics.commands; 2 | 3 | import cloud.commandframework.annotations.*; 4 | import cloud.commandframework.annotations.suggestions.Suggestions; 5 | import cloud.commandframework.bukkit.arguments.selector.SinglePlayerSelector; 6 | import cloud.commandframework.context.CommandContext; 7 | import me.youhavetrouble.serverbasics.ServerBasics; 8 | import me.youhavetrouble.serverbasics.commands.registration.CommandRegistration; 9 | import me.youhavetrouble.serverbasics.messages.MessageParser; 10 | import net.kyori.adventure.text.Component; 11 | import net.kyori.adventure.text.TextReplacementConfig; 12 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.OfflinePlayer; 15 | import org.bukkit.command.CommandSender; 16 | import org.bukkit.entity.Player; 17 | import org.bukkit.util.StringUtil; 18 | 19 | import java.time.Instant; 20 | import java.time.temporal.ChronoUnit; 21 | import java.util.ArrayList; 22 | import java.util.Date; 23 | import java.util.List; 24 | import java.util.Locale; 25 | 26 | @CommandRegistration 27 | public class BanCommand { 28 | 29 | @CommandMethod("ban ") 30 | @CommandDescription("Ban player") 31 | @CommandPermission("serverbasics.command.ban") 32 | private void commandBan( 33 | final CommandSender sender, 34 | @Argument(value = "player", description = "Player to ban") SinglePlayerSelector playerSelector 35 | ) { 36 | 37 | OfflinePlayer target; 38 | 39 | if (!playerSelector.hasAny()) { 40 | target = Bukkit.getOfflinePlayer(playerSelector.getSelector()); 41 | if (!target.hasPlayedBefore()) { 42 | MessageParser.sendHaventPlayedError(sender); 43 | return; 44 | } 45 | } else 46 | target = playerSelector.getPlayer(); 47 | 48 | Component banMessage = Component.empty(); 49 | Locale locale; 50 | if (target.isOnline()) 51 | locale = target.getPlayer().locale(); 52 | else 53 | locale = ServerBasics.getConfigCache().default_lang; 54 | 55 | for (String line : ServerBasics.getLang(locale).ban_message) { 56 | line = line.replaceAll("%reason%", ServerBasics.getLang(locale).ban_reason); 57 | banMessage = banMessage.append(MessageParser.miniMessage.deserialize(line)).append(Component.newline()); 58 | } 59 | 60 | String finalKickReasonParsed = LegacyComponentSerializer.legacySection().serialize(banMessage); 61 | Bukkit.getScheduler().runTask(ServerBasics.getInstance(), () -> target.banPlayer(finalKickReasonParsed, sender.getName())); 62 | } 63 | 64 | @CommandMethod("ban ") 65 | @CommandDescription("Ban player") 66 | @CommandPermission("serverbasics.command.ban") 67 | private void commandBanWithReason( 68 | final CommandSender sender, 69 | @Argument(value = "player", description = "Player to ban") SinglePlayerSelector playerSelector, 70 | @Argument(value = "reason", description = "Reason for ban") String[] reason 71 | ) { 72 | OfflinePlayer target; 73 | 74 | 75 | if (!playerSelector.hasAny()) { 76 | target = Bukkit.getOfflinePlayer(playerSelector.getSelector()); 77 | if (!target.hasPlayedBefore()) { 78 | MessageParser.sendHaventPlayedError(sender); 79 | return; 80 | } 81 | } else 82 | target = playerSelector.getPlayer(); 83 | 84 | Component joinedReason = MessageParser.miniMessage.deserialize(String.join(" ", reason)); 85 | Component banMessage = Component.empty(); 86 | Locale locale; 87 | if (target.isOnline()) 88 | locale = target.getPlayer().locale(); 89 | else 90 | locale = ServerBasics.getConfigCache().default_lang; 91 | 92 | for (String line : ServerBasics.getLang(locale).ban_message) { 93 | banMessage = banMessage.append(MessageParser.miniMessage.deserialize(line)).append(Component.newline()); 94 | } 95 | 96 | TextReplacementConfig reasonReplacer = TextReplacementConfig.builder().match("%reason%").replacement(joinedReason).build(); 97 | banMessage = banMessage.replaceText(reasonReplacer); 98 | 99 | String finalKickReasonParsed = LegacyComponentSerializer.legacySection().serialize(banMessage); 100 | Bukkit.getScheduler().runTask(ServerBasics.getInstance(), () -> target.banPlayer(finalKickReasonParsed, sender.getName())); 101 | } 102 | 103 | @CommandMethod("tempban