├── .github └── workflows │ ├── build.yml │ ├── pr_build.yml │ └── release.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── docs ├── COMMANDS.md ├── CONFIGURATION.md ├── INDEX.md └── TECHNICAL.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main ├── java └── com │ └── oskarsmc │ └── message │ ├── Message.java │ ├── command │ ├── MessageCommand.java │ ├── ReplyCommand.java │ └── SocialSpyCommand.java │ ├── configuration │ └── MessageSettings.java │ ├── event │ ├── MessageEvent.java │ └── StringResult.java │ ├── locale │ ├── CommandExceptionHandler.java │ ├── TranslationFile.java │ └── TranslationManager.java │ ├── logic │ ├── MessageHandler.java │ └── MessageMetrics.java │ └── util │ ├── CloudSuggestionProcessor.java │ ├── DefaultPermission.java │ ├── DependencyChecker.java │ ├── MessageModule.java │ ├── StatsUtils.java │ └── VersionUtils.java └── resources ├── config.toml ├── translations.json └── velocity-plugin.json /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build message 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | java: [ "17" ] 12 | os: [ "ubuntu-latest" ] 13 | 14 | runs-on: ${{ matrix.os }} 15 | steps: 16 | - name: "checkout" 17 | uses: actions/checkout@v3 18 | 19 | - name: "setup java" 20 | uses: actions/setup-java@v2 21 | with: 22 | java-version: ${{ matrix.java }} 23 | distribution: 'adopt' 24 | cache: gradle 25 | 26 | - name: "validate gradle wrapper" 27 | uses: gradle/wrapper-validation-action@v1 28 | 29 | - name: gradle build 30 | run: ./gradlew clean build 31 | 32 | # Upload Artifacts 33 | - uses: actions/upload-artifact@v2 34 | with: 35 | name: message 36 | path: build/libs 37 | retention-days: 60 38 | publish: 39 | strategy: 40 | matrix: 41 | java: [ "17" ] 42 | os: [ "ubuntu-latest" ] 43 | 44 | needs: build 45 | runs-on: ${{ matrix.os }} 46 | steps: 47 | - name: "checkout" 48 | uses: actions/checkout@v3 49 | 50 | - name: "setup java" 51 | uses: actions/setup-java@v2 52 | with: 53 | java-version: ${{ matrix.java }} 54 | distribution: 'adopt' 55 | cache: gradle 56 | 57 | - name: "validate gradle wrapper" 58 | uses: gradle/wrapper-validation-action@v1 59 | 60 | - name: gradle publish 61 | run: ./gradlew build publish publishAllPublicationsToHangar 62 | env: 63 | MAVEN_USERNAME: ${{ SECRETS.MAVEN_USERNAME }} 64 | MAVEN_SECRET: ${{ SECRETS.MAVEN_SECRET }} 65 | HANGAR_API_KEY: ${{ SECRETS.HANGAR_API_KEY }} 66 | -------------------------------------------------------------------------------- /.github/workflows/pr_build.yml: -------------------------------------------------------------------------------- 1 | name: Build message 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: "checkout" 10 | uses: actions/checkout@v3 11 | 12 | - name: "setup jdk" 13 | uses: actions/setup-java@v3 14 | with: 15 | java-version: 17 16 | distribution: 'adopt' 17 | cache: gradle 18 | 19 | - name: "validate gradle wrapper" 20 | uses: gradle/wrapper-validation-action@v1 21 | 22 | - name: "build with gradle" 23 | run: ./gradlew clean build 24 | 25 | # Upload Artifacts 26 | - name: "upload artifacts" 27 | uses: actions/upload-artifact@v2 28 | with: 29 | name: message-pr-${{ github.event.pullrequest.number }} 30 | path: build/libs 31 | retention-days: 30 -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release message 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | release: 9 | strategy: 10 | matrix: 11 | java: [ "17" ] 12 | os: [ "ubuntu-latest" ] 13 | 14 | runs-on: ${{ matrix.os }} 15 | steps: 16 | - name: "checkout" 17 | uses: actions/checkout@v3 18 | 19 | - name: "setup jdk ${{ matrix.java }}" 20 | uses: actions/setup-java@v3 21 | with: 22 | java-version: ${{ matrix.java }} 23 | distribution: 'adopt' 24 | cache: gradle 25 | 26 | - name: "validate gradle wrapper" 27 | uses: gradle/wrapper-validation-action@v1 28 | 29 | - name: "setup gradle" 30 | uses: gradle/gradle-build-action@v2 31 | 32 | - name: "gradle build and publish" 33 | run: ./gradlew clean build publish publishAllPublicationsToHangar 34 | env: 35 | GRADLE_RELEASE: true 36 | MAVEN_USERNAME: ${{ SECRETS.MAVEN_USERNAME }} 37 | MAVEN_SECRET: ${{ SECRETS.MAVEN_SECRET }} 38 | HANGAR_RELEASE_CHANGELOG: ${{ github.event.release.body }} 39 | HANGAR_API_KEY: ${{ SECRETS.HANGAR_API_KEY }} 40 | 41 | - name: upload artifacts 42 | uses: actions/upload-artifact@v2 43 | with: 44 | name: message 45 | path: build/libs/*.jar 46 | retention-days: 365 47 | 48 | # Release Artifacts 49 | - name: release artifacts 50 | uses: softprops/action-gh-release@v1 51 | with: 52 | tag_name: ${{ github.event.release.tag_name }} 53 | files: build/libs/*.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/java,gradle,intellij+all,windows,linux,macos,git 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle,intellij+all,windows,linux,macos,git 4 | 5 | ### Git ### 6 | # Created by git for backups. To disable backups in Git: 7 | # $ git config --global mergetool.keepBackup false 8 | *.orig 9 | 10 | # Created by git when using merge tools for conflicts 11 | *.BACKUP.* 12 | *.BASE.* 13 | *.LOCAL.* 14 | *.REMOTE.* 15 | *_BACKUP_*.txt 16 | *_BASE_*.txt 17 | *_LOCAL_*.txt 18 | *_REMOTE_*.txt 19 | 20 | ### Intellij+all ### 21 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 22 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 23 | 24 | # User-specific stuff 25 | .idea/**/workspace.xml 26 | .idea/**/tasks.xml 27 | .idea/**/usage.statistics.xml 28 | .idea/**/dictionaries 29 | .idea/**/shelf 30 | 31 | # AWS User-specific 32 | .idea/**/aws.xml 33 | 34 | # Generated files 35 | .idea/**/contentModel.xml 36 | 37 | # Sensitive or high-churn files 38 | .idea/**/dataSources/ 39 | .idea/**/dataSources.ids 40 | .idea/**/dataSources.local.xml 41 | .idea/**/sqlDataSources.xml 42 | .idea/**/dynamic.xml 43 | .idea/**/uiDesigner.xml 44 | .idea/**/dbnavigator.xml 45 | 46 | # Gradle 47 | .idea/**/gradle.xml 48 | .idea/**/libraries 49 | 50 | # Gradle and Maven with auto-import 51 | # When using Gradle or Maven with auto-import, you should exclude module files, 52 | # since they will be recreated, and may cause churn. Uncomment if using 53 | # auto-import. 54 | # .idea/artifacts 55 | # .idea/compiler.xml 56 | # .idea/jarRepositories.xml 57 | # .idea/modules.xml 58 | # .idea/*.iml 59 | # .idea/modules 60 | # *.iml 61 | # *.ipr 62 | 63 | # CMake 64 | cmake-build-*/ 65 | 66 | # Mongo Explorer plugin 67 | .idea/**/mongoSettings.xml 68 | 69 | # File-based project format 70 | *.iws 71 | 72 | # IntelliJ 73 | out/ 74 | 75 | # mpeltonen/sbt-idea plugin 76 | .idea_modules/ 77 | 78 | # JIRA plugin 79 | atlassian-ide-plugin.xml 80 | 81 | # Cursive Clojure plugin 82 | .idea/replstate.xml 83 | 84 | # Crashlytics plugin (for Android Studio and IntelliJ) 85 | com_crashlytics_export_strings.xml 86 | crashlytics.properties 87 | crashlytics-build.properties 88 | fabric.properties 89 | 90 | # Editor-based Rest Client 91 | .idea/httpRequests 92 | 93 | # Android studio 3.1+ serialized cache file 94 | .idea/caches/build_file_checksums.ser 95 | 96 | ### Intellij+all Patch ### 97 | # Ignores the whole .idea folder and all .iml files 98 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 99 | 100 | .idea/ 101 | 102 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 103 | 104 | *.iml 105 | modules.xml 106 | .idea/misc.xml 107 | *.ipr 108 | 109 | # Sonarlint plugin 110 | .idea/sonarlint 111 | 112 | ### Java ### 113 | # Compiled class file 114 | *.class 115 | 116 | # Log file 117 | *.log 118 | 119 | # BlueJ files 120 | *.ctxt 121 | 122 | # Mobile Tools for Java (J2ME) 123 | .mtj.tmp/ 124 | 125 | # Package Files # 126 | *.jar 127 | *.war 128 | *.nar 129 | *.ear 130 | *.zip 131 | *.tar.gz 132 | *.rar 133 | 134 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 135 | hs_err_pid* 136 | 137 | ### Linux ### 138 | *~ 139 | 140 | # temporary files which can be created if a process still has a handle open of a deleted file 141 | .fuse_hidden* 142 | 143 | # KDE directory preferences 144 | .directory 145 | 146 | # Linux trash folder which might appear on any partition or disk 147 | .Trash-* 148 | 149 | # .nfs files are created when an open file is removed but is still being accessed 150 | .nfs* 151 | 152 | ### macOS ### 153 | # General 154 | .DS_Store 155 | .AppleDouble 156 | .LSOverride 157 | 158 | # Icon must end with two \r 159 | Icon 160 | 161 | 162 | # Thumbnails 163 | ._* 164 | 165 | # Files that might appear in the root of a volume 166 | .DocumentRevisions-V100 167 | .fseventsd 168 | .Spotlight-V100 169 | .TemporaryItems 170 | .Trashes 171 | .VolumeIcon.icns 172 | .com.apple.timemachine.donotpresent 173 | 174 | # Directories potentially created on remote AFP share 175 | .AppleDB 176 | .AppleDesktop 177 | Network Trash Folder 178 | Temporary Items 179 | .apdisk 180 | 181 | ### Windows ### 182 | # Windows thumbnail cache files 183 | Thumbs.db 184 | Thumbs.db:encryptable 185 | ehthumbs.db 186 | ehthumbs_vista.db 187 | 188 | # Dump file 189 | *.stackdump 190 | 191 | # Folder config file 192 | [Dd]esktop.ini 193 | 194 | # Recycle Bin used on file shares 195 | $RECYCLE.BIN/ 196 | 197 | # Windows Installer files 198 | *.cab 199 | *.msi 200 | *.msix 201 | *.msm 202 | *.msp 203 | 204 | # Windows shortcuts 205 | *.lnk 206 | 207 | ### Gradle ### 208 | .gradle 209 | build/ 210 | 211 | # Ignore Gradle GUI config 212 | gradle-app.setting 213 | 214 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 215 | !gradle-wrapper.jar 216 | 217 | # Cache of project 218 | .gradletasknamecache 219 | 220 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 221 | # gradle/wrapper/gradle-wrapper.properties 222 | 223 | ### Gradle Patch ### 224 | **/build/ 225 | 226 | # Eclipse Gradle plugin generated files 227 | # Eclipse Core 228 | .project 229 | # JDT-specific (Eclipse Java Development Tools) 230 | .classpath 231 | 232 | # End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij+all,windows,linux,macos,git 233 | 234 | # message - runVelocity 235 | run/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OskarsMC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # message 2 | 3 | Message is the first cross-server proxy messaging platform for Velocity with API and LuckPerms integration. 4 | 5 | It is simple yet extensive, allowing for a working messaging system with no setup, but is also completely customisable 6 | with logical configuration files and API. 7 | 8 | It has: 9 | 10 | * **full & custom translation support** - all messages sent by the plugin can be customised, which is useful for 11 | networks that have struggled with english-only plugins for years 12 | * **extensive customisation** - every aspect of the plugin can be customised 13 | * **LuckPerms integration** - if one wants to customise messages using data from LuckPerms, that is completely 14 | achievable with message 15 | * **API integration** - other plugins can integrate with message, for example moderation plugins or your internal 16 | toolkit for the best user & moderation experiences 17 | 18 | 19 | message usage statistics 20servers, 100players at the time of writing 20 | 21 | message has dispatched thousands of messages on velocity servers 22 | worldwide, with little reported bugs. 23 | 24 | ## Documentation: 25 | 26 | - [Documentation Index](docs/INDEX.md) 27 | * [Commands](docs/COMMANDS.md) 28 | * [Configuration](docs/CONFIGURATION.md) 29 | * [Technical / API](docs/TECHNICAL.md) 30 | 31 | ## Download: 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 46 | 49 | 50 | 51 |
GitHubHangarOskarsMC Repository (mirror)
41 | GitHub Releases 42 | 44 | hangar.papermc.io 45 | 47 | repository.oskarsmc.com 48 |
52 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import io.papermc.hangarpublishplugin.model.Platforms 2 | import java.io.* 3 | 4 | plugins { 5 | java 6 | id("com.github.johnrengelman.shadow") version "7.1.2" 7 | `maven-publish` 8 | id("xyz.jpenilla.run-velocity") version "2.0.0" 9 | id("io.papermc.hangar-publish-plugin") version "0.0.4" 10 | } 11 | 12 | repositories { 13 | mavenCentral() 14 | maven("https://repo.papermc.io/repository/maven-public/") 15 | } 16 | 17 | dependencies { 18 | implementation("org.bstats:bstats-velocity:3.0.1") 19 | implementation("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") 20 | implementation("cloud.commandframework:cloud-velocity:1.8.2") 21 | implementation("cloud.commandframework:cloud-minecraft-extras:1.8.2") 22 | compileOnly("net.luckperms:api:5.4") 23 | compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.0.0") 24 | } 25 | 26 | fun runCommand(command: String): String { 27 | return Runtime 28 | .getRuntime() 29 | .exec(command) 30 | .let { process -> 31 | process.waitFor() 32 | val output = process.inputStream.use { 33 | it.bufferedReader().use(BufferedReader::readText) 34 | } 35 | process.destroy() 36 | output.trim() 37 | } 38 | } 39 | 40 | val release = System.getenv("GRADLE_RELEASE").equals("true", ignoreCase = true) 41 | val gitHash = runCommand("git rev-parse --short HEAD") 42 | group = "com.oskarsmc" 43 | version = "1.4.0" 44 | 45 | if (!release) { 46 | version = "$version-$gitHash-SNAPSHOT" 47 | } 48 | 49 | 50 | tasks { 51 | processResources { 52 | expand("project" to project) 53 | } 54 | 55 | shadowJar { 56 | dependencies { 57 | include { 58 | it.moduleGroup == "org.bstats" || it.moduleGroup == "cloud.commandframework" || it.moduleGroup == "io.leangen.geantyref" 59 | } 60 | } 61 | relocate("org.bstats", "com.oskarsmc.message.relocated.bstats") 62 | relocate("cloud.commandframework", "com.oskarsmc.message.relocated.cloud") 63 | relocate("io.leangen.geantyref", "com.oskarsmc.message.relocated.geantyref") 64 | } 65 | 66 | build { 67 | dependsOn(named("shadowJar")) 68 | } 69 | 70 | runVelocity { 71 | // Configure the Velocity version for our task. 72 | // This is the only required configuration besides applying the plugin. 73 | // Your plugin's jar (or shadowJar if present) will be used automatically. 74 | velocityVersion("3.1.2-SNAPSHOT") 75 | } 76 | } 77 | 78 | val jar by tasks.getting(Jar::class) { 79 | manifest { 80 | attributes["Implementation-Title"] = "message" 81 | attributes["Implementation-Version"] = project.version 82 | attributes["Implementation-Vendor"] = "OskarsMC" 83 | } 84 | } 85 | 86 | publishing { 87 | publications { 88 | create("maven") { 89 | groupId = project.group as String? 90 | artifactId = project.name 91 | version = project.version as String? 92 | 93 | from(components["java"]) 94 | } 95 | } 96 | repositories { 97 | maven { 98 | val releasesRepoUrl = uri("https://repository.oskarsmc.com/releases") 99 | val snapshotsRepoUrl = uri("https://repository.oskarsmc.com/snapshots") 100 | url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl 101 | credentials { 102 | username = System.getenv("MAVEN_USERNAME") 103 | password = System.getenv("MAVEN_SECRET") 104 | } 105 | } 106 | } 107 | } 108 | 109 | hangarPublish { 110 | if (!release) { 111 | publications.register("dev") { 112 | namespace("OskarsMC-Plugins", "message") 113 | channel.set("Development") 114 | apiKey.set(System.getenv("HANGAR_API_KEY")) 115 | version.set(project.version.toString()) 116 | 117 | changelog.set(runCommand("git log -n 1")) 118 | 119 | 120 | platforms { 121 | register(Platforms.VELOCITY) { 122 | jar.set(tasks.shadowJar.flatMap { it.archiveFile }) 123 | platformVersions.set(listOf("3.2")) 124 | } 125 | } 126 | } 127 | } else { 128 | publications.register("publish") { 129 | namespace("OskarsMC-Plugins", "message") 130 | channel.set("Release") 131 | apiKey.set(System.getenv("HANGAR_API_KEY")) 132 | version.set(project.version.toString()) 133 | 134 | 135 | changelog.set(System.getenv("HANGAR_RELEASE_CHANGELOG")) 136 | 137 | platforms { 138 | register(Platforms.VELOCITY) { 139 | jar.set(tasks.shadowJar.flatMap { it.archiveFile }) 140 | platformVersions.set(listOf("3.2")) 141 | } 142 | } 143 | } 144 | } 145 | } 146 | 147 | java { 148 | withJavadocJar() 149 | withSourcesJar() 150 | } 151 | -------------------------------------------------------------------------------- /docs/COMMANDS.md: -------------------------------------------------------------------------------- 1 | # Commands 2 | 3 | - [Index](INDEX.md) 4 | - [Commands](#commands) 5 | - [/message](#message-) 6 | - [/reply](#reply-) 7 | - [/socialspy](#socialspy-) 8 | 9 | ## Message: 10 | 11 | /message 12 | /msg 13 | 14 | | Base Command | Player | Message | Permission | 15 | |--------------|------------------------------|-------------|-----------------------------| 16 | | /message | Any name of an online player | Any Message | osmc.message.send (Default) | 17 | | /msg | Any name of an online player | Any Message | osmc.message.send (Default) | 18 | 19 | ## Reply: 20 | 21 | /reply 22 | /r 23 | 24 | | Base Command | Message | Permission | 25 | |--------------|-------------|------------------------------| 26 | | /reply | Any Message | osmc.message.reply (Default) | 27 | | /r | Any Message | osmc.message.reply (Default) | 28 | 29 | ## SocialSpy: 30 | 31 | /socialspy 32 | /ss 33 | 34 | | Base Command | Action | Permission | 35 | |--------------|------------------------|------------------------| 36 | | /socialspy | Turn On, Off or Toggle | osmc.message.socialspy | 37 | | /ss | Turn On, Off or Toggle | osmc.message.socialspy | 38 | -------------------------------------------------------------------------------- /docs/CONFIGURATION.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | - [Index](INDEX.md) 4 | - [Configuration](#configuration) 5 | - [File](#file-) 6 | - [`plugin`](#plugin) 7 | - [`messages`](#messages) 8 | - [`error-handlers`](#error-handlers) 9 | - [`aliases`](#aliases) 10 | - [Translations](#translations) 11 | 12 | ## File: 13 | 14 | ```toml 15 | # Plugin Settings 16 | [plugin] 17 | enabled = true 18 | luckperms-integration = true # If luckperms is found, use luckperms prefixes and suffixes. 19 | miniplaceholders-integration = true # If miniplaceholders is present, you can use the MiniPlaceholders placeholders in the messages. 20 | allow-self-message-sending = true # Allow a player to send messages to themselves. 21 | 22 | # Customise messages using MiniMessage 23 | # Documentation: https://docs.adventure.kyori.net/minimessage.html#format or https://webui.adventure.kyori.net/ 24 | # Default Placeholders: , , , , , , , , , , 25 | # You may use MiniPlaceholders placeholders if the respective integration option is enabled. 26 | # Preview: https://webui.adventure.kyori.net/?mode=chat_closed&input=%3Cwhite%3E%5B%3Ccolor%3A%23FFCE45%3EYOU%3C%2Fcolor%3E%20%E2%86%92%20%3Ccolor%3A%23D4AC2B%3E%3Creceiver_prefix%3E%3Creceiver%3E%3Creceiver_suffix%3E%3C%2Fcolor%3E%5D%20%3Cmessage%3E%3C%2Fwhite%3E%0A%3Cwhite%3E%5B%3Ccolor%3A%23FFCE45%3E%3Csender_prefix%3E%3Csender%3E%3Csender_suffix%3E%3C%2Fcolor%3E%20%E2%86%92%20%3Ccolor%3A%23D4AC2B%3EYOU%3C%2Fcolor%3E%5D%20%3Cmessage%3E%3C%2Fwhite%3E%0A%3Cgradient%3Aaqua%3Ablue%3E%5BSocialSpy%5D%20%3C%2Fgradient%3E%5B%3Cwhite%3E%3Csender%3E%20%E2%86%92%20%3Creceiver%3E%5D%3A%20%3Cmessage%3E&st=%7B%22sender%22%3A%22Player1%22%2C%22receiver%22%3A%22Player2%22%2C%22message%22%3A%22Hello%2C%20World!%22%2C%22receiver_prefix%22%3A%22Admin%20%22%2C%22receiver_suffix%22%3A%22%20%5BLevel%201%5D%22%2C%22sender_prefix%22%3A%22Moderator%20%22%2C%22sender_suffix%22%3A%22%20%5BLevel%200%5D%22%7D 27 | [messages] 28 | message-sent = "[YOU → ] " 29 | message-received = "[YOU] " 30 | message-socialspy = "[SocialSpy] []: " 31 | 32 | 33 | # Customise error handling - leave blank to disable 34 | # Documentation: https://docs.adventure.kyori.net/minimessage.html#format or https://webui.adventure.kyori.net/ 35 | # Syntax: "class" = "message in minimessage" 36 | [error-handlers] 37 | # "cloud.commandframework.exceptions.InvalidSyntaxException" = "" 38 | 39 | # Aliases: 40 | # Customise using a TOML string array. 41 | [aliases] 42 | message = ["msg", "tell"] 43 | reply = ["r"] 44 | socialspy = ["ss"] 45 | 46 | # Please don't touch this 47 | [developer-info] 48 | config-version = 1.2 49 | ``` 50 | 51 | ### Plugin 52 | 53 | - `enabled`: (boolean) Enable the plugin 54 | - `luckperms-integration`: (boolean) Enable [luckperms](https://luckperms.net/) integration 55 | - `miniplaceholders-integration`: (boolean) 56 | Enable [MiniPlaceholders](https://github.com/MiniPlaceholders/MiniPlaceholders/) integration 57 | - `allow-self-message-sending`: (boolean) Allow players to send messages to themselves 58 | 59 | ### Messages 60 | 61 | - `message-sent`: The message sent to the command sender after _sending_ the message 62 | - `message-received`: The message sent to the command sender _receiving_ the message 63 | - `message-socialspy`: The message displayed to a command sender receiving _socialspy_ messages. 64 | 65 | ### Error Handlers 66 | 67 | The format for declaring an error handler is as follows: 68 | 69 | ```toml 70 | "com.example.exception.ExceptionClass" = "minimessage format" 71 | ``` 72 | 73 |
74 |
75 | Example: Using exception handlers with translations 76 | In some cases, server admins may wish to localise their error messages. 77 | For this, the MiniMessage translatable tag would be used as seen below: 78 | 79 | ```toml 80 | "cloud.commandframework.exceptions.InvalidSyntaxException" = "" 81 | ``` 82 | 83 | Accompanied by a matching translation definition for `com.yourserver-invalid-syntax` as a custom definition in the 84 | translation configuration. Read more about the translation configuration [here](#translations) 85 |
86 |
87 | 88 | #### Common Exceptions 89 | 90 | * `cloud.commandframework.exceptions.InvalidSyntaxException`: Invalid Syntax 91 | * `cloud.commandframework.exceptions.ArgumentParseException`: Invalid Argument 92 | * `cloud.commandframework.exceptions.NoPermissionException`: Permission Error 93 | * `cloud.commandframework.exceptions.InvalidCommandSenderException`: Sender Type Error 94 | 95 | ### Aliases 96 | 97 | * `message`: list\[string] List of aliases for the `/message` command 98 | * `reply`: list\[string] List of aliases for the `/reply` command 99 | * `socialspy`: list\[string] List of aliases for the `/socialspy` command 100 | 101 | ## Translations 102 | 103 | Translations are included as json files, in the `message/translations/` folder. 104 | 105 | The plugin will read translations that match the following filename: `translations-.json`, 106 | where `` is the version of the plugin. 107 | 108 | ### Translation File 109 | 110 | ```json 111 | { 112 | "translation-version": "1.2.0-SNAPSHOT", 113 | "translations": [ 114 | { 115 | "language-tag": "en-US", 116 | "translations": { 117 | "oskarsmc.message.command.message.argument.player-argument": "The player to send the message to.", 118 | "oskarsmc.message.command.common.argument.message-description": "The message to send to the player.", 119 | "oskarsmc.message.command.socialspy.on": "SocialSpy enabled.", 120 | "oskarsmc.message.command.socialspy.off": "SocialSpy disabled.", 121 | "oskarsmc.message.command.common.self-sending-error": "You cannot send messages to yourself." 122 | } 123 | }, 124 | { 125 | "language-tag": "es-ES", 126 | "translations": { 127 | "oskarsmc.message.command.message.argument.player-argument": "El jugador al cual enviar el mensaje.", 128 | "oskarsmc.message.command.common.argument.message-description": "El mensaje que se enviara al jugador.", 129 | "oskarsmc.message.command.socialspy.on": "SocialSpy habilitado.", 130 | "oskarsmc.message.command.socialspy.off": "SocialSpy deshabilitado.", 131 | "oskarsmc.message.command.common.self-sending-error": "No puedes enviarte mensajes a ti mismo." 132 | } 133 | } 134 | ] 135 | } 136 | ``` 137 | 138 | * `translation-version`: (string) version of the translation, used to determine if the translation file is outdated or 139 | not. don't touch this. 140 | * `translations`: (list\[object]) _as follows_ 141 | * `language-tag`: (string) A [language tag](https://www.oracle.com/java/technologies/javase/java8locales.html) 142 | compliant with [IETF BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag) 143 | * `translations`: (dictionary\[string, string]) A dictionary of translation keys and values. 144 | 145 |
146 |
147 | Example: Creating custom translations 148 | In some cases, server admins may wish to create their own localisations, for example, in custom error messages. 149 | For this, a custom translation would be defined as such, under translations[].translations 150 | 151 | ```json5 152 | // note json doesn't support comments like in this demo 153 | { 154 | "language-tag": "en-GB", 155 | "translations": { 156 | // remember to include the default translations as to not break existing commands! 157 | "com.yourserver.invalid-syntax": "Invalid Syntax" 158 | } 159 | } 160 | ``` 161 | 162 | Accompanied by a matching error handler for `com.yourserver-invalid-syntax` as a custom exception handler in the 163 | [`error-handlers`](#error-handlers) configuration. Read more about the error handler 164 | configuration [here](#error-handlers) 165 |
166 |
-------------------------------------------------------------------------------- /docs/INDEX.md: -------------------------------------------------------------------------------- 1 | # message documentation 2 | 3 | [Back to README](../README.md) 4 | 5 | * [Index](#message-documentation) 6 | * [Commands](COMMANDS.md#commands) 7 | * [/message](COMMANDS.md#message-) 8 | * [/reply](COMMANDS.md#reply-) 9 | * [/socialspy](COMMANDS.md#socialspy-) 10 | 11 | * [Configuration](CONFIGURATION.md#configuration) 12 | * [File](CONFIGURATION.md#file-) 13 | * [`plugin`](CONFIGURATION.md#plugin) 14 | * [`messages`](CONFIGURATION.md#messages) 15 | * [`error-handlers`](CONFIGURATION.md#error-handlers) 16 | * [`aliases`](CONFIGURATION.md#aliases) 17 | * [Translations](CONFIGURATION.md#translations) 18 | 19 | * [Technical Details](TECHNICAL.md#technical-details-) 20 | * [Java](TECHNICAL.md#java) 21 | * [API](TECHNICAL.md#api) 22 | * [API Inclusion](TECHNICAL.md#including-) 23 | * [Usage](TECHNICAL.md#usage-) 24 | * [JavaDocs](TECHNICAL.md#javadocs) 25 | * [Code Example](TECHNICAL.md#example) 26 | 27 | Message is published on [Hangar](https://hangar.papermc.io/OskarsMC-Plugins/message) 28 | and [GitHub](https://github.com/OskarsMC-Plugins/message). -------------------------------------------------------------------------------- /docs/TECHNICAL.md: -------------------------------------------------------------------------------- 1 | # Technical Details: 2 | 3 | * [Index](INDEX.md) 4 | * [Technical Details](#technical-details-) 5 | * [Java](#java) 6 | * [API](#api) 7 | * [API Inclusion](#including-) 8 | * [Usage](#usage-) 9 | * [JavaDocs](#javadocs) 10 | * [Code Example](#example) 11 | 12 | ## Java 13 | 14 | Recommended Version: 17 15 | 16 | Tested Versions: 16, 17 17 | 18 | ## API 19 | 20 | Do not shade message into your plugin. It will always be present in its plugin form at runtime. 21 | 22 | ### Including: 23 | 24 |
25 | Maven 26 | 27 | ```xml 28 | 29 | 30 | oskarsmc-repo 31 | https://repository.oskarsmc.com/releases 32 | 33 | ``` 34 | 35 | ```xml 36 | 37 | 38 | com.oskarsmc 39 | message 40 | 1.2.0 41 | 42 | ``` 43 | 44 |
45 | 46 |
47 | Gradle Kotlin DSL 48 | 49 | ```kotlin 50 | maven("https://repository.oskarsmc.com/releases") 51 | ``` 52 | 53 | ```kotlin 54 | implementation("com.oskarsmc:message:1.2.0") 55 | ``` 56 | 57 |
58 | 59 | ### Usage: 60 | 61 | #### JavaDocs 62 | 63 | Javadocs are not published anywhere yet. A javadoc jar is published alongside each artifact. 64 | 65 | #### Example 66 | 67 | ```java 68 | import com.google.inject.Inject; 69 | import com.oskarsmc.message.event.MessageEvent; 70 | import com.oskarsmc.message.event.StringResult; 71 | import com.velocitypowered.api.event.Subscribe; 72 | import com.velocitypowered.api.plugin.Plugin; 73 | import org.jetbrains.annotations.NotNull; 74 | 75 | @Plugin( 76 | id = "testvelocityplugin", 77 | name = "TestVelocityPlugin", 78 | version = "1.0.0" 79 | ) 80 | public class TestVelocityPlugin { 81 | @Subscribe 82 | private void MessageEvent(@NotNull MessageEvent event) { 83 | if (event.originalMessage().contains("poop")) { // Check if message contains a very naughty word. 84 | event.setResult(StringResult.denied()); // Don't send naughty words to people. 85 | } 86 | } 87 | } 88 | ``` -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OskarsMC-Plugins/message/c7747e3b67cda4f00dd2181044cf0a67c621d637/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-8.0.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 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "message" 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/Message.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message; 2 | 3 | import cloud.commandframework.execution.CommandExecutionCoordinator; 4 | import cloud.commandframework.velocity.CloudInjectionModule; 5 | import cloud.commandframework.velocity.VelocityCommandManager; 6 | import com.google.inject.Inject; 7 | import com.google.inject.Injector; 8 | import com.google.inject.Key; 9 | import com.google.inject.TypeLiteral; 10 | import com.oskarsmc.message.command.MessageCommand; 11 | import com.oskarsmc.message.command.ReplyCommand; 12 | import com.oskarsmc.message.command.SocialSpyCommand; 13 | import com.oskarsmc.message.configuration.MessageSettings; 14 | import com.oskarsmc.message.locale.CommandExceptionHandler; 15 | import com.oskarsmc.message.locale.TranslationManager; 16 | import com.oskarsmc.message.logic.MessageMetrics; 17 | import com.oskarsmc.message.util.CloudSuggestionProcessor; 18 | import com.oskarsmc.message.util.DependencyChecker; 19 | import com.oskarsmc.message.util.MessageModule; 20 | import com.velocitypowered.api.command.CommandSource; 21 | import com.velocitypowered.api.event.Subscribe; 22 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 23 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 24 | import net.luckperms.api.LuckPermsProvider; 25 | import org.jetbrains.annotations.NotNull; 26 | import org.slf4j.Logger; 27 | 28 | import java.nio.file.Path; 29 | import java.util.function.Function; 30 | 31 | /** 32 | * The main class for the message plugin. 33 | */ 34 | public final class Message { 35 | @Inject 36 | private Injector injector; 37 | 38 | @Inject 39 | private Logger logger; 40 | 41 | @Inject 42 | private @DataDirectory 43 | @NotNull Path dataFolder; 44 | 45 | /** 46 | * Initialise the plugin. 47 | * 48 | * @param event Proxy Initialise Event 49 | */ 50 | @Subscribe 51 | public void onProxyInitialization(ProxyInitializeEvent event) { 52 | MessageSettings messageSettings = new MessageSettings(dataFolder, logger); 53 | 54 | injector = injector.createChildInjector( 55 | new CloudInjectionModule<>( 56 | CommandSource.class, 57 | CommandExecutionCoordinator.simpleCoordinator(), 58 | Function.identity(), 59 | Function.identity() 60 | ), 61 | new MessageModule(messageSettings) 62 | ); 63 | 64 | if (messageSettings.enabled()) { 65 | injector.getInstance(TranslationManager.class); 66 | 67 | if (messageSettings.luckpermsIntegration()) { 68 | if (DependencyChecker.luckperms()) { 69 | logger.info("LuckPerms integration enabled. Targeted LuckPerms version 5.4, using {}", LuckPermsProvider.get().getPluginMetadata().getVersion()); 70 | } else { 71 | logger.warn("LuckPerms integration was enabled but LuckPerms was not detected on the proxy. Continuing without it."); 72 | messageSettings.luckpermsIntegration(false); 73 | } 74 | } 75 | 76 | if (messageSettings.miniPlaceholdersIntegration()) { 77 | if (DependencyChecker.miniplaceholders()) { 78 | logger.info("MiniPlaceholders integration enabled."); 79 | } else { 80 | logger.warn("MiniPlaceholders integration was enabled but MiniPlaceholders was not detected on the proxy. Continuing without it."); 81 | messageSettings.miniPlaceholdersIntegration(false); 82 | } 83 | } 84 | 85 | // Register custom exception handlers 86 | injector.getInstance(CommandExceptionHandler.class); 87 | 88 | // Allow autocompletion regardless of capitalisation 89 | injector.getInstance(Key.get(new TypeLiteral>() { 90 | })).commandSuggestionProcessor(new CloudSuggestionProcessor()); 91 | 92 | // Commands 93 | injector.getInstance(MessageCommand.class); 94 | injector.getInstance(SocialSpyCommand.class); 95 | injector.getInstance(ReplyCommand.class); 96 | 97 | // Metrics 98 | injector.getInstance(MessageMetrics.class); 99 | } 100 | 101 | logger.info("Loaded message {}", getClass().getPackage().getImplementationVersion()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/command/MessageCommand.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.command; 2 | 3 | import cloud.commandframework.Command; 4 | import cloud.commandframework.arguments.standard.StringArgument; 5 | import cloud.commandframework.minecraft.extras.RichDescription; 6 | import cloud.commandframework.velocity.VelocityCommandManager; 7 | import cloud.commandframework.velocity.arguments.PlayerArgument; 8 | import com.google.inject.Inject; 9 | import com.oskarsmc.message.configuration.MessageSettings; 10 | import com.oskarsmc.message.event.MessageEvent; 11 | import com.oskarsmc.message.logic.MessageHandler; 12 | import com.oskarsmc.message.util.DefaultPermission; 13 | import com.velocitypowered.api.command.CommandSource; 14 | import com.velocitypowered.api.proxy.Player; 15 | import com.velocitypowered.api.proxy.ProxyServer; 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | /** 19 | * The message command class. 20 | */ 21 | public final class MessageCommand { 22 | /** 23 | * Construct the message command. 24 | * @param messageSettings Message Settings 25 | * @param commandManager Command Manager 26 | * @param proxyServer Proxy Server 27 | * @param messageHandler Message Handler 28 | */ 29 | @Inject 30 | public MessageCommand(@NotNull MessageSettings messageSettings, @NotNull VelocityCommandManager commandManager, ProxyServer proxyServer, MessageHandler messageHandler) { 31 | Command.Builder builder = commandManager.commandBuilder("message", messageSettings.messageAliases().toArray(new String[0])); 32 | 33 | commandManager.command(builder 34 | .argument(PlayerArgument.of("player"), RichDescription.translatable("oskarsmc.message.command.message.argument.player-argument")) 35 | .argument(StringArgument.of("message", StringArgument.StringMode.GREEDY), RichDescription.translatable("oskarsmc.message.command.common.argument.message-description")) 36 | .permission(new DefaultPermission("osmc.message.send")) 37 | .handler(context -> { 38 | Player receiver = context.get("player"); 39 | 40 | proxyServer.getEventManager().fire(new MessageEvent( 41 | context.getSender(), 42 | receiver, 43 | context.get("message") 44 | )).thenAccept(messageHandler::handleMessageEvent); 45 | }) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/command/ReplyCommand.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.command; 2 | 3 | import cloud.commandframework.Command; 4 | import cloud.commandframework.arguments.standard.StringArgument; 5 | import cloud.commandframework.minecraft.extras.RichDescription; 6 | import cloud.commandframework.velocity.VelocityCommandManager; 7 | import com.google.inject.Inject; 8 | import com.oskarsmc.message.configuration.MessageSettings; 9 | import com.oskarsmc.message.event.MessageEvent; 10 | import com.oskarsmc.message.logic.MessageHandler; 11 | import com.oskarsmc.message.util.DefaultPermission; 12 | import com.velocitypowered.api.command.CommandSource; 13 | import com.velocitypowered.api.proxy.Player; 14 | import com.velocitypowered.api.proxy.ProxyServer; 15 | import org.jetbrains.annotations.NotNull; 16 | 17 | import java.util.Map; 18 | 19 | /** 20 | * Reply Command 21 | */ 22 | public final class ReplyCommand { 23 | /** 24 | * Construct the reply command 25 | * @param messageSettings Message Settings 26 | * @param commandManager Command Manager 27 | * @param proxyServer Proxy Server 28 | * @param messageHandler Message Handler. 29 | */ 30 | @Inject 31 | public ReplyCommand(@NotNull MessageSettings messageSettings, @NotNull VelocityCommandManager commandManager, ProxyServer proxyServer, MessageHandler messageHandler) { 32 | Command.Builder builder = commandManager.commandBuilder("reply", messageSettings.replyAliases().toArray(new String[0])); 33 | 34 | commandManager.command(builder 35 | .senderType(Player.class) 36 | .permission(new DefaultPermission("osmc.message.reply")) 37 | .argument(StringArgument.of("message", StringArgument.StringMode.GREEDY), RichDescription.translatable("oskarsmc.message.command.common.argument.message-description")) 38 | .handler(context -> { 39 | Map conversations = messageHandler.conversations(); 40 | 41 | Player receiver = conversations.get(((Player) context.getSender())); 42 | 43 | proxyServer.getEventManager().fire(new MessageEvent( 44 | context.getSender(), 45 | receiver, 46 | context.get("message") 47 | )).thenAccept(messageHandler::handleMessageEvent); 48 | }) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/command/SocialSpyCommand.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.command; 2 | 3 | import cloud.commandframework.Command; 4 | import cloud.commandframework.velocity.VelocityCommandManager; 5 | import com.google.inject.Inject; 6 | import com.oskarsmc.message.configuration.MessageSettings; 7 | import com.oskarsmc.message.logic.MessageHandler; 8 | import com.velocitypowered.api.command.CommandSource; 9 | import net.kyori.adventure.text.Component; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | /** 13 | * Social Spy command 14 | */ 15 | public final class SocialSpyCommand { 16 | @Inject 17 | private MessageHandler messageHandler; 18 | 19 | /** 20 | * Construct the social spy command. 21 | * 22 | * @param messageSettings Message Settings 23 | * @param commandManager Command Manager 24 | */ 25 | @Inject 26 | public SocialSpyCommand(@NotNull MessageSettings messageSettings, @NotNull VelocityCommandManager commandManager) { 27 | Command.Builder builder = commandManager.commandBuilder("socialspy", messageSettings.socialSpyAliases().toArray(new String[0])).permission("osmc.message.socialspy"); 28 | 29 | commandManager.command(builder 30 | .literal("on") 31 | .handler(context -> addWatcher(context.getSender())) 32 | ); 33 | 34 | commandManager.command(builder 35 | .literal("off") 36 | .handler(context -> removeWatcher(context.getSender())) 37 | ); 38 | 39 | commandManager.command(builder 40 | .literal("toggle") 41 | .handler(context -> { 42 | if (messageHandler.conversationWatchers.contains(context.getSender())) { 43 | removeWatcher(context.getSender()); 44 | } else { 45 | addWatcher(context.getSender()); 46 | } 47 | }) 48 | ); 49 | } 50 | 51 | private void addWatcher(CommandSource source) { 52 | if (!messageHandler.conversationWatchers.contains(source)) { 53 | messageHandler.conversationWatchers.add(source); 54 | } 55 | source.sendMessage(Component.translatable("oskarsmc.message.command.socialspy.on")); 56 | } 57 | 58 | private void removeWatcher(CommandSource source) { 59 | messageHandler.conversationWatchers.remove(source); 60 | source.sendMessage(Component.translatable("oskarsmc.message.command.socialspy.off")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/configuration/MessageSettings.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.configuration; 2 | 3 | import com.google.inject.Inject; 4 | import com.moandjiezana.toml.Toml; 5 | import com.oskarsmc.message.util.VersionUtils; 6 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 7 | import org.checkerframework.dataflow.qual.Pure; 8 | import org.jetbrains.annotations.Contract; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.UnmodifiableView; 11 | import org.slf4j.Logger; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.util.Collections; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * The settings container class for the message plugin. 24 | */ 25 | public final class MessageSettings { 26 | private final Path dataFolder; 27 | private final Path file; 28 | 29 | private String messageSentMiniMessage; 30 | private String messageReceivedMiniMessage; 31 | private String messageSocialSpyMiniMessage; 32 | 33 | private HashMap, String> customErrorHandlers; 34 | 35 | private List messageAlias; 36 | private List replyAlias; 37 | private List socialSpyAlias; 38 | 39 | private boolean luckpermsIntegration; 40 | private boolean miniPlaceholdersIntegration; 41 | private boolean selfMessageSending; 42 | 43 | private final double configVersion; 44 | private boolean enabled; 45 | 46 | /** 47 | * Construct message settings. 48 | * 49 | * @param dataFolder Data Folder 50 | * @param logger Logger 51 | */ 52 | @Inject 53 | public MessageSettings(@DataDirectory @NotNull Path dataFolder, Logger logger) { 54 | this.dataFolder = dataFolder; 55 | this.file = this.dataFolder.resolve("config.toml"); 56 | 57 | saveDefaultConfig(); 58 | Toml toml = loadConfig(); 59 | 60 | this.enabled = toml.getBoolean("plugin.enabled"); 61 | 62 | // Version 63 | this.configVersion = toml.getDouble("developer-info.config-version"); 64 | 65 | if (!VersionUtils.isLatestConfigVersion(this)) { 66 | logger.warn("Your Config is out of date (Latest: {}, Config Version: {})!", VersionUtils.CONFIG_VERSION, this.configVersion()); 67 | logger.warn("Please backup your current config.toml, and delete the current one. A new config will then be created on the next proxy launch."); 68 | logger.warn("The plugin's functionality will not be enabled until the config is updated."); 69 | this.enabled(false); 70 | return; 71 | } 72 | 73 | // Plugin Features 74 | this.luckpermsIntegration = toml.getBoolean("plugin.luckperms-integration"); 75 | this.selfMessageSending = toml.getBoolean("plugin.allow-self-message-sending"); 76 | this.miniPlaceholdersIntegration = toml.getBoolean("plugin.miniplaceholders-integration"); 77 | 78 | // Messages - Message 79 | this.messageSentMiniMessage = toml.getString("messages.message-sent"); 80 | this.messageReceivedMiniMessage = toml.getString("messages.message-received"); 81 | this.messageSocialSpyMiniMessage = toml.getString("messages.message-socialspy"); 82 | 83 | // Aliases 84 | this.messageAlias = toml.getList("aliases.message"); 85 | this.replyAlias = toml.getList("aliases.reply"); 86 | this.socialSpyAlias = toml.getList("aliases.socialspy"); 87 | 88 | // Exceptions 89 | this.customErrorHandlers = new HashMap<>(); 90 | Toml handlers = toml.getTable("error-handlers"); 91 | for (Map.Entry entry : handlers.entrySet()) { 92 | // TODO: Fix this jankyness, but works for now 93 | String classPath = entry.getKey().replace("\"", ""); 94 | // classPath = classPath.replace("cloud.commandframework", "com.oskarsmc.message.relocated.cloud"); // cant do this because the string gets relocated 95 | if (classPath.startsWith("loud.commandframework", 1)) { // TODO: make this less janky 96 | classPath = "com.oskarsmc.message.relocated.cloud" + classPath.substring(22); 97 | } 98 | 99 | try { 100 | @SuppressWarnings("unchecked") 101 | Class exceptionClass = (Class) Class.forName(classPath); 102 | 103 | this.customErrorHandlers.put(exceptionClass, entry.getValue().toString()); 104 | } catch (ClassCastException e) { 105 | logger.error("Class \"{}\" is not of type exception!", classPath); 106 | e.printStackTrace(); 107 | } catch (ClassNotFoundException e) { 108 | logger.error("Could not find class \"{}\" as defined in custom exception handlers.", classPath); 109 | } 110 | } 111 | } 112 | 113 | private void saveDefaultConfig() { 114 | if (!Files.exists(dataFolder)) { 115 | try { 116 | Files.createDirectory(dataFolder); 117 | } catch (IOException e) { 118 | throw new RuntimeException(e); 119 | } 120 | } 121 | 122 | if (!Files.exists(file)) { 123 | try (InputStream in = MessageSettings.class.getResourceAsStream("/config.toml")) { 124 | assert in != null; 125 | Files.copy(in, file); 126 | } catch (IOException e) { 127 | throw new RuntimeException(e); 128 | } 129 | } 130 | } 131 | 132 | private @NotNull Path configFile() { 133 | return this.file; 134 | } 135 | 136 | private Toml loadConfig() { 137 | try { 138 | return new Toml().read(Files.newInputStream(this.file)); 139 | } catch (IOException e) { 140 | throw new RuntimeException(e); 141 | } 142 | 143 | } 144 | 145 | /** 146 | * Get the MiniMessage markup of the senders sent message. 147 | * 148 | * @return The MiniMessage markup of the senders sent message. 149 | */ 150 | public String messageSentMiniMessage() { 151 | return this.messageSentMiniMessage; 152 | } 153 | 154 | /** 155 | * Get the MiniMessage markup of the recipients received message. 156 | * 157 | * @return The MiniMessage markup of the recipients received message. 158 | */ 159 | public String messageReceivedMiniMessage() { 160 | return this.messageReceivedMiniMessage; 161 | } 162 | 163 | /** 164 | * Get if the plugin is enabled. 165 | * 166 | * @return If the plugin is enabled. 167 | */ 168 | @Pure 169 | public boolean enabled() { 170 | return this.enabled; 171 | } 172 | 173 | /** 174 | * Set if the plugin is enabled. 175 | * 176 | * @param enabled If the plugin is enabled. 177 | */ 178 | public void enabled(boolean enabled) { 179 | this.enabled = enabled; 180 | } 181 | 182 | /** 183 | * Get luckperms integration. 184 | * 185 | * @return Luckperms integration. 186 | */ 187 | @Pure 188 | public boolean luckpermsIntegration() { 189 | return this.luckpermsIntegration; 190 | } 191 | 192 | /** 193 | * Set luckperms integration. 194 | * 195 | * @param luckpermsIntegration Luckperms integration 196 | */ 197 | public void luckpermsIntegration(boolean luckpermsIntegration) { 198 | this.luckpermsIntegration = luckpermsIntegration; 199 | } 200 | 201 | /** 202 | * Get miniplaceholders integration. 203 | * 204 | * @return MiniPlaceholders integration. 205 | */ 206 | @Pure 207 | public boolean miniPlaceholdersIntegration() { 208 | return this.miniPlaceholdersIntegration; 209 | } 210 | 211 | /** 212 | * Set miniplaceholders integration. 213 | * 214 | * @param miniPlaceholdersIntegration MiniPlaceholders integration 215 | */ 216 | public void miniPlaceholdersIntegration(boolean miniPlaceholdersIntegration) { 217 | this.miniPlaceholdersIntegration = miniPlaceholdersIntegration; 218 | } 219 | 220 | /** 221 | * Get if the config allows players sending messages to themselves. 222 | * 223 | * @return If the config allows players sending messages to themselves. 224 | */ 225 | @Pure 226 | public boolean selfMessageSending() { 227 | return selfMessageSending; 228 | } 229 | 230 | /** 231 | * Get the configuration version. 232 | * 233 | * @return The configuration version. 234 | */ 235 | @Pure 236 | public Double configVersion() { 237 | return configVersion; 238 | } 239 | 240 | /** 241 | * Get the MiniMessage markup of the socialspy message. 242 | * 243 | * @return The MiniMessage markup of the socialspy message. 244 | */ 245 | @Pure 246 | public String messageSocialSpyMiniMessage() { 247 | return messageSocialSpyMiniMessage; 248 | } 249 | 250 | /** 251 | * Get the aliases of the message command. 252 | * 253 | * @return The aliases of the message command. 254 | */ 255 | @Pure 256 | public List messageAliases() { 257 | return messageAlias; 258 | } 259 | 260 | /** 261 | * Get the aliases of the socialspy command. 262 | * 263 | * @return The aliases of the socialspy command. 264 | */ 265 | @Pure 266 | public List socialSpyAliases() { 267 | return socialSpyAlias; 268 | } 269 | 270 | /** 271 | * Get the aliases of the reply command. 272 | * 273 | * @return The aliases of the reply command. 274 | */ 275 | @Pure 276 | public List replyAliases() { 277 | return replyAlias; 278 | } 279 | 280 | /** 281 | * Get all defined custom error handlers 282 | * 283 | * @return a map of all defined error handlers 284 | */ 285 | @Contract(pure = true) 286 | public @NotNull @UnmodifiableView Map, String> getCustomErrorHandlers() { 287 | return Collections.unmodifiableMap(customErrorHandlers); 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/event/MessageEvent.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.event; 2 | 3 | import com.velocitypowered.api.command.CommandSource; 4 | import com.velocitypowered.api.event.ResultedEvent; 5 | import com.velocitypowered.api.proxy.Player; 6 | import net.kyori.adventure.text.Component; 7 | import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; 8 | import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 9 | 10 | import java.util.Objects; 11 | 12 | /** 13 | * The event that is fired when a message is sent. 14 | */ 15 | @SuppressWarnings("unused") 16 | public class MessageEvent implements ResultedEvent { 17 | private final CommandSource sender; 18 | private final Player recipient; 19 | private final String originalMessage; 20 | private final TagResolver.Builder extraPlaceholders; 21 | private StringResult result = StringResult.allowed(); 22 | 23 | /** 24 | * Construct the message event. 25 | * 26 | * @param sender The message sender. Can be console. 27 | * @param recipient The message recipient. 28 | * @param message The message. 29 | */ 30 | public MessageEvent(CommandSource sender, Player recipient, String message) { 31 | this.sender = sender; 32 | this.recipient = recipient; 33 | this.originalMessage = message; 34 | this.extraPlaceholders = TagResolver.builder(); 35 | this.result = StringResult.message(message); 36 | } 37 | 38 | /** 39 | * The sender of the message. 40 | * 41 | * @return The sender of the message. 42 | */ 43 | public CommandSource sender() { 44 | return sender; 45 | } 46 | 47 | /** 48 | * The recipient (receiver) of the message. 49 | * 50 | * @return The recipient (receiver) of the message. 51 | */ 52 | public Player recipient() { 53 | return recipient; 54 | } 55 | 56 | /** 57 | * Get the original contents of the message. 58 | * 59 | * @return The contents of the message. 60 | */ 61 | public String originalMessage() { 62 | return originalMessage; 63 | } 64 | 65 | /** 66 | * Add an extra placeholder. 67 | * 68 | * @param key The MiniMessage key. 69 | * @param value The Component to replace the placeholder with. 70 | */ 71 | public void extraPlaceholder(String key, Component value) { 72 | this.extraPlaceholder(Placeholder.component(key, value)); 73 | } 74 | 75 | /** 76 | * Add an extra placeholder. 77 | * 78 | * @param resolver The resolver to add. 79 | */ 80 | public void extraPlaceholder(TagResolver resolver) { 81 | extraPlaceholders.resolver(resolver); 82 | } 83 | 84 | /** 85 | * Get the extra placeholders. 86 | * 87 | * @return The extra placeholders. 88 | */ 89 | public TagResolver extraPlaceholders() { 90 | return extraPlaceholders.build(); 91 | } 92 | 93 | @Override 94 | public StringResult getResult() { 95 | return this.result; 96 | } 97 | 98 | @Override 99 | public void setResult(StringResult result) { 100 | this.result = Objects.requireNonNull(result); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/event/StringResult.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.event; 2 | 3 | import java.util.Objects; 4 | 5 | import org.jetbrains.annotations.Contract; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import com.velocitypowered.api.event.ResultedEvent; 10 | 11 | /** 12 | * StringResult class, used for the result of sent messages. 13 | */ 14 | public class StringResult implements ResultedEvent.Result { 15 | private static final StringResult ALLOWED = new StringResult(true, null); 16 | private static final StringResult DENIED = new StringResult(false, null); 17 | 18 | private final boolean status; 19 | private final String string; 20 | 21 | private StringResult(boolean b, String string) { 22 | this.status = b; 23 | this.string = string; 24 | } 25 | 26 | @Override 27 | public boolean isAllowed() { 28 | return this.status; 29 | } 30 | 31 | /** 32 | * String content of the {@link StringResult} 33 | * 34 | * @return String content of the {@link StringResult} 35 | */ 36 | public @Nullable String string() { 37 | return this.string; 38 | } 39 | 40 | /** 41 | * Generic Allowed {@link StringResult} 42 | * 43 | * @return Generic Allowed {@link StringResult} 44 | */ 45 | public static StringResult allowed() { 46 | return ALLOWED; 47 | } 48 | 49 | /** 50 | * Generic Denied {@link StringResult} 51 | * 52 | * @return Generic Denied {@link StringResult} 53 | */ 54 | public static StringResult denied() { 55 | return DENIED; 56 | } 57 | 58 | /** 59 | * Create a new {@link StringResult} object. 60 | * 61 | * @param message The message to set 62 | * @return The newly instantiated {@link StringResult} object. 63 | */ 64 | @Contract("_ -> new") 65 | public static @NotNull StringResult message(String message) { 66 | return new StringResult(true, Objects.requireNonNull(message)); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/locale/CommandExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.locale; 2 | 3 | import cloud.commandframework.velocity.VelocityCommandManager; 4 | import com.google.inject.Inject; 5 | import com.oskarsmc.message.configuration.MessageSettings; 6 | import com.velocitypowered.api.command.CommandSource; 7 | import net.kyori.adventure.text.minimessage.MiniMessage; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.slf4j.Logger; 10 | 11 | import java.util.Map; 12 | 13 | /** 14 | * The command exception handler for handling custom exceptions 15 | */ 16 | public class CommandExceptionHandler { 17 | /** 18 | * Construct the command exception handler 19 | * 20 | * @param settings message settings 21 | * @param commandManager velocity command manager 22 | * @param logger logger 23 | */ 24 | @Inject 25 | public CommandExceptionHandler(@NotNull MessageSettings settings, @NotNull VelocityCommandManager commandManager, @NotNull Logger logger) { 26 | MiniMessage miniMessage = MiniMessage.miniMessage(); 27 | for (Map.Entry, String> entry : settings.getCustomErrorHandlers().entrySet()) { 28 | commandManager.registerExceptionHandler(entry.getKey(), (commandSource, e) -> commandSource.sendMessage(miniMessage.deserialize(entry.getValue()))); 29 | } 30 | 31 | int exceptionHandlerAmount = settings.getCustomErrorHandlers().size(); 32 | if (exceptionHandlerAmount > 0) { 33 | logger.info("Loaded {} custom exception handlers", settings.getCustomErrorHandlers().size()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/locale/TranslationFile.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.locale; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * A Translation file. 10 | */ 11 | public final class TranslationFile { 12 | @SerializedName("translation-version") 13 | private String translationVersion; 14 | 15 | @SerializedName("translations") 16 | private List translations; 17 | 18 | /** 19 | * Get the version of the translation file. 20 | * 21 | * @return The version of the translation file. 22 | */ 23 | public String translationVersion() { 24 | return translationVersion; 25 | } 26 | 27 | /** 28 | * All the translations in the translation file. 29 | * 30 | * @return The translations in the translation file. 31 | */ 32 | public List translations() { 33 | return translations; 34 | } 35 | 36 | /** 37 | * Translations for a language. 38 | */ 39 | public final static class LocaleTranslation { 40 | @SerializedName("language-tag") 41 | private String languageTag; 42 | 43 | @SerializedName("translations") 44 | private Map translations; 45 | 46 | /** 47 | * Get the language tag of the translation. 48 | * 49 | * @return The language tag of the translation. 50 | */ 51 | public String languageTag() { 52 | return languageTag; 53 | } 54 | 55 | /** 56 | * Get all translations in the {@link LocaleTranslation}. 57 | * 58 | * @return All translations in the {@link LocaleTranslation}. 59 | */ 60 | public Map translations() { 61 | return translations; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/locale/TranslationManager.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.locale; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonParseException; 5 | import com.google.inject.Inject; 6 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 7 | import net.kyori.adventure.key.Key; 8 | import net.kyori.adventure.translation.GlobalTranslator; 9 | import net.kyori.adventure.translation.TranslationRegistry; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | import org.slf4j.Logger; 13 | 14 | import java.io.IOException; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.text.MessageFormat; 18 | import java.util.Locale; 19 | import java.util.Map; 20 | import java.util.Objects; 21 | 22 | /** 23 | * The translation manager in charge of registering translations. 24 | */ 25 | public final class TranslationManager { 26 | @Inject 27 | private Logger logger; 28 | 29 | /** 30 | * Construct the translation manager 31 | * 32 | * @param logger logger 33 | * @param dataDirectory plugin data directory 34 | */ 35 | @Inject 36 | public TranslationManager(@NotNull Logger logger, @DataDirectory @NotNull Path dataDirectory) { 37 | this.logger = logger; 38 | logger.info("Loading Translations"); 39 | TranslationRegistry translationRegistry = TranslationRegistry.create(Key.key("oskarsmc", "message")); 40 | translationRegistry.defaultLocale(Locale.ENGLISH); 41 | 42 | TranslationFile translationFile = readTranslationFile(dataDirectory.resolve("translations/")); 43 | if (translationFile != null) { 44 | for (TranslationFile.LocaleTranslation localeTranslation : translationFile.translations()) { 45 | Locale locale = Locale.forLanguageTag(localeTranslation.languageTag()); 46 | for (Map.Entry entry : localeTranslation.translations().entrySet()) { 47 | translationRegistry.register(entry.getKey(), locale, new MessageFormat(entry.getValue().replace("'", "''"))); 48 | } 49 | } 50 | logger.info("Loaded {} translations.", translationFile.translations().size()); 51 | } else { 52 | logger.error("Could not find a translations file. Continuing without translations."); 53 | } 54 | 55 | GlobalTranslator.translator().addSource(translationRegistry); 56 | } 57 | 58 | /** 59 | * Reads the translation file and maps it to an {@link TranslationFile} instance. 60 | * 61 | * @param translationsDirectory directory to store translations 62 | * @return The mapped {@link TranslationFile} instance. 63 | */ 64 | public @Nullable TranslationFile readTranslationFile(@NotNull Path translationsDirectory) { 65 | Gson gson = new Gson(); 66 | String version = TranslationManager.class.getPackage().getImplementationVersion(); 67 | Path currentTranslationFile = translationsDirectory.resolve("translations-" + version + ".json"); 68 | Path relativeCurrentTranslationFile = Path.of(".").relativize(currentTranslationFile); 69 | 70 | try { 71 | if (!Files.exists(translationsDirectory)) Files.createDirectory(translationsDirectory); 72 | 73 | if (Files.exists(currentTranslationFile)) { 74 | TranslationFile definedTranslationFile = gson.fromJson(Files.readString(currentTranslationFile), TranslationFile.class); 75 | if (!Objects.equals(definedTranslationFile.translationVersion(), version)) { 76 | logger.warn("The custom translation file located at {} is outdated (expected {}, got {}).", 77 | relativeCurrentTranslationFile, version, definedTranslationFile.translationVersion()); 78 | } 79 | return definedTranslationFile; 80 | } else { 81 | Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/translations.json")), currentTranslationFile); 82 | logger.info("Creating translation file {}...", relativeCurrentTranslationFile); 83 | return readTranslationFile(translationsDirectory); 84 | } 85 | } catch (IOException | JsonParseException exception) { 86 | exception.printStackTrace(); 87 | logger.error("Could not read, parse, or write to {}", relativeCurrentTranslationFile); 88 | return null; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/logic/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.logic; 2 | 3 | import com.oskarsmc.message.configuration.MessageSettings; 4 | import com.oskarsmc.message.event.MessageEvent; 5 | import com.velocitypowered.api.command.CommandSource; 6 | import com.velocitypowered.api.proxy.Player; 7 | import io.github.miniplaceholders.api.MiniPlaceholders; 8 | import net.kyori.adventure.text.Component; 9 | import net.kyori.adventure.text.format.NamedTextColor; 10 | import net.kyori.adventure.text.minimessage.MiniMessage; 11 | import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; 12 | import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 13 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 14 | import net.luckperms.api.LuckPerms; 15 | import net.luckperms.api.LuckPermsProvider; 16 | import net.luckperms.api.cacheddata.CachedMetaData; 17 | import net.luckperms.api.platform.PlayerAdapter; 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.UnmodifiableView; 20 | 21 | import java.util.*; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | /** 25 | * The handler that handles all messages sent via the plugin. 26 | */ 27 | public final class MessageHandler { 28 | private final MessageSettings messageSettings; 29 | private final MiniMessage miniMessage = MiniMessage.miniMessage(); 30 | private final ConcurrentHashMap conversations = new ConcurrentHashMap<>(); 31 | /** 32 | * Conversation Watchers 33 | */ 34 | public final List conversationWatchers = Collections.synchronizedList(new ArrayList<>()); 35 | 36 | /** 37 | * Construct the Message Handler. 38 | * 39 | * @param messageSettings Message Settings 40 | */ 41 | public MessageHandler(MessageSettings messageSettings) { 42 | this.messageSettings = messageSettings; 43 | } 44 | 45 | /** 46 | * Handle the message event once it's been fired. 47 | * 48 | * @param event The Message Event instance. 49 | */ 50 | public void handleMessageEvent(@NotNull MessageEvent event) { 51 | if (!messageSettings.selfMessageSending() && event.sender() == event.recipient()) { 52 | event.sender().sendMessage(Component.translatable("oskarsmc.message.command.common.self-sending-error", NamedTextColor.RED)); 53 | return; 54 | } 55 | 56 | if (!event.getResult().isAllowed()) { 57 | return; 58 | } 59 | 60 | Component senderName = event.sender() instanceof Player player ? Component.text(player.getUsername()) : Component.text("UNKNOWN"); 61 | Component receiverName = Component.text(event.recipient().getUsername()); 62 | 63 | String senderServer = event.sender() instanceof Player player 64 | ? player.getCurrentServer().map(sv -> sv.getServerInfo().getName()).orElse("UNKNOWN") 65 | : "UNKNOWN"; 66 | String receiverServer = event.recipient().getCurrentServer() 67 | .map(sv -> sv.getServerInfo().getName()).orElse("UNKNOWN"); 68 | 69 | TagResolver.Builder builder = TagResolver.builder() 70 | .resolver(Placeholder.component("sender", senderName)) 71 | .resolver(Placeholder.component("receiver", receiverName)) 72 | .resolver(Placeholder.unparsed("sender_server", senderServer)) 73 | .resolver(Placeholder.unparsed("receiver_server", receiverServer)) 74 | .resolver(Placeholder.unparsed("message", event.getResult().string() != null 75 | ? Objects.requireNonNull(event.getResult().string()) 76 | : event.originalMessage())); 77 | 78 | if (messageSettings.luckpermsIntegration()) { 79 | LuckPerms luckPerms = LuckPermsProvider.get(); 80 | 81 | PlayerAdapter playerAdapter = luckPerms.getPlayerAdapter(Player.class); 82 | 83 | CachedMetaData senderMetaData = event.sender() instanceof Player player 84 | ? playerAdapter.getUser(player).getCachedData().getMetaData() 85 | : null; 86 | 87 | CachedMetaData recipientMetaData = playerAdapter.getUser(event.recipient()).getCachedData().getMetaData(); 88 | 89 | builder.resolver(craftLuckpermsPlaceholders("sender", senderMetaData)) 90 | .resolver(craftLuckpermsPlaceholders("receiver", recipientMetaData)); 91 | } else { 92 | builder.resolver(craftPlaceholders()); 93 | } 94 | 95 | if (messageSettings.miniPlaceholdersIntegration()) { 96 | builder.resolver(MiniPlaceholders.getRelationalGlobalPlaceholders(event.sender(), event.recipient())); 97 | } 98 | 99 | TagResolver placeholders = builder.resolver(event.extraPlaceholders()).build(); 100 | 101 | Component senderMessage = miniMessage.deserialize(messageSettings.messageSentMiniMessage(), placeholders); 102 | Component receiverMessage = miniMessage.deserialize(messageSettings.messageReceivedMiniMessage(), placeholders); 103 | 104 | event.sender().sendMessage(senderMessage); 105 | event.recipient().sendMessage(receiverMessage); 106 | 107 | if (event.sender() instanceof Player player) { 108 | conversations.remove(event.recipient()); 109 | conversations.put(event.recipient(), player); 110 | } 111 | 112 | Component socialSpyComponent = miniMessage.deserialize(messageSettings.messageSocialSpyMiniMessage(), placeholders); 113 | for (CommandSource watcher : conversationWatchers) { 114 | watcher.sendMessage(socialSpyComponent); 115 | } 116 | } 117 | 118 | private @NotNull TagResolver craftLuckpermsPlaceholders(String role, CachedMetaData cachedMetaData) { 119 | return cachedMetaData == null 120 | ? TagResolver.resolver( 121 | Placeholder.component(role + "_prefix", Component.empty()), 122 | Placeholder.component(role + "_suffix", Component.empty()), 123 | Placeholder.component(role + "_group", Component.empty())) 124 | : TagResolver.resolver( 125 | Placeholder.component(role + "_prefix", LegacyComponentSerializer.legacyAmpersand().deserialize(Objects.requireNonNullElse(cachedMetaData.getPrefix(), ""))), 126 | Placeholder.component(role + "_suffix", LegacyComponentSerializer.legacyAmpersand().deserialize(Objects.requireNonNullElse(cachedMetaData.getSuffix(), ""))), 127 | Placeholder.component(role + "_group", Component.text(Objects.requireNonNullElse(cachedMetaData.getPrimaryGroup(), ""))) 128 | ); 129 | } 130 | 131 | private @NotNull TagResolver craftPlaceholders() { 132 | return TagResolver.resolver( 133 | Placeholder.component("sender_prefix", Component.empty()), 134 | Placeholder.component("sender_suffix", Component.empty()), 135 | Placeholder.component("sender_group", Component.empty()), 136 | Placeholder.component("receiver_prefix", Component.empty()), 137 | Placeholder.component("receiver_suffix", Component.empty()), 138 | Placeholder.component("receiver_group", Component.empty()) 139 | ); 140 | } 141 | 142 | /** 143 | * Get all current conversations. 144 | * 145 | * @return An unmodifiable map with all conversations. 146 | */ 147 | public @NotNull @UnmodifiableView Map conversations() { 148 | return Collections.unmodifiableMap(conversations); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/logic/MessageMetrics.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.logic; 2 | 3 | import com.google.inject.Inject; 4 | import com.oskarsmc.message.Message; 5 | import com.oskarsmc.message.event.MessageEvent; 6 | import com.oskarsmc.message.util.StatsUtils; 7 | import com.velocitypowered.api.event.Subscribe; 8 | import com.velocitypowered.api.proxy.ProxyServer; 9 | import org.bstats.charts.SingleLineChart; 10 | import org.bstats.velocity.Metrics; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.concurrent.atomic.AtomicInteger; 14 | 15 | /** 16 | * Metrics for message. 17 | */ 18 | public final class MessageMetrics { 19 | private final AtomicInteger messagesSent = new AtomicInteger(); 20 | 21 | /** 22 | * Initialise BStats Metrics 23 | * @param plugin Message Plugin 24 | * @param metricsFactory Metrics Factory 25 | * @param proxyServer Proxy Server 26 | */ 27 | @Inject 28 | public MessageMetrics(Message plugin, Metrics.@NotNull Factory metricsFactory, @NotNull ProxyServer proxyServer) { 29 | proxyServer.getEventManager().register(plugin, this); 30 | Metrics metrics = metricsFactory.make(plugin, StatsUtils.PLUGIN_ID); 31 | 32 | metrics.addCustomChart(new SingleLineChart("messages_sent", () -> { 33 | int ret = messagesSent.get(); 34 | messagesSent.set(0); 35 | return ret; 36 | })); 37 | } 38 | 39 | @Subscribe 40 | private void onMessageEvent(MessageEvent event) { 41 | messagesSent.incrementAndGet(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/CloudSuggestionProcessor.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | import cloud.commandframework.execution.CommandSuggestionProcessor; 4 | import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; 5 | import com.velocitypowered.api.command.CommandSource; 6 | import org.checkerframework.checker.nullness.qual.NonNull; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Lowercase Cloud Suggestion Processor 13 | */ 14 | public final class CloudSuggestionProcessor implements CommandSuggestionProcessor { 15 | 16 | @Override 17 | public @NonNull List apply(@NonNull CommandPreprocessingContext context, @NonNull List strings) { 18 | String currentInput; 19 | 20 | if (context.getInputQueue().isEmpty()) { 21 | currentInput = ""; 22 | } else { 23 | currentInput = context.getInputQueue().peek(); 24 | } 25 | 26 | currentInput = currentInput.toLowerCase(); 27 | ArrayList suggestions = new ArrayList<>(); 28 | 29 | for (String suggestion : strings) { 30 | if (suggestion.toLowerCase().startsWith(currentInput)) { 31 | suggestions.add(suggestion); 32 | } 33 | } 34 | 35 | return suggestions; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/DefaultPermission.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | import cloud.commandframework.permission.PredicatePermission; 4 | import com.velocitypowered.api.command.CommandSource; 5 | import com.velocitypowered.api.permission.Tristate; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | /** 9 | * Default permission PredicatePermission, as it's not present in CLOUD. 10 | */ 11 | public record DefaultPermission(String permission) implements PredicatePermission { 12 | @Override 13 | public boolean hasPermission(@NotNull CommandSource sender) { 14 | return sender.getPermissionValue(permission) != Tristate.FALSE; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/DependencyChecker.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | /** 4 | * Dependency Checker 5 | */ 6 | public final class DependencyChecker { 7 | /** 8 | * Check if the luckperms api is present in the classpath. 9 | * @return If the luckperms api is present in the classpath. 10 | */ 11 | public static boolean luckperms() { 12 | try { 13 | Class.forName("net.luckperms.api.LuckPerms"); 14 | return true; 15 | } catch (ClassNotFoundException exception) { 16 | return false; 17 | } 18 | } 19 | 20 | /** 21 | * Check if the miniplaceholders api is present in the classpath. 22 | * @return If the miniplaceholders api is present in the classpath. 23 | */ 24 | public static boolean miniplaceholders() { 25 | try { 26 | Class.forName("io.github.miniplaceholders.api.MiniPlaceholders"); 27 | return true; 28 | } catch (ClassNotFoundException exception) { 29 | return false; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/MessageModule.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Provides; 5 | import com.google.inject.Singleton; 6 | import com.oskarsmc.message.command.MessageCommand; 7 | import com.oskarsmc.message.command.ReplyCommand; 8 | import com.oskarsmc.message.command.SocialSpyCommand; 9 | import com.oskarsmc.message.configuration.MessageSettings; 10 | import com.oskarsmc.message.logic.MessageHandler; 11 | import com.oskarsmc.message.logic.MessageMetrics; 12 | import org.jetbrains.annotations.Contract; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | /** 16 | * The message guice module. 17 | */ 18 | public final class MessageModule extends AbstractModule { 19 | private final MessageSettings messageSettings; 20 | 21 | /** 22 | * Construct the message guice module 23 | * 24 | * @param messageSettings The message settings to use when providing other values. 25 | */ 26 | public MessageModule(MessageSettings messageSettings) { 27 | this.messageSettings = messageSettings; 28 | } 29 | 30 | @Override 31 | protected void configure() { 32 | bind(MessageSettings.class).toInstance(messageSettings); 33 | bind(MessageCommand.class).in(Singleton.class); 34 | bind(ReplyCommand.class).in(Singleton.class); 35 | bind(SocialSpyCommand.class).in(Singleton.class); 36 | bind(MessageMetrics.class).in(Singleton.class); 37 | } 38 | 39 | @Contract(" -> new") 40 | @Singleton 41 | @Provides 42 | private @NotNull MessageHandler provideHandler() { 43 | return new MessageHandler(messageSettings); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/StatsUtils.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | /** 4 | * Utilites relating to statistics. 5 | */ 6 | public final class StatsUtils { 7 | /** 8 | * The BStats plugin ID. 9 | */ 10 | public static final int PLUGIN_ID = 11242; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/oskarsmc/message/util/VersionUtils.java: -------------------------------------------------------------------------------- 1 | package com.oskarsmc.message.util; 2 | 3 | import com.oskarsmc.message.configuration.MessageSettings; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | /** 7 | * Utilities relating to versioning. 8 | */ 9 | public final class VersionUtils { 10 | 11 | /** 12 | * The latest config version. 13 | */ 14 | public static final double CONFIG_VERSION = 1.2; 15 | 16 | /** 17 | * Check if the Message Settings object is up-to-date. 18 | * @param messageSettings The message settings object to check. 19 | * @return If the message settings object it up-to-date. 20 | */ 21 | public static boolean isLatestConfigVersion(@NotNull MessageSettings messageSettings) { 22 | if (messageSettings.configVersion() == null) { 23 | return false; 24 | } 25 | return messageSettings.configVersion() == CONFIG_VERSION; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/resources/config.toml: -------------------------------------------------------------------------------- 1 | # Plugin Settings 2 | [plugin] 3 | enabled = true 4 | luckperms-integration = true # If luckperms is found, use luckperms prefixes and suffixes. 5 | miniplaceholders-integration = true # If miniplaceholders is present, you can use the MiniPlaceholders placeholders in the messages. 6 | allow-self-message-sending = true # Allow a player to send messages to themselves. 7 | 8 | # Customise messages using MiniMessage 9 | # Documentation: https://docs.adventure.kyori.net/minimessage.html#format or https://webui.adventure.kyori.net/ 10 | # Default Placeholders: , , , , , , , , , , 11 | # You may use MiniPlaceholders placeholders if the respective integration option is enabled. 12 | # Preview: https://webui.adventure.kyori.net/?mode=chat_closed&input=%3Cwhite%3E%5B%3Ccolor%3A%23FFCE45%3EYOU%3C%2Fcolor%3E%20%E2%86%92%20%3Ccolor%3A%23D4AC2B%3E%3Creceiver_prefix%3E%3Creceiver%3E%3Creceiver_suffix%3E%3C%2Fcolor%3E%5D%20%3Cmessage%3E%3C%2Fwhite%3E%0A%3Cwhite%3E%5B%3Ccolor%3A%23FFCE45%3E%3Csender_prefix%3E%3Csender%3E%3Csender_suffix%3E%3C%2Fcolor%3E%20%E2%86%92%20%3Ccolor%3A%23D4AC2B%3EYOU%3C%2Fcolor%3E%5D%20%3Cmessage%3E%3C%2Fwhite%3E%0A%3Cgradient%3Aaqua%3Ablue%3E%5BSocialSpy%5D%20%3C%2Fgradient%3E%5B%3Cwhite%3E%3Csender%3E%20%E2%86%92%20%3Creceiver%3E%5D%3A%20%3Cmessage%3E&st=%7B%22sender%22%3A%22Player1%22%2C%22receiver%22%3A%22Player2%22%2C%22message%22%3A%22Hello%2C%20World!%22%2C%22receiver_prefix%22%3A%22Admin%20%22%2C%22receiver_suffix%22%3A%22%20%5BLevel%201%5D%22%2C%22sender_prefix%22%3A%22Moderator%20%22%2C%22sender_suffix%22%3A%22%20%5BLevel%200%5D%22%7D 13 | [messages] 14 | message-sent = "[YOU → ] " 15 | message-received = "[YOU] " 16 | message-socialspy = "[SocialSpy] []: " 17 | 18 | 19 | # Customise error handling - leave blank to disable 20 | # Documentation: https://docs.adventure.kyori.net/minimessage.html#format or https://webui.adventure.kyori.net/ 21 | # Syntax: "class" = "message in minimessage" 22 | [error-handlers] 23 | # "cloud.commandframework.exceptions.InvalidSyntaxException" = "" 24 | 25 | # Aliases: 26 | # Customise using a TOML string array. 27 | [aliases] 28 | message = ["msg", "tell"] 29 | reply = ["r"] 30 | socialspy = ["ss"] 31 | 32 | # Please don't touch this 33 | [developer-info] 34 | config-version = 1.2 -------------------------------------------------------------------------------- /src/main/resources/translations.json: -------------------------------------------------------------------------------- 1 | { 2 | "translation-version": "${project.version}", 3 | "translations": [ 4 | { 5 | "language-tag": "en-US", 6 | "translations": { 7 | "oskarsmc.message.command.message.argument.player-argument": "The player to send the message to.", 8 | "oskarsmc.message.command.common.argument.message-description": "The message to send to the player.", 9 | "oskarsmc.message.command.socialspy.on": "SocialSpy enabled.", 10 | "oskarsmc.message.command.socialspy.off": "SocialSpy disabled.", 11 | "oskarsmc.message.command.common.self-sending-error": "You cannot send messages to yourself." 12 | } 13 | }, 14 | { 15 | "language-tag": "es-ES", 16 | "translations": { 17 | "oskarsmc.message.command.message.argument.player-argument": "El jugador al cual enviar el mensaje.", 18 | "oskarsmc.message.command.common.argument.message-description": "El mensaje que se enviara al jugador.", 19 | "oskarsmc.message.command.socialspy.on": "SocialSpy habilitado.", 20 | "oskarsmc.message.command.socialspy.off": "SocialSpy deshabilitado.", 21 | "oskarsmc.message.command.common.self-sending-error": "No puedes enviarte mensajes a ti mismo." 22 | } 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /src/main/resources/velocity-plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "message", 3 | "name": "message", 4 | "version": "${project.version}", 5 | "description": "Cross-Server Messaging Platform for Velocity with API and LuckPerms integration.", 6 | "url": "https://software.oskarsmc.com/plugins/velocity/message/", 7 | "authors": [ 8 | "OskarsMC", 9 | "OskarZyg" 10 | ], 11 | "dependencies": [ 12 | { 13 | "id":"miniplaceholders", 14 | "optional":true 15 | }, 16 | { 17 | "id":"luckperms", 18 | "optional":true 19 | } 20 | ], 21 | "main": "com.oskarsmc.message.Message" 22 | } --------------------------------------------------------------------------------