├── .editorconfig ├── .gitignore ├── LICENSE.txt ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main └── kotlin └── com └── velocitypowered └── api └── kt ├── VelocityPlugin.kt ├── command ├── CommandInvocation.kt ├── CommandManager.kt └── CommandMeta.kt ├── event ├── EventContinuation.kt ├── EventManager.kt ├── ResultedEvent.kt ├── command │ ├── CommandExecuteEvent.kt │ └── PlayerAvailableCommandsEvent.kt ├── connection │ ├── ConnectionHandshakeEvent.kt │ ├── PluginMessageEvent.kt │ ├── ProxyPingEvent.kt │ └── ProxyQueryEvent.kt ├── lifecycle │ └── network │ │ ├── ListenerBoundEvent.kt │ │ └── ListenerClosedEvent.kt ├── permission │ └── PermissionsSetupEvent.kt └── player │ ├── DisconnectedEvent.kt │ ├── GameProfileRequestEvent.kt │ ├── KickedFromServerEvent.kt │ ├── LoginEvent.kt │ ├── PlayerChannelRegisterEvent.kt │ ├── PlayerChatEvent.kt │ ├── PlayerChooseInitialServerEvent.kt │ ├── PlayerClientSettingsChangedEvent.kt │ ├── PlayerModInfoEvent.kt │ ├── PlayerResourcePackStatusEvent.kt │ ├── PostLoginEvent.kt │ ├── PreLoginEvent.kt │ ├── ServerConnectedEvent.kt │ ├── ServerPostConnectEvent.kt │ ├── ServerPreConnectEvent.kt │ └── TabCompleteEvent.kt ├── network └── ProtocolVersion.kt ├── plugin ├── PluginContainer.kt ├── PluginDescription.kt ├── PluginManager.kt └── meta │ └── PluginDependency.kt ├── proxy ├── ProxyServer.kt ├── connection │ ├── InboundConnection.kt │ ├── Player.kt │ └── ServerConnection.kt ├── player │ ├── ConnectionRequestBuilder.kt │ ├── TabList.kt │ └── TabListEntry.kt └── server │ ├── QueryResponse.kt │ ├── RegisteredServer.kt │ ├── ServerInfo.kt │ └── ServerPing.kt ├── scheduler └── Scheduler.kt └── util └── GameProfile.kt /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | max_line_length = 100 10 | tab_width = 2 11 | ij_continuation_indent_size = 4 12 | ij_formatter_off_tag = @formatter:off 13 | ij_formatter_on_tag = @formatter:on 14 | ij_formatter_tags_enabled = false 15 | ij_smart_tabs = false 16 | ij_wrap_on_typing = true 17 | 18 | [{*.kts,*.kt}] 19 | ij_kotlin_name_count_to_use_star_import = 100 20 | ij_kotlin_name_count_to_use_star_import_for_members = 100 21 | # Remove default star imports 22 | ij_kotlin_packages_to_use_import_on_demand = 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Intellij ### 2 | .idea/ 3 | *.iws 4 | */out/ 5 | *.iml 6 | .idea_modules/ 7 | atlassian-ide-plugin.xml 8 | 9 | ### Eclipse ### 10 | .metadata 11 | bin/ 12 | tmp/ 13 | *.tmp 14 | *.bak 15 | *.swp 16 | *~.nib 17 | local.properties 18 | .settings/ 19 | .loadpath 20 | .recommenders 21 | .externalToolBuilders/ 22 | *.launch 23 | .factorypath 24 | .recommenders/ 25 | .apt_generated/ 26 | .project 27 | .classpath 28 | 29 | ### Linux ### 30 | *~ 31 | .fuse_hidden* 32 | .directory 33 | .Trash-* 34 | .nfs* 35 | 36 | ### macOS ### 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | Icon 41 | ._* 42 | .DocumentRevisions-V100 43 | .fseventsd 44 | .Spotlight-V100 45 | .TemporaryItems 46 | .Trashes 47 | .VolumeIcon.icns 48 | .com.apple.timemachine.donotpresent 49 | .AppleDB 50 | .AppleDesktop 51 | Network Trash Folder 52 | Temporary Items 53 | .apdisk 54 | 55 | ### NetBeans ### 56 | nbproject/private/ 57 | build/ 58 | nbbuild/ 59 | dist/ 60 | nbdist/ 61 | .nb-gradle/ 62 | 63 | ### Windows ### 64 | # Windows thumbnail cache files 65 | Thumbs.db 66 | ehthumbs.db 67 | ehthumbs_vista.db 68 | *.stackdump 69 | [Dd]esktop.ini 70 | $RECYCLE.BIN/ 71 | *.lnk 72 | 73 | ### Gradle ### 74 | .gradle 75 | /build/ 76 | /out/ 77 | gradle-app.setting 78 | !gradle-wrapper.jar 79 | .gradletasknamecache 80 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2021 Velocity Contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # velocity-language-kotlin 2 | 3 | Provides Kotlin support and useful DSLs as a Velocity plugin. 4 | 5 | ## Provided dependencies 6 | 7 | * Kotlin standard library (version 1.5.0) 8 | * `kotlinx.serialization` (version 1.5.0, JSON serialization library version `1.2.1`) 9 | * `kotlinx.coroutines` (version 1.5.0) -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | kotlin("kapt") 4 | kotlin("plugin.serialization") 5 | id("com.github.johnrengelman.shadow") 6 | } 7 | 8 | val kotlinVersion: String by project 9 | val velocityVersion: String by project 10 | 11 | group = "com.velocitypowered" 12 | version = "$velocityVersion+$kotlinVersion" 13 | 14 | repositories { 15 | mavenLocal() 16 | mavenCentral() 17 | 18 | maven("https://repo.velocitypowered.com/snapshots/") 19 | } 20 | 21 | dependencies { 22 | implementation(kotlin("reflect")) 23 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1") 24 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinVersion") 25 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlinVersion") 26 | implementation("net.kyori:adventure-extra-kotlin:4.7.0") 27 | 28 | compileOnly("com.velocitypowered:velocity-api:$velocityVersion") 29 | kapt("com.velocitypowered:velocity-annotation-processor:$velocityVersion") 30 | } 31 | 32 | tasks.build { 33 | dependsOn(tasks.shadowJar.get()) 34 | } 35 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | kotlinVersion=1.5.0 4 | velocityVersion=4.0.0-SNAPSHOT 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VelocityPowered/velocity-language-kotlin/3f457b9f0a73d086fae7f7d12ec770d8c3cde1c2/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.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or 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 UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "velocity-language-kotlin" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenCentral() 6 | gradlePluginPortal() 7 | } 8 | 9 | plugins { 10 | val kotlinVersion: String by settings 11 | 12 | kotlin("jvm") version kotlinVersion 13 | kotlin("kapt") version kotlinVersion 14 | kotlin("plugin.serialization") version kotlinVersion 15 | 16 | id("com.github.johnrengelman.shadow") version "6.1.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/VelocityPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt 2 | 3 | import com.google.inject.Inject 4 | import com.velocitypowered.api.event.EventManager 5 | import com.velocitypowered.api.event.PostOrder 6 | import com.velocitypowered.api.event.Subscribe 7 | import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent 8 | import com.velocitypowered.api.kt.event.registerCoroutineContinuationAdapter 9 | import com.velocitypowered.api.plugin.Plugin 10 | import org.slf4j.Logger 11 | 12 | @Plugin(id = "velocity-language-kotlin", authors = ["Velocity Contributors"]) 13 | @Suppress("unused") 14 | class VelocityPlugin @Inject constructor( 15 | val logger: Logger, 16 | val eventManager: EventManager, 17 | ) { 18 | 19 | init { 20 | eventManager.registerCoroutineContinuationAdapter(logger) 21 | } 22 | 23 | @Subscribe(order = PostOrder.FIRST) 24 | fun onInit(event: ProxyInitializeEvent) { 25 | logger.info("The Kotlin Language Adapter is initialized!") 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/command/CommandInvocation.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.command 2 | 3 | import com.velocitypowered.api.command.CommandInvocation 4 | import com.velocitypowered.api.command.CommandSource 5 | 6 | inline val CommandInvocation<*>.source: CommandSource 7 | get() = source() 8 | 9 | inline val CommandInvocation.arguments: T 10 | get() = arguments() 11 | 12 | inline val CommandInvocation<*>.alias: String 13 | get() = alias() 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/command/CommandManager.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.command 2 | 3 | import com.velocitypowered.api.command.BrigadierCommand 4 | import com.velocitypowered.api.command.CommandManager 5 | import com.velocitypowered.api.command.CommandMeta 6 | 7 | inline fun CommandManager.createMeta( 8 | alias: String, 9 | build: CommandMeta.Builder.() -> Unit 10 | ): CommandMeta = createMetaBuilder(alias).apply(build).build() 11 | 12 | inline fun CommandManager.createMeta( 13 | command: BrigadierCommand, 14 | build: CommandMeta.Builder.() -> Unit 15 | ): CommandMeta = createMetaBuilder(command).apply(build).build() 16 | 17 | operator fun CommandManager.contains(alias: String): Boolean = 18 | hasCommand(alias) 19 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/command/CommandMeta.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.command 2 | 3 | import com.mojang.brigadier.tree.CommandNode 4 | import com.velocitypowered.api.command.CommandMeta 5 | import com.velocitypowered.api.command.CommandSource 6 | 7 | inline val CommandMeta.aliases: Collection 8 | get() = aliases() 9 | 10 | inline val CommandMeta.hints: Collection> 11 | get() = hints() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/EventContinuation.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event 2 | 3 | import com.google.common.reflect.TypeToken 4 | import com.velocitypowered.api.event.Event 5 | import com.velocitypowered.api.event.EventManager 6 | import com.velocitypowered.api.event.EventTask 7 | import org.slf4j.Logger 8 | import java.lang.reflect.Method 9 | import java.util.function.BiConsumer 10 | import java.util.function.BiFunction 11 | import java.util.function.Function 12 | import java.util.function.Predicate 13 | import kotlin.reflect.jvm.kotlinFunction 14 | 15 | /** 16 | * Registers a kotlin coroutine continuation adapter into the VelocityEventManager. This adds 17 | * support for suspending event functions. 18 | */ 19 | internal fun EventManager.registerCoroutineContinuationAdapter(logger: Logger) { 20 | try { 21 | registerHandlerAdapter( 22 | name = "kt_suspend", 23 | filter = filter@ { method -> 24 | val function = method.kotlinFunction 25 | ?: return@filter false 26 | function.isSuspend 27 | }, 28 | validator = { method, errors -> 29 | val function = method.kotlinFunction!! 30 | // parameters includes receiver, but excludes continuation 31 | if (function.parameters.size != 2) { 32 | errors.add("function must have a single parameter which is the event type") 33 | } 34 | if (function.returnType.classifier != Unit::class) { 35 | errors.add("function return type must be Unit") 36 | } 37 | }, 38 | invokeFunctionType = object : TypeToken Unit>() {}, 39 | handlerBuilder = { invokeFunction -> 40 | BiFunction { instance, event -> 41 | suspendingEventTask { 42 | invokeFunction(instance, event) 43 | } 44 | } 45 | } 46 | ) 47 | } catch (ex: UnsupportedOperationException) { 48 | logger.warn("Suspending event functions will not be supported.", ex) 49 | } 50 | } 51 | 52 | internal fun EventManager.registerHandlerAdapter( 53 | name: String, 54 | filter: Predicate, 55 | validator: BiConsumer>, 56 | invokeFunctionType: TypeToken, 57 | handlerBuilder: Function> 58 | ) { 59 | try { 60 | val method = javaClass.getMethod("registerHandlerAdapter", String::class.java, 61 | Predicate::class.java, BiConsumer::class.java, TypeToken::class.java, Function::class.java) 62 | method.invoke(this, name, filter, validator, invokeFunctionType, handlerBuilder) 63 | } catch (ex: NoSuchMethodException) { 64 | throw UnsupportedOperationException("The registerHandlerAdapter method couldn't be found" 65 | + " in VelocityEventManager, handler adapters aren't supported.", ex) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/EventManager.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event 2 | 3 | import com.velocitypowered.api.event.Event 4 | import com.velocitypowered.api.event.EventManager 5 | import com.velocitypowered.api.event.EventTask 6 | import com.velocitypowered.api.event.PostOrder 7 | import com.velocitypowered.api.event.Continuation as EventContinuation 8 | import kotlin.coroutines.Continuation 9 | import kotlin.coroutines.EmptyCoroutineContext 10 | import kotlin.coroutines.startCoroutine 11 | 12 | /** 13 | * Registers an event listener for the event [E] for the given [plugin]. The listener will use a 14 | * suspended coroutine, allowing you to use a coroutine context to process the event in a 15 | * non-blocking way. 16 | */ 17 | inline fun EventManager.on( 18 | plugin: Any, order: Short = PostOrder.NORMAL, crossinline handler: suspend (E) -> Unit 19 | ) = 20 | register(plugin, E::class.java, order) { event -> 21 | suspendingEventTask { 22 | handler(event) 23 | } 24 | } 25 | 26 | /** 27 | * Marks the specified function as a suspended function, which uses the event continuation system in 28 | * Velocity to allow you to process the event in a non-blocking way. 29 | */ 30 | @PublishedApi 31 | internal fun suspendingEventTask(handler: suspend () -> Unit): EventTask = 32 | EventTask.withContinuation { continuation -> 33 | handler.startCoroutine(continuation.asCoroutineContinuation()) 34 | } 35 | 36 | internal fun EventContinuation.asCoroutineContinuation(): Continuation = 37 | Continuation(EmptyCoroutineContext) { result -> 38 | if (result.isFailure) { 39 | resumeWithException(result.exceptionOrNull()) 40 | } else { 41 | resume() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/ResultedEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event 2 | 3 | import com.velocitypowered.api.event.ResultedEvent 4 | import net.kyori.adventure.text.Component 5 | 6 | inline var ResultedEvent.result: R 7 | get() = result() 8 | set(value) { 9 | setResult(value) 10 | } 11 | 12 | inline val ResultedEvent.ComponentResult.reason: Component? 13 | get() = reason() 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/command/CommandExecuteEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.command 2 | 3 | import com.velocitypowered.api.command.CommandSource 4 | import com.velocitypowered.api.event.command.CommandExecuteEvent 5 | 6 | inline val CommandExecuteEvent.source: CommandSource 7 | get() = source() 8 | 9 | inline val CommandExecuteEvent.rawCommand: String 10 | get() = rawCommand() 11 | 12 | inline val CommandExecuteEvent.CommandResult.modifiedCommand: String? 13 | get() = modifiedCommand() 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/command/PlayerAvailableCommandsEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.command 2 | 3 | import com.mojang.brigadier.tree.RootCommandNode 4 | import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent 5 | import com.velocitypowered.api.proxy.connection.Player 6 | 7 | inline val PlayerAvailableCommandsEvent.player: Player 8 | get() = player() 9 | 10 | inline val PlayerAvailableCommandsEvent.rootNode: RootCommandNode<*> 11 | get() = rootNode() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/connection/ConnectionHandshakeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.connection 2 | 3 | import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent 4 | import com.velocitypowered.api.proxy.connection.InboundConnection 5 | import java.net.SocketAddress 6 | 7 | inline val ConnectionHandshakeEvent.connection: InboundConnection 8 | get() = connection() 9 | 10 | inline var ConnectionHandshakeEvent.currentHostname: String 11 | get() = currentHostname() 12 | set(value) { 13 | setCurrentHostname(value) 14 | } 15 | 16 | inline val ConnectionHandshakeEvent.originalHostname: String 17 | get() = originalHostname() 18 | 19 | inline var ConnectionHandshakeEvent.currentRemoteHostAddress: SocketAddress? 20 | get() = currentRemoteHostAddress() 21 | set(value) { 22 | setCurrentRemoteHostAddress(value) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/connection/PluginMessageEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.connection 2 | 3 | import com.velocitypowered.api.event.connection.PluginMessageEvent 4 | import com.velocitypowered.api.proxy.messages.ChannelMessageSink 5 | import com.velocitypowered.api.proxy.messages.ChannelMessageSource 6 | import com.velocitypowered.api.proxy.messages.PluginChannelId 7 | 8 | inline val PluginMessageEvent.source: ChannelMessageSource 9 | get() = source() 10 | 11 | inline val PluginMessageEvent.sink: ChannelMessageSink 12 | get() = sink() 13 | 14 | inline val PluginMessageEvent.channel: PluginChannelId 15 | get() = channel() 16 | 17 | inline val PluginMessageEvent.rawMessage: ByteArray 18 | get() = rawMessage() 19 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/connection/ProxyPingEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.connection 2 | 3 | import com.velocitypowered.api.event.connection.ProxyPingEvent 4 | import com.velocitypowered.api.proxy.connection.InboundConnection 5 | import com.velocitypowered.api.proxy.server.ServerPing 6 | 7 | inline val ProxyPingEvent.connection: InboundConnection 8 | get() = connection() 9 | 10 | inline var ProxyPingEvent.ping: ServerPing 11 | get() = ping() 12 | set(value) { 13 | setPing(value) 14 | } 15 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/connection/ProxyQueryEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.connection 2 | 3 | import com.velocitypowered.api.event.connection.ProxyQueryEvent 4 | import com.velocitypowered.api.proxy.server.QueryResponse 5 | import java.net.InetAddress 6 | 7 | inline val ProxyQueryEvent.type: ProxyQueryEvent.QueryType 8 | get() = type() 9 | 10 | inline val ProxyQueryEvent.queryingAddress: InetAddress 11 | get() = queryingAddress() 12 | 13 | inline var ProxyQueryEvent.response: QueryResponse 14 | get() = response() 15 | set(value) { 16 | setResponse(value) 17 | } 18 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/lifecycle/network/ListenerBoundEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.lifecycle.network 2 | 3 | import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEvent 4 | import com.velocitypowered.api.network.ListenerType 5 | import java.net.SocketAddress 6 | 7 | inline val ListenerBoundEvent.address: SocketAddress 8 | get() = address() 9 | 10 | inline val ListenerBoundEvent.type: ListenerType 11 | get() = type() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/lifecycle/network/ListenerClosedEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.lifecycle.network 2 | 3 | import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEvent 4 | import com.velocitypowered.api.network.ListenerType 5 | import java.net.SocketAddress 6 | 7 | inline val ListenerClosedEvent.address: SocketAddress 8 | get() = address() 9 | 10 | inline val ListenerClosedEvent.type: ListenerType 11 | get() = type() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/permission/PermissionsSetupEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.permission 2 | 3 | import com.velocitypowered.api.event.permission.PermissionsSetupEvent 4 | import com.velocitypowered.api.permission.PermissionProvider 5 | import com.velocitypowered.api.permission.PermissionSubject 6 | 7 | inline val PermissionsSetupEvent.subject: PermissionSubject 8 | get() = subject() 9 | 10 | inline var PermissionsSetupEvent.provider: PermissionProvider 11 | get() = provider() 12 | set(value) { 13 | setProvider(value) 14 | } 15 | 16 | fun PermissionsSetupEvent.resetProvider() = setProvider(null) 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/DisconnectedEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.DisconnectEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val DisconnectEvent.player: Player 7 | get() = player() 8 | 9 | inline val DisconnectEvent.loginStatus: DisconnectEvent.LoginStatus 10 | get() = loginStatus() 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/GameProfileRequestEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.GameProfileRequestEvent 4 | import com.velocitypowered.api.proxy.connection.InboundConnection 5 | import com.velocitypowered.api.util.GameProfile 6 | 7 | inline val GameProfileRequestEvent.connection: InboundConnection 8 | get() = connection() 9 | 10 | inline val GameProfileRequestEvent.username: String 11 | get() = username() 12 | 13 | inline val GameProfileRequestEvent.initialProfile: GameProfile 14 | get() = initialProfile() 15 | 16 | inline var GameProfileRequestEvent.gameProfile: GameProfile 17 | get() = gameProfile() 18 | set(value) { 19 | setGameProfile(value) 20 | } 21 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/KickedFromServerEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.KickedFromServerEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | import net.kyori.adventure.text.Component 7 | 8 | inline val KickedFromServerEvent.player: Player 9 | get() = player() 10 | 11 | inline val KickedFromServerEvent.server: RegisteredServer 12 | get() = server() 13 | 14 | inline val KickedFromServerEvent.serverKickReason: Component? 15 | get() = serverKickReason() 16 | 17 | inline val KickedFromServerEvent.isKickedDuringServerConnect: Boolean 18 | get() = kickedDuringServerConnect() 19 | 20 | inline val KickedFromServerEvent.DisconnectPlayer.message: Component 21 | get() = message() 22 | 23 | inline val KickedFromServerEvent.RedirectPlayer.message: Component? 24 | get() = message() 25 | 26 | inline val KickedFromServerEvent.Notify.message: Component 27 | get() = message() 28 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/LoginEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.LoginEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val LoginEvent.player: Player 7 | get() = player() 8 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerChannelRegisterEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.messages.PluginChannelId 6 | 7 | inline val PlayerChannelRegisterEvent.player: Player 8 | get() = player() 9 | 10 | inline val PlayerChannelRegisterEvent.channels: Collection 11 | get() = channels() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerChatEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerChatEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val PlayerChatEvent.player: Player 7 | get() = player() 8 | 9 | inline val PlayerChatEvent.originalMessage: String 10 | get() = originalMessage() 11 | 12 | inline var PlayerChatEvent.currentMessage: String 13 | get() = currentMessage() 14 | set(value) { 15 | setCurrentMessage(value) 16 | } 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerChooseInitialServerEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | 7 | inline val PlayerChooseInitialServerEvent.player: Player 8 | get() = player() 9 | 10 | inline var PlayerChooseInitialServerEvent.initialServer: RegisteredServer? 11 | get() = initialServer() 12 | set(value) { 13 | setInitialServer(value) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerClientSettingsChangedEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerClientSettingsChangedEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.player.ClientSettings 6 | 7 | inline val PlayerClientSettingsChangedEvent.player: Player 8 | get() = player() 9 | 10 | inline val PlayerClientSettingsChangedEvent.settings: ClientSettings 11 | get() = settings() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerModInfoEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerModInfoEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.util.ModInfo 6 | 7 | inline val PlayerModInfoEvent.player: Player 8 | get() = player() 9 | 10 | inline val PlayerModInfoEvent.modInfo: ModInfo 11 | get() = modInfo() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PlayerResourcePackStatusEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val PlayerResourcePackStatusEvent.player: Player 7 | get() = player() 8 | 9 | inline val PlayerResourcePackStatusEvent.status: PlayerResourcePackStatusEvent.Status 10 | get() = status() 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PostLoginEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PostLoginEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val PostLoginEvent.player: Player 7 | get() = player() 8 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/PreLoginEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.PreLoginEvent 4 | import com.velocitypowered.api.proxy.connection.InboundConnection 5 | 6 | inline val PreLoginEvent.connection: InboundConnection 7 | get() = connection() 8 | 9 | inline val PreLoginEvent.username: String 10 | get() = username() 11 | 12 | inline var PreLoginEvent.onlineMode: Boolean 13 | get() = onlineMode() 14 | set(value) { 15 | setOnlineMode(value) 16 | } 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/ServerConnectedEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.ServerConnectedEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | 7 | inline val ServerConnectedEvent.player: Player 8 | get() = player() 9 | 10 | inline val ServerConnectedEvent.target: RegisteredServer 11 | get() = target() 12 | 13 | inline val ServerConnectedEvent.previousServer: RegisteredServer? 14 | get() = previousServer() 15 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/ServerPostConnectEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.ServerPostConnectEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | 7 | inline val ServerPostConnectEvent.player: Player 8 | get() = player() 9 | 10 | inline val ServerPostConnectEvent.previousServer: RegisteredServer? 11 | get() = previousServer() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/ServerPreConnectEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.ServerPreConnectEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | 7 | inline val ServerPreConnectEvent.player: Player 8 | get() = player() 9 | 10 | inline val ServerPreConnectEvent.originalTarget: RegisteredServer 11 | get() = originalTarget() 12 | 13 | inline val ServerPreConnectEvent.ServerResult.target: RegisteredServer? 14 | get() = target() 15 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/event/player/TabCompleteEvent.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.event.player 2 | 3 | import com.velocitypowered.api.event.player.TabCompleteEvent 4 | import com.velocitypowered.api.proxy.connection.Player 5 | 6 | inline val TabCompleteEvent.player: Player 7 | get() = player() 8 | 9 | inline val TabCompleteEvent.partialMessage: String 10 | get() = partialMessage() 11 | 12 | inline val TabCompleteEvent.suggestions: Collection 13 | get() = suggestions() 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/network/ProtocolVersion.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.network 2 | 3 | import com.velocitypowered.api.network.ProtocolVersion 4 | 5 | inline val ProtocolVersion.protocol: Int 6 | get() = protocol() 7 | 8 | inline val ProtocolVersion.supportedVersions: Collection 9 | get() = supportedVersions() 10 | 11 | inline val ProtocolVersion.versionIntroducedIn: String 12 | get() = versionIntroducedIn() 13 | 14 | inline val ProtocolVersion.mostRecentSupportedVersion: String 15 | get() = mostRecentSupportedVersion() 16 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/plugin/PluginContainer.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.plugin 2 | 3 | import com.velocitypowered.api.plugin.PluginContainer 4 | import com.velocitypowered.api.plugin.PluginDescription 5 | 6 | inline val PluginContainer.description: PluginDescription 7 | get() = description() 8 | 9 | inline val PluginContainer.instance: Any? 10 | get() = instance() 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/plugin/PluginDescription.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.plugin 2 | 3 | import com.velocitypowered.api.plugin.PluginDescription 4 | import com.velocitypowered.api.plugin.meta.PluginDependency 5 | import java.nio.file.Path 6 | 7 | inline val PluginDescription.id: String 8 | get() = id() 9 | 10 | inline val PluginDescription.name: String 11 | get() = name() 12 | 13 | inline val PluginDescription.version: String? 14 | get() = version() 15 | 16 | inline val PluginDescription.description: String? 17 | get() = description() 18 | 19 | inline val PluginDescription.url: String? 20 | get() = url() 21 | 22 | inline val PluginDescription.authors: Collection 23 | get() = authors() 24 | 25 | inline val PluginDescription.dependencies: Collection 26 | get() = dependencies() 27 | 28 | inline val PluginDescription.file: Path? 29 | get() = file() 30 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/plugin/PluginManager.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.plugin 2 | 3 | import com.velocitypowered.api.plugin.PluginContainer 4 | import com.velocitypowered.api.plugin.PluginManager 5 | 6 | inline val PluginManager.plugins: Collection 7 | get() = plugins() 8 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/plugin/meta/PluginDependency.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.plugin.meta 2 | 3 | import com.velocitypowered.api.plugin.meta.PluginDependency 4 | 5 | inline val PluginDependency.id: String 6 | get() = id() 7 | 8 | inline val PluginDependency.version: String? 9 | get() = version() 10 | 11 | inline val PluginDependency.isOptional: Boolean 12 | get() = optional() 13 | 14 | operator fun PluginDependency.component1(): String = id 15 | operator fun PluginDependency.component2(): String? = version 16 | operator fun PluginDependency.component3(): Boolean = isOptional 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/ProxyServer.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy 2 | 3 | import com.velocitypowered.api.command.CommandManager 4 | import com.velocitypowered.api.command.ConsoleCommandSource 5 | import com.velocitypowered.api.event.EventManager 6 | import com.velocitypowered.api.plugin.PluginManager 7 | import com.velocitypowered.api.proxy.ProxyServer 8 | import com.velocitypowered.api.proxy.config.ProxyConfig 9 | import com.velocitypowered.api.proxy.messages.ChannelRegistrar 10 | import com.velocitypowered.api.scheduler.Scheduler 11 | import com.velocitypowered.api.util.ProxyVersion 12 | 13 | inline val ProxyServer.consoleCommandSource: ConsoleCommandSource 14 | get() = consoleCommandSource() 15 | 16 | inline val ProxyServer.pluginManager: PluginManager 17 | get() = pluginManager() 18 | 19 | inline val ProxyServer.eventManager: EventManager 20 | get() = eventManager() 21 | 22 | inline val ProxyServer.commandManager: CommandManager 23 | get() = commandManager() 24 | 25 | inline val ProxyServer.scheduler: Scheduler 26 | get() = scheduler() 27 | 28 | inline val ProxyServer.channelRegistrar: ChannelRegistrar 29 | get() = channelRegistrar() 30 | 31 | inline val ProxyServer.configuration: ProxyConfig 32 | get() = configuration() 33 | 34 | inline val ProxyServer.version: ProxyVersion 35 | get() = version() 36 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/connection/InboundConnection.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.connection 2 | 3 | import com.velocitypowered.api.network.ProtocolVersion 4 | import com.velocitypowered.api.proxy.connection.InboundConnection 5 | import java.net.InetSocketAddress 6 | import java.net.SocketAddress 7 | 8 | inline val InboundConnection.remoteAddress: SocketAddress? 9 | get() = remoteAddress() 10 | 11 | inline val InboundConnection.connectedHostname: InetSocketAddress? 12 | get() = connectedHostname() 13 | 14 | inline val InboundConnection.protocolVersion: ProtocolVersion 15 | get() = protocolVersion() 16 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/connection/Player.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.connection 2 | 3 | import com.velocitypowered.api.proxy.connection.Player 4 | import com.velocitypowered.api.proxy.connection.ServerConnection 5 | import com.velocitypowered.api.proxy.player.ClientSettings 6 | import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder 7 | import com.velocitypowered.api.proxy.player.TabList 8 | import com.velocitypowered.api.proxy.server.RegisteredServer 9 | import com.velocitypowered.api.util.GameProfile 10 | import com.velocitypowered.api.util.ModInfo 11 | import kotlinx.coroutines.future.await 12 | import java.util.UUID 13 | 14 | inline val Player.uniqueId: UUID 15 | get() = id() 16 | 17 | inline val Player.username: String 18 | get() = username() 19 | 20 | inline val Player.connectedServer: ServerConnection? 21 | get() = connectedServer() 22 | 23 | inline val Player.clientSettings: ClientSettings 24 | get() = clientSettings() 25 | 26 | inline val Player.modInfo: ModInfo? 27 | get() = modInfo() 28 | 29 | inline val Player.ping: Long 30 | get() = ping() 31 | 32 | inline val Player.onlineMode: Boolean 33 | get() = onlineMode() 34 | 35 | inline var Player.gameProfileProperties: Collection 36 | get() = gameProfile().properties() 37 | set(value) { 38 | setGameProfileProperties(value.toList()) 39 | } 40 | 41 | inline val Player.gameProfile: GameProfile 42 | get() = gameProfile() 43 | 44 | inline val Player.tabList: TabList 45 | get() = tabList() 46 | 47 | suspend fun Player.connectTo(server: RegisteredServer): ConnectionRequestBuilder.Result = 48 | createConnectionRequest(server).connect().await() 49 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/connection/ServerConnection.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.connection 2 | 3 | import com.velocitypowered.api.proxy.connection.Player 4 | import com.velocitypowered.api.proxy.connection.ServerConnection 5 | import com.velocitypowered.api.proxy.server.RegisteredServer 6 | import com.velocitypowered.api.proxy.server.ServerInfo 7 | 8 | inline val ServerConnection.target: RegisteredServer 9 | get() = target() 10 | 11 | inline val ServerConnection.serverInfo: ServerInfo 12 | get() = serverInfo() 13 | 14 | inline val ServerConnection.player: Player 15 | get() = player() 16 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/player/ConnectionRequestBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.player 2 | 3 | import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder 4 | import com.velocitypowered.api.proxy.server.RegisteredServer 5 | import net.kyori.adventure.text.Component 6 | 7 | inline val ConnectionRequestBuilder.target: RegisteredServer 8 | get() = target() 9 | 10 | inline val ConnectionRequestBuilder.Result.status: ConnectionRequestBuilder.Status 11 | get() = status() 12 | 13 | inline val ConnectionRequestBuilder.Result.failureReason: Component? 14 | get() = failureReason() 15 | 16 | inline val ConnectionRequestBuilder.Result.finalTarget: RegisteredServer 17 | get() = finalTarget() 18 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/player/TabList.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.player 2 | 3 | import com.velocitypowered.api.proxy.player.TabList 4 | import com.velocitypowered.api.proxy.player.TabListEntry 5 | import java.util.UUID 6 | 7 | inline val TabList.entries: Collection 8 | get() = entries() 9 | 10 | operator fun TabList.plus(entry: TabListEntry): TabList = apply { 11 | addEntry(entry) 12 | } 13 | 14 | operator fun TabList.plusAssign(entry: TabListEntry) { 15 | addEntry(entry) 16 | } 17 | 18 | operator fun TabList.minus(uniqueId: UUID): TabList = apply { 19 | removeEntry(uniqueId) 20 | } 21 | 22 | operator fun TabList.minusAssign(uniqueId: UUID) { 23 | removeEntry(uniqueId) 24 | } 25 | 26 | operator fun TabList.contains(uniqueId: UUID): Boolean = 27 | containsEntry(uniqueId) 28 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/player/TabListEntry.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.player 2 | 3 | import com.velocitypowered.api.proxy.player.TabList 4 | import com.velocitypowered.api.proxy.player.TabListEntry 5 | import com.velocitypowered.api.util.GameProfile 6 | import net.kyori.adventure.text.Component 7 | 8 | inline val TabListEntry.parent: TabList 9 | get() = parent() 10 | 11 | inline val TabListEntry.gameProfile: GameProfile 12 | get() = gameProfile() 13 | 14 | inline var TabListEntry.displayName: Component? 15 | get() = displayName() 16 | set(value) { 17 | setDisplayName(value) 18 | } 19 | 20 | inline var TabListEntry.ping: Int 21 | get() = ping() 22 | set(value) { 23 | setPing(value) 24 | } 25 | 26 | inline var TabListEntry.gameMode: Int 27 | get() = gameMode() 28 | set(value) { 29 | setGameMode(value) 30 | } 31 | 32 | inline fun TabListEntry(builder: TabListEntry.Builder.() -> Unit): TabListEntry = 33 | TabListEntry.builder().apply(builder).build() 34 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/server/QueryResponse.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.server 2 | 3 | import com.velocitypowered.api.proxy.server.QueryResponse 4 | 5 | inline val QueryResponse.hostname: String 6 | get() = hostname() 7 | 8 | inline val QueryResponse.gameVersion: String 9 | get() = gameVersion() 10 | 11 | inline val QueryResponse.mapName: String 12 | get() = mapName() 13 | 14 | inline val QueryResponse.onlinePlayers: Int 15 | get() = onlinePlayers() 16 | 17 | inline val QueryResponse.maxPlayers: Int 18 | get() = maxPlayers() 19 | 20 | inline val QueryResponse.proxyHost: String 21 | get() = proxyHost() 22 | 23 | inline val QueryResponse.proxyPort: Int 24 | get() = proxyPort() 25 | 26 | inline val QueryResponse.players: Collection 27 | get() = players() 28 | 29 | inline val QueryResponse.proxyVersion: String 30 | get() = proxyVersion() 31 | 32 | inline val QueryResponse.plugins: Collection 33 | get() = plugins() 34 | 35 | inline fun QueryResponse(builder: QueryResponse.Builder.() -> Unit): QueryResponse = 36 | QueryResponse.builder().apply(builder).build() 37 | 38 | operator fun QueryResponse.PluginInformation.component1(): String = name 39 | operator fun QueryResponse.PluginInformation.component2(): String? = version 40 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/server/RegisteredServer.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.server 2 | 3 | import com.velocitypowered.api.proxy.connection.Player 4 | import com.velocitypowered.api.proxy.server.RegisteredServer 5 | import com.velocitypowered.api.proxy.server.ServerInfo 6 | 7 | inline val RegisteredServer.serverInfo: ServerInfo 8 | get() = serverInfo() 9 | 10 | inline val RegisteredServer.connectedPlayers: Collection 11 | get() = connectedPlayers() 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/server/ServerInfo.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.server 2 | 3 | import com.velocitypowered.api.proxy.server.ServerInfo 4 | import java.net.SocketAddress 5 | 6 | inline val ServerInfo.name: String 7 | get() = name() 8 | 9 | inline val ServerInfo.address: SocketAddress 10 | get() = address() 11 | 12 | operator fun ServerInfo.component1(): String = name 13 | operator fun ServerInfo.component2(): SocketAddress = address 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/proxy/server/ServerPing.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.proxy.server 2 | 3 | import com.velocitypowered.api.proxy.server.ServerPing 4 | import com.velocitypowered.api.util.Favicon 5 | import com.velocitypowered.api.util.ModInfo 6 | import net.kyori.adventure.text.Component 7 | import java.util.UUID 8 | 9 | inline val ServerPing.version: ServerPing.Version 10 | get() = version() 11 | 12 | inline val ServerPing.players: ServerPing.Players? 13 | get() = players() 14 | 15 | inline val ServerPing.description: Component 16 | get() = description() 17 | 18 | inline val ServerPing.favicon: Favicon? 19 | get() = favicon() 20 | 21 | inline val ServerPing.modInfo: ModInfo? 22 | get() = modInfo() 23 | 24 | fun ServerPing(builder: ServerPing.Builder.() -> Unit): ServerPing = 25 | ServerPing.builder().apply(builder).build() 26 | 27 | inline val ServerPing.Version.protocol: Int 28 | get() = protocol() 29 | 30 | inline val ServerPing.Version.name: String 31 | get() = name() 32 | 33 | operator fun ServerPing.Version.component1(): Int = protocol 34 | operator fun ServerPing.Version.component2(): String = name 35 | 36 | inline val ServerPing.Players.online: Int 37 | get() = online() 38 | 39 | inline val ServerPing.Players.max: Int 40 | get() = maximum() 41 | 42 | inline val ServerPing.Players.sample: Collection 43 | get() = sample() 44 | 45 | operator fun ServerPing.Players.component1(): Int = online 46 | operator fun ServerPing.Players.component2(): Int = max 47 | operator fun ServerPing.Players.component3(): Collection = sample 48 | 49 | inline val ServerPing.SamplePlayer.uniqueId: UUID 50 | get() = id() 51 | 52 | inline val ServerPing.SamplePlayer.name: String 53 | get() = name() 54 | 55 | operator fun ServerPing.SamplePlayer.component1(): UUID = uniqueId 56 | operator fun ServerPing.SamplePlayer.component2(): String = name 57 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/scheduler/Scheduler.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.scheduler 2 | 3 | import com.velocitypowered.api.scheduler.Scheduler 4 | import java.util.concurrent.TimeUnit 5 | import kotlin.time.Duration 6 | import kotlin.time.ExperimentalTime 7 | 8 | @ExperimentalTime 9 | fun Scheduler.TaskBuilder.delay(duration: Duration) = apply { 10 | delay(duration.inWholeMilliseconds, TimeUnit.MILLISECONDS) 11 | } 12 | 13 | @ExperimentalTime 14 | fun Scheduler.TaskBuilder.repeat(duration: Duration) = apply { 15 | repeat(duration.inWholeMilliseconds, TimeUnit.MILLISECONDS) 16 | } 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/velocitypowered/api/kt/util/GameProfile.kt: -------------------------------------------------------------------------------- 1 | package com.velocitypowered.api.kt.util 2 | 3 | import com.velocitypowered.api.util.GameProfile 4 | import java.util.UUID 5 | 6 | inline val GameProfile.uniqueId: UUID 7 | get() = uuid() 8 | 9 | inline val GameProfile.name: String 10 | get() = name() 11 | 12 | inline val GameProfile.properties: Collection 13 | get() = properties() 14 | 15 | operator fun GameProfile.plus(properties: Iterable): GameProfile = 16 | addProperties(properties) 17 | 18 | operator fun GameProfile.plus(property: GameProfile.Property): GameProfile = 19 | addProperty(property) 20 | 21 | operator fun GameProfile.component1(): UUID = uniqueId 22 | operator fun GameProfile.component2(): String = name 23 | operator fun GameProfile.component3(): Collection = properties 24 | 25 | inline val GameProfile.Property.name: String 26 | get() = name() 27 | 28 | inline val GameProfile.Property.value: String 29 | get() = value() 30 | 31 | inline val GameProfile.Property.signature: String? 32 | get() = signature() 33 | 34 | operator fun GameProfile.Property.component1(): String = name 35 | operator fun GameProfile.Property.component2(): String = value 36 | operator fun GameProfile.Property.component3(): String? = signature 37 | --------------------------------------------------------------------------------