├── .github └── workflows │ ├── pullrequests.yml │ └── snapshots.yml ├── .gitignore ├── LICENSE ├── LICENSE_HEADER ├── README.md ├── build.gradle ├── common ├── build.gradle └── src │ └── main │ ├── java │ └── me │ │ └── minecraftauth │ │ └── plugin │ │ └── common │ │ ├── abstracted │ │ ├── Logger.java │ │ ├── Player.java │ │ └── event │ │ │ ├── Event.java │ │ │ └── RealmJoinEvent.java │ │ ├── feature │ │ ├── Feature.java │ │ └── gatekeeper │ │ │ ├── Expression.java │ │ │ ├── GatekeeperFeature.java │ │ │ ├── GatekeeperResult.java │ │ │ ├── Realm.java │ │ │ └── function │ │ │ ├── AbstractFunction.java │ │ │ ├── DiscordRoleFunction.java │ │ │ ├── DiscordServerFunction.java │ │ │ ├── GlimpseSponsorFunction.java │ │ │ ├── PatreonMemberFunction.java │ │ │ ├── TwitchFollowerFunction.java │ │ │ ├── TwitchSubscriberFunction.java │ │ │ ├── YouTubeMemberFunction.java │ │ │ └── YouTubeSubscriberFunction.java │ │ └── service │ │ └── AuthenticationService.java │ └── resources │ ├── game-config │ └── en.yml │ └── proxy-config │ └── en.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── proxy ├── bungeecord │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── me │ │ │ └── minecraftauth │ │ │ └── plugin │ │ │ └── bungee │ │ │ ├── BungeeEventsListener.java │ │ │ ├── BungeeLogger.java │ │ │ └── MinecraftAuthBungee.java │ │ └── resources │ │ └── bungee.yml └── velocity │ ├── build.gradle │ └── src │ └── main │ └── java │ └── me │ └── minecraftauth │ └── plugin │ └── velocity │ ├── MinecraftAuthVelocity.java │ ├── VelocityEventsListener.java │ └── VelocityLogger.java ├── server ├── bukkit │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── me │ │ │ └── minecraftauth │ │ │ └── plugin │ │ │ └── bukkit │ │ │ ├── BukkitEventsListener.java │ │ │ ├── BukkitLogger.java │ │ │ └── MinecraftAuthBukkit.java │ │ └── resources │ │ └── plugin.yml ├── forge │ ├── 1.16.5 │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── me │ │ │ │ └── minecraftauth │ │ │ │ └── forge │ │ │ │ └── server │ │ │ │ ├── Command.java │ │ │ │ ├── MinecraftAuthMod.java │ │ │ │ └── mixin │ │ │ │ └── LoginMixin.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── mods.toml │ │ │ ├── minecraftauth.mixins.json │ │ │ └── pack.mcmeta │ ├── 1.18.2 │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── me │ │ │ │ └── minecraftauth │ │ │ │ └── forge │ │ │ │ └── server │ │ │ │ ├── Command.java │ │ │ │ ├── MinecraftAuthMod.java │ │ │ │ └── mixin │ │ │ │ └── LoginMixin.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── mods.toml │ │ │ ├── minecraftauth.mixins.json │ │ │ └── pack.mcmeta │ ├── 1.19.3 │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── me │ │ │ │ └── minecraftauth │ │ │ │ └── forge │ │ │ │ └── server │ │ │ │ ├── Command.java │ │ │ │ ├── MinecraftAuthMod.java │ │ │ │ └── mixin │ │ │ │ └── LoginMixin.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── mods.toml │ │ │ ├── minecraftauth.mixins.json │ │ │ └── pack.mcmeta │ └── 1.20.1 │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ ├── java │ │ └── me │ │ │ └── minecraftauth │ │ │ └── forge │ │ │ └── server │ │ │ ├── Command.java │ │ │ ├── MinecraftAuthMod.java │ │ │ └── mixin │ │ │ └── LoginMixin.java │ │ └── resources │ │ ├── META-INF │ │ └── mods.toml │ │ ├── minecraftauth.mixins.json │ │ └── pack.mcmeta └── sponge │ ├── build.gradle │ └── src │ └── main │ └── java │ └── me │ └── minecraftauth │ └── plugin │ └── sponge │ ├── MinecraftAuthSponge.java │ ├── SpongeEventsListener.java │ └── SpongeLogger.java └── settings.gradle /.github/workflows/pullrequests.yml: -------------------------------------------------------------------------------- 1 | name: Compile pull request 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | compile: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | - name: Set up JDK 8 13 | uses: actions/setup-java@v2 14 | with: 15 | java-version: '8' 16 | distribution: 'adopt' 17 | - name: Cache dependencies 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/.m2 21 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/**gradle**') }} 22 | restore-keys: ${{ runner.os }}-gradle 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Build 26 | run: ./gradlew build 27 | -------------------------------------------------------------------------------- /.github/workflows/snapshots.yml: -------------------------------------------------------------------------------- 1 | name: Compile & push snapshots 2 | 3 | on: 4 | push: 5 | branches: 6 | - devel 7 | 8 | jobs: 9 | compile: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Set up JDK 17 16 | uses: actions/setup-java@v2 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | cache: gradle 21 | - name: Grant execute permission for gradlew 22 | run: chmod +x gradlew 23 | - name: Build common library 24 | run: ./gradlew --no-daemon common:build 25 | - name: Build Bukkit plugin 26 | run: ./gradlew --no-daemon server:bukkit:build 27 | - name: Build Sponge plugin 28 | run: ./gradlew --no-daemon server:sponge:build 29 | - name: Build Forge 1.16.5 mod 30 | run: ./gradlew --no-daemon server:forge:1.16.5:build 31 | - name: Build Forge 1.18.2 mod 32 | run: ./gradlew --no-daemon server:forge:1.18.2:build 33 | - name: Build Forge 1.19.3 mod 34 | run: ./gradlew --no-daemon server:forge:1.19.3:build 35 | - name: Build Forge 1.20.1 mod 36 | run: ./gradlew --no-daemon server:forge:1.20.1:build 37 | - name: Build BungeeCord plugin 38 | run: ./gradlew --no-daemon proxy:bungeecord:build 39 | - name: Build Velocity plugin 40 | run: ./gradlew --no-daemon proxy:velocity:build 41 | - name: Upload artifacts 42 | uses: pyTooling/Actions/releaser@main 43 | with: 44 | token: ${{ secrets.GITHUB_TOKEN }} 45 | tag: snapshot 46 | rm: true 47 | files: | 48 | server/bukkit/build/libs/MinecraftAuth-Bukkit*.jar 49 | server/sponge/build/libs/MinecraftAuth-Sponge*.jar 50 | server/forge/*/build/libs/MinecraftAuth-Forge*.jar 51 | proxy/bungeecord/build/libs/MinecraftAuth-BungeeCord.jar 52 | proxy/velocity/build/libs/MinecraftAuth-Velocity.jar 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | **/.idea/ 3 | .vscode/ 4 | .settings 5 | .classpath 6 | .project 7 | 8 | *.iml 9 | *.ipr 10 | *.iws 11 | 12 | # IntelliJ 13 | out/ 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Package Files # 25 | *.jar 26 | *.war 27 | *.nar 28 | *.ear 29 | *.zip 30 | *.tar.gz 31 | *.rar 32 | 33 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 34 | hs_err_pid* 35 | 36 | *~ 37 | 38 | # temporary files which can be created if a process still has a handle open of a deleted file 39 | .fuse_hidden* 40 | 41 | # KDE directory preferences 42 | .directory 43 | 44 | # Linux trash folder which might appear on any partition or disk 45 | .Trash-* 46 | 47 | # .nfs files are created when an open file is removed but is still being accessed 48 | .nfs* 49 | 50 | # General 51 | .DS_Store 52 | .AppleDouble 53 | .LSOverride 54 | 55 | # Icon must end with two \r 56 | Icon 57 | 58 | # Thumbnails 59 | ._* 60 | 61 | # Files that might appear in the root of a volume 62 | .DocumentRevisions-V100 63 | .fseventsd 64 | .Spotlight-V100 65 | .TemporaryItems 66 | .Trashes 67 | .VolumeIcon.icns 68 | .com.apple.timemachine.donotpresent 69 | 70 | # Directories potentially created on remote AFP share 71 | .AppleDB 72 | .AppleDesktop 73 | Network Trash Folder 74 | Temporary Items 75 | .apdisk 76 | 77 | # Windows thumbnail cache files 78 | Thumbs.db 79 | Thumbs.db:encryptable 80 | ehthumbs.db 81 | ehthumbs_vista.db 82 | 83 | # Dump file 84 | *.stackdump 85 | 86 | # Folder config file 87 | [Dd]esktop.ini 88 | 89 | # Recycle Bin used on file shares 90 | $RECYCLE.BIN/ 91 | 92 | # Windows Installer files 93 | *.cab 94 | *.msi 95 | *.msix 96 | *.msm 97 | *.msp 98 | 99 | # Windows shortcuts 100 | *.lnk 101 | 102 | target/ 103 | 104 | pom.xml.tag 105 | pom.xml.releaseBackup 106 | pom.xml.versionsBackup 107 | pom.xml.next 108 | 109 | release.properties 110 | dependency-reduced-pom.xml 111 | buildNumber.properties 112 | .mvn/timing.properties 113 | .mvn/wrapper/maven-wrapper.jar 114 | .flattened-pom.xml 115 | 116 | # Common working directory 117 | run/ 118 | 119 | # Gradle 120 | .gradle 121 | **/build/ 122 | !src/**/build/ 123 | 124 | # Ignore Gradle GUI config 125 | gradle-app.setting 126 | 127 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 128 | !gradle-wrapper.jar 129 | 130 | # Cache of project 131 | .gradletasknamecache 132 | 133 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 134 | # gradle/wrapper/gradle-wrapper.properties 135 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${year} MinecraftAuth.me 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # plugin 2 | Minecraft plugin for https://minecraftauth.me 3 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.freefair.lombok' version '5.3.3.3' 3 | id 'com.github.johnrengelman.shadow' version '7.0.0' 4 | id 'org.cadixdev.licenser' version '0.6.1' 5 | } 6 | 7 | version = '1.0-SNAPSHOT' 8 | 9 | println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" 10 | 11 | subprojects { 12 | apply plugin: 'java' 13 | apply plugin: 'io.freefair.lombok' 14 | apply plugin: 'com.github.johnrengelman.shadow' 15 | apply plugin: 'org.cadixdev.licenser' 16 | 17 | java.toolchain.languageVersion = JavaLanguageVersion.of(8) 18 | 19 | generateLombokConfig.enabled = false 20 | 21 | repositories { 22 | mavenCentral() 23 | maven { 24 | url 'https://nexus.scarsz.me/content/groups/public/' 25 | } 26 | } 27 | 28 | configurations { 29 | shaded 30 | implementation.extendsFrom(shaded) 31 | } 32 | 33 | jar { 34 | // avoid needing to run licenseFormat & shadowJar when building 35 | dependsOn licenseFormat 36 | finalizedBy shadowJar 37 | } 38 | 39 | shadowJar { 40 | configurations = [project.configurations.shaded] 41 | relocate 'github.scarsz.configuralize', 'me.minecraftauth.config' 42 | relocate 'com.udojava.evalex', 'me.minecraftauth.lib.evalex' 43 | relocate 'com.github.benmanes.caffeine', 'me.minecraftauth.lib.caffeine' 44 | 45 | //noinspection GroovyAssignabilityCheck 46 | archiveClassifier = null 47 | } 48 | 49 | task sourcesJar(type: Jar, dependsOn: classes) { 50 | from sourceSets.main.allSource 51 | 52 | //noinspection GroovyAssignabilityCheck 53 | archiveClassifier = 'sources' 54 | } 55 | 56 | task javadocJar(type: Jar, dependsOn: javadoc) { 57 | from javadoc.destinationDir 58 | 59 | //noinspection GroovyAssignabilityCheck 60 | archiveClassifier = 'javadoc' 61 | } 62 | 63 | // artifacts { 64 | // archives sourcesJar 65 | // archives javadocJar 66 | // } 67 | 68 | license { 69 | header = rootProject.file('LICENSE_HEADER') 70 | properties { 71 | String inception = '2021' 72 | String currentYear = Calendar.getInstance().get(Calendar.YEAR) 73 | year = inception == currentYear ? currentYear : inception + '-' + currentYear 74 | } 75 | include '**/*.java' // only java files 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /common/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | configurations { 6 | api.extendsFrom(shaded) 7 | } 8 | 9 | dependencies { 10 | compileOnly 'org.jetbrains:annotations:22.0.0' 11 | 12 | shaded 'me.minecraftauth:lib:1.1.1' 13 | shaded 'github.scarsz:configuralize:1.4.0' 14 | //noinspection GradlePackageUpdate caffeine 3.x doesn't support JDK 8 15 | shaded 'com.github.ben-manes.caffeine:caffeine:2.9.3' 16 | shaded 'com.udojava:EvalEx:2.7' 17 | } 18 | 19 | jar { 20 | archivesBaseName = 'MinecraftAuth-Common' 21 | } 22 | 23 | shadowJar { 24 | // Overrides the classifier in the root project's build.gradle 25 | // Set the classifier to something, to avoid having the same file name as the regular jar task. 26 | // This prevents warnings during build, as this module is used as a dependency in other modules 27 | 28 | //noinspection GroovyAssignabilityCheck 29 | archiveClassifier = 'shaded' 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/abstracted/Logger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.abstracted; 18 | 19 | import java.io.PrintWriter; 20 | import java.io.StringWriter; 21 | 22 | public interface Logger { 23 | 24 | void info(String message); 25 | 26 | void warning(String message); 27 | 28 | void error(String message); 29 | default void error(String message, Throwable throwable) { 30 | error(message); 31 | 32 | StringWriter writer = new StringWriter(); 33 | try (PrintWriter print = new PrintWriter(writer)) { 34 | throwable.printStackTrace(print); 35 | } 36 | error(writer.toString()); 37 | } 38 | 39 | void debug(String message); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/abstracted/Player.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.abstracted; 18 | 19 | import me.minecraftauth.lib.AuthService; 20 | import me.minecraftauth.lib.account.Account; 21 | import me.minecraftauth.lib.account.AccountType; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | 24 | import java.util.UUID; 25 | 26 | public abstract class Player { 27 | 28 | public abstract String getName(); 29 | public abstract UUID getUUID(); 30 | 31 | public Account getLinkedAccount(AccountType type) throws LookupException { 32 | switch (type) { 33 | case DISCORD: 34 | case PATREON: 35 | case TWITCH: 36 | case GOOGLE: 37 | AuthService.lookup(AccountType.MINECRAFT, getUUID(), type); 38 | default: 39 | throw new IllegalArgumentException("Invalid account type to lookup: " + type.name().toLowerCase()); 40 | } 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | return obj.getClass().equals(getClass()) && getUUID().equals(((Player) obj).getUUID()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/abstracted/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.abstracted.event; 18 | 19 | public interface Event {} 20 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/abstracted/event/RealmJoinEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.abstracted.event; 18 | 19 | import lombok.Getter; 20 | 21 | import java.util.UUID; 22 | 23 | public abstract class RealmJoinEvent implements Event { 24 | 25 | @Getter private final UUID uuid; 26 | @Getter private final String name; 27 | @Getter private final boolean admin; 28 | @Getter private final String server; 29 | 30 | public RealmJoinEvent(UUID uuid, String name, boolean admin, String server) { 31 | this.uuid = uuid; 32 | this.name = name; 33 | this.admin = admin; 34 | this.server = server; 35 | } 36 | 37 | public abstract void disallow(String message); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature; 18 | 19 | public abstract class Feature { 20 | 21 | public abstract void reload(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper; 18 | 19 | import lombok.Getter; 20 | 21 | public class Expression extends com.udojava.evalex.Expression { 22 | 23 | @Getter int successCount = 0; 24 | 25 | public Expression(String expression) { 26 | super(expression); 27 | } 28 | 29 | public int incrementSuccessCount() { 30 | return ++successCount; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/GatekeeperFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper; 18 | 19 | import alexh.weak.Dynamic; 20 | import com.udojava.evalex.AbstractOperator; 21 | import com.udojava.evalex.Operator; 22 | import lombok.Getter; 23 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 24 | import me.minecraftauth.plugin.common.feature.Feature; 25 | import me.minecraftauth.plugin.common.feature.gatekeeper.function.*; 26 | import me.minecraftauth.plugin.common.service.AuthenticationService; 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.math.BigDecimal; 30 | import java.util.*; 31 | import java.util.concurrent.TimeUnit; 32 | import java.util.concurrent.locks.ReentrantLock; 33 | import java.util.function.Supplier; 34 | 35 | public class GatekeeperFeature extends Feature { 36 | 37 | @Getter private final AuthenticationService service; 38 | @Getter private final Map realms = new HashMap<>(); 39 | 40 | @Getter private final Set functions = new HashSet<>(); 41 | @Getter private final Set operators = new HashSet<>(); 42 | 43 | private final ReentrantLock expressionLock = new ReentrantLock(); 44 | private MinecraftAccount accountBeingEvaluated = null; 45 | 46 | public GatekeeperFeature(AuthenticationService service) { 47 | this.service = service; 48 | 49 | Supplier supplier = () -> accountBeingEvaluated; 50 | this.functions.add(new DiscordRoleFunction(this, supplier)); 51 | this.functions.add(new DiscordServerFunction(this, supplier)); 52 | this.functions.add(new GlimpseSponsorFunction(this, supplier)); 53 | this.functions.add(new PatreonMemberFunction(this, supplier)); 54 | this.functions.add(new TwitchFollowerFunction(this, supplier)); 55 | this.functions.add(new TwitchSubscriberFunction(this, supplier)); 56 | this.functions.add(new YouTubeMemberFunction(this, supplier)); 57 | this.functions.add(new YouTubeSubscriberFunction(this, supplier)); 58 | 59 | this.operators.add(new AbstractOperator("and", 4, false, true) { 60 | @Override 61 | public BigDecimal eval(BigDecimal v1, BigDecimal v2) { 62 | Objects.requireNonNull(v1, "No left boolean for AND operator"); 63 | Objects.requireNonNull(v2, "No right boolean for AND operator"); 64 | 65 | boolean b1 = v1.compareTo(BigDecimal.ZERO) != 0; 66 | 67 | if (!b1) { 68 | return BigDecimal.ZERO; 69 | } else { 70 | boolean b2 = v2.compareTo(BigDecimal.ZERO) != 0; 71 | return b2 ? BigDecimal.ONE : BigDecimal.ZERO; 72 | } 73 | } 74 | }); 75 | 76 | reload(); 77 | } 78 | 79 | public @NotNull GatekeeperResult verify(MinecraftAccount account, boolean playerIsAdmin) { 80 | return verify(account, playerIsAdmin, null); 81 | } 82 | public @NotNull GatekeeperResult verify(MinecraftAccount account, boolean playerIsAdmin, String server) { 83 | if (service.getServerToken() == null || realms.isEmpty()) return new GatekeeperResult(GatekeeperResult.Type.NOT_ENABLED); 84 | 85 | if (playerIsAdmin && service.getConfig().getBooleanElse("Gatekeeper.Admin bypass", service.getConfig().getBooleanElse("Gatekeeper.OP bypass", true))) { 86 | service.getLogger().info("[Gatekeeper] " + account + " is bypassing login requirements because they're a server admin"); 87 | return new GatekeeperResult(GatekeeperResult.Type.BYPASSED); 88 | } 89 | 90 | if (service.getConfig().dget("Gatekeeper.Bypass").children().anyMatch(dynamic -> { 91 | String value = dynamic.convert().intoString(); 92 | return value.equalsIgnoreCase(account.getUUID().toString()) || value.equalsIgnoreCase(account.getName()); 93 | })) { 94 | service.getLogger().info("[Gatekeeper] " + account + " is bypassing login requirements because they're listed as a bypass player"); 95 | return new GatekeeperResult(GatekeeperResult.Type.BYPASSED); 96 | } 97 | 98 | try { 99 | if (!expressionLock.tryLock(5, TimeUnit.SECONDS)) 100 | return new GatekeeperResult(GatekeeperResult.Type.DENIED, "Unable to schedule verification, try again"); 101 | this.accountBeingEvaluated = account; 102 | 103 | Realm realm = realms.get(server); 104 | if (realm != null) { 105 | GatekeeperResult result = realm.verify(account); 106 | if (result.getType() == GatekeeperResult.Type.DENIED) { 107 | service.getLogger().info("[Gatekeeper] Denying " + account + (server != null ? "@" + server : "") + ", no conditions were successful"); 108 | } 109 | return result; 110 | } else { 111 | return new GatekeeperResult(GatekeeperResult.Type.NOT_ENABLED); 112 | } 113 | } catch (InterruptedException e) { 114 | service.getLogger().info("[Gatekeeper] Denying " + account + ", verification was interrupted"); 115 | return new GatekeeperResult(GatekeeperResult.Type.DENIED, "Verification was interrupted, try again"); 116 | } finally { 117 | expressionLock.unlock(); 118 | } 119 | } 120 | 121 | @Override 122 | public void reload() { 123 | realms.clear(); 124 | 125 | Realm superRealm = new Realm(this, service.getConfig().dget("Gatekeeper"), null); 126 | if (!superRealm.getExpressions().isEmpty()) { 127 | realms.put(null, superRealm); 128 | } 129 | 130 | Dynamic serversDynamic = service.getConfig().dgetSilent("Gatekeeper.Servers"); 131 | if (serversDynamic.isPresent()) { 132 | serversDynamic.children().forEach(child -> { 133 | String server = child.key().convert().intoString(); 134 | realms.put(server, new Realm(this, child, server)); 135 | }); 136 | } 137 | 138 | boolean onlySuper = realms.keySet().stream().allMatch(Objects::isNull); 139 | int expressionCount = realms.values().stream().mapToInt(realm -> realm.getExpressions().size()).sum(); 140 | 141 | service.getLogger().info(new StringBuilder() 142 | .append("[Gatekeeper] Controlling entry ") 143 | .append(!onlySuper ? "to " + realms.size() + " realm" + (realms.size() > 1 ? "s" : "") + ", " : "") 144 | .append("based on ").append(expressionCount).append(" conditions") 145 | .toString() 146 | ); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/GatekeeperResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper; 18 | 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | public class GatekeeperResult { 22 | 23 | @NotNull private final Type type; 24 | @NotNull private final String message; 25 | 26 | public GatekeeperResult(@NotNull Type type) { 27 | this.type = type; 28 | this.message = ""; 29 | } 30 | public GatekeeperResult(@NotNull Type type, @NotNull String message) { 31 | this.type = type; 32 | this.message = message; 33 | } 34 | 35 | public @NotNull Type getType() { 36 | return type; 37 | } 38 | public @NotNull String getMessage() { 39 | return message; 40 | } 41 | 42 | public enum Type { 43 | 44 | NOT_ENABLED, 45 | DENIED(true), 46 | ALLOWED, 47 | BYPASSED; 48 | 49 | private final boolean willDenyLogin; 50 | 51 | Type() { 52 | this.willDenyLogin = false; 53 | } 54 | Type(boolean willDenyLogin) { 55 | this.willDenyLogin = willDenyLogin; 56 | } 57 | 58 | public boolean willDenyLogin() { 59 | return willDenyLogin; 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/Realm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper; 18 | 19 | import alexh.weak.Dynamic; 20 | import com.udojava.evalex.Operator; 21 | import lombok.Getter; 22 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.function.AbstractFunction; 24 | 25 | import java.math.BigDecimal; 26 | import java.util.Comparator; 27 | import java.util.LinkedList; 28 | import java.util.List; 29 | 30 | public class Realm { 31 | 32 | @Getter private final GatekeeperFeature gatekeeper; 33 | @Getter private final String server; 34 | @Getter private final String kickMessage; 35 | @Getter private final List expressions = new LinkedList<>(); 36 | 37 | protected Realm(GatekeeperFeature gatekeeper, Dynamic config, String server) { 38 | this.gatekeeper = gatekeeper; 39 | this.server = server; 40 | 41 | Dynamic _kickMessage = config.get("Kick message"); 42 | this.kickMessage = _kickMessage.isPresent() ? _kickMessage.convert().intoString() : null; 43 | 44 | config.get("Conditions").children().forEach(d -> { 45 | Expression expression = new Expression(d.asString()); 46 | for (AbstractFunction function : gatekeeper.getFunctions()) expression.addLazyFunction(function); 47 | for (Operator operator : gatekeeper.getOperators()) expression.addOperator(operator); 48 | expressions.add(expression); 49 | }); 50 | } 51 | 52 | public GatekeeperResult verify(MinecraftAccount account) { 53 | boolean first = true; 54 | for (Expression expression : expressions) { 55 | if (expression.eval().compareTo(BigDecimal.ONE) == 0) { 56 | gatekeeper.getService().getLogger().info("[Gatekeeper] " + account + (server != null ? "@" + server : "") + " is being allowed via [" + expression.getOriginalExpression() + "]"); 57 | expression.incrementSuccessCount(); 58 | if (!first) expressions.sort(Comparator.comparingInt(value -> -value.successCount)); 59 | return new GatekeeperResult(GatekeeperResult.Type.ALLOWED); 60 | } 61 | first = false; 62 | } 63 | return new GatekeeperResult(GatekeeperResult.Type.DENIED, kickMessage); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/AbstractFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.github.benmanes.caffeine.cache.Cache; 20 | import com.github.benmanes.caffeine.cache.Caffeine; 21 | import com.udojava.evalex.AbstractLazyFunction; 22 | import com.udojava.evalex.Expression; 23 | import lombok.Getter; 24 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 25 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 26 | 27 | import java.math.BigDecimal; 28 | import java.util.concurrent.TimeUnit; 29 | import java.util.function.Supplier; 30 | 31 | public abstract class AbstractFunction extends AbstractLazyFunction { 32 | 33 | private static final Cache VALUE_CACHE = Caffeine.newBuilder().expireAfterWrite(3, TimeUnit.SECONDS).build(); 34 | 35 | public static final Expression.LazyNumber TRUE = new Expression.LazyNumber() { 36 | @Override 37 | public BigDecimal eval() { 38 | return BigDecimal.ONE; 39 | } 40 | 41 | @Override 42 | public String getString() { 43 | return "1"; 44 | } 45 | }; 46 | 47 | public static final Expression.LazyNumber FALSE = new Expression.LazyNumber() { 48 | @Override 49 | public BigDecimal eval() { 50 | return BigDecimal.ZERO; 51 | } 52 | 53 | @Override 54 | public String getString() { 55 | return "0"; 56 | } 57 | }; 58 | 59 | @Getter private final GatekeeperFeature gatekeeper; 60 | private final Supplier accountSupplier; 61 | 62 | public AbstractFunction(GatekeeperFeature gatekeeper, String name, int numParams, Supplier accountSupplier) { 63 | super(name, numParams, true); 64 | this.gatekeeper = gatekeeper; 65 | this.accountSupplier = accountSupplier; 66 | } 67 | 68 | Expression.LazyNumber cache(String function, String account, String data, Supplier compute) { 69 | return VALUE_CACHE.get(function + "." + account + (data != null ? "." + data : ""), s -> compute.get()); 70 | } 71 | 72 | public MinecraftAccount getAccount() { 73 | return accountSupplier.get(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/DiscordRoleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.Objects; 27 | import java.util.function.Supplier; 28 | 29 | public class DiscordRoleFunction extends AbstractFunction { 30 | 31 | public DiscordRoleFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 32 | super(gatekeeper, "DiscordRole", 1, accountSupplier); 33 | } 34 | 35 | @Override 36 | public Expression.LazyNumber lazyEval(List lazyParams) { 37 | String role = lazyParams.get(0).getString(); 38 | Objects.requireNonNull(role, "No role ID given for " + getClass().getSimpleName()); 39 | 40 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), role, () -> { 41 | try { 42 | return AuthService.isDiscordRolePresent(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), role) ? TRUE : FALSE; 43 | } catch (LookupException e) { 44 | e.printStackTrace(); 45 | return FALSE; 46 | } 47 | }); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/DiscordServerFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.Objects; 27 | import java.util.function.Supplier; 28 | 29 | public class DiscordServerFunction extends AbstractFunction { 30 | 31 | public DiscordServerFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 32 | super(gatekeeper, "DiscordServer", 1, accountSupplier); 33 | } 34 | 35 | @Override 36 | public Expression.LazyNumber lazyEval(List lazyParams) { 37 | String server = lazyParams.get(0).getString(); 38 | Objects.requireNonNull(server, "No server ID given for " + getClass().getSimpleName()); 39 | 40 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), server, () -> { 41 | try { 42 | return AuthService.isDiscordMemberPresent(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), server) ? TRUE : FALSE; 43 | } catch (LookupException e) { 44 | e.printStackTrace(); 45 | return FALSE; 46 | } 47 | }); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/GlimpseSponsorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.function.Supplier; 27 | 28 | public class GlimpseSponsorFunction extends AbstractFunction { 29 | 30 | public GlimpseSponsorFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 31 | super(gatekeeper, "GlimpseSponsor", 1, accountSupplier); 32 | } 33 | 34 | @Override 35 | public Expression.LazyNumber lazyEval(List lazyParams) { 36 | String levelName = lazyParams.size() >= 1 ? lazyParams.get(0).getString() : null; 37 | 38 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), levelName, () -> { 39 | try { 40 | return AuthService.isSubscribedGlimpse(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), levelName) ? TRUE : FALSE; 41 | } catch (LookupException e) { 42 | e.printStackTrace(); 43 | return FALSE; 44 | } 45 | }); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/PatreonMemberFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.function.Supplier; 27 | 28 | public class PatreonMemberFunction extends AbstractFunction { 29 | 30 | public PatreonMemberFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 31 | super(gatekeeper, "PatreonMember", -1, accountSupplier); 32 | } 33 | 34 | @Override 35 | public Expression.LazyNumber lazyEval(List lazyParams) { 36 | String tier = lazyParams.size() >= 1 ? lazyParams.get(0).getString() : null; 37 | 38 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), tier, () -> { 39 | try { 40 | return AuthService.isSubscribedPatreon(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), tier) ? TRUE : FALSE; 41 | } catch (LookupException e) { 42 | e.printStackTrace(); 43 | return FALSE; 44 | } 45 | }); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/TwitchFollowerFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.function.Supplier; 27 | 28 | public class TwitchFollowerFunction extends AbstractFunction { 29 | 30 | public TwitchFollowerFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 31 | super(gatekeeper, "TwitchFollower", 0, accountSupplier); 32 | } 33 | 34 | @Override 35 | public Expression.LazyNumber lazyEval(List lazyParams) { 36 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), null, () -> { 37 | try { 38 | return AuthService.isFollowingTwitch(getGatekeeper().getService().getServerToken(), getAccount().getUUID()) ? TRUE : FALSE; 39 | } catch (LookupException e) { 40 | e.printStackTrace(); 41 | return FALSE; 42 | } 43 | }); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/TwitchSubscriberFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.account.platform.twitch.SubTier; 23 | import me.minecraftauth.lib.exception.LookupException; 24 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 25 | 26 | import java.util.List; 27 | import java.util.function.Supplier; 28 | 29 | public class TwitchSubscriberFunction extends AbstractFunction { 30 | 31 | public TwitchSubscriberFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 32 | super(gatekeeper, "TwitchSubscriber", -1, accountSupplier); 33 | } 34 | 35 | @Override 36 | public Expression.LazyNumber lazyEval(List lazyParams) { 37 | int tierRaw = 1; 38 | if (lazyParams.size() >= 1) tierRaw = lazyParams.get(0).eval().intValueExact(); 39 | SubTier tier = SubTier.level(tierRaw); 40 | 41 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), String.valueOf(tier.getValue()), () -> { 42 | try { 43 | return AuthService.isSubscribedTwitch(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), tier) ? TRUE : FALSE; 44 | } catch (LookupException e) { 45 | e.printStackTrace(); 46 | return FALSE; 47 | } 48 | }); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/YouTubeMemberFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.function.Supplier; 27 | 28 | public class YouTubeMemberFunction extends AbstractFunction { 29 | 30 | public YouTubeMemberFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 31 | super(gatekeeper, "YouTubeMember", -1, accountSupplier); 32 | } 33 | 34 | @Override 35 | public Expression.LazyNumber lazyEval(List lazyParams) { 36 | String tier = lazyParams.size() >= 1 ? lazyParams.get(0).getString() : null; 37 | 38 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), tier, () -> { 39 | try { 40 | return AuthService.isMemberYouTube(getGatekeeper().getService().getServerToken(), getAccount().getUUID(), tier) ? TRUE : FALSE; 41 | } catch (LookupException e) { 42 | e.printStackTrace(); 43 | return FALSE; 44 | } 45 | }); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/feature/gatekeeper/function/YouTubeSubscriberFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.feature.gatekeeper.function; 18 | 19 | import com.udojava.evalex.Expression; 20 | import me.minecraftauth.lib.AuthService; 21 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 22 | import me.minecraftauth.lib.exception.LookupException; 23 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 24 | 25 | import java.util.List; 26 | import java.util.function.Supplier; 27 | 28 | public class YouTubeSubscriberFunction extends AbstractFunction { 29 | 30 | public YouTubeSubscriberFunction(GatekeeperFeature gatekeeper, Supplier accountSupplier) { 31 | super(gatekeeper, "YouTubeSubscriber", 0, accountSupplier); 32 | } 33 | 34 | @Override 35 | public Expression.LazyNumber lazyEval(List lazyParams) { 36 | return cache(getClass().getSimpleName(), getAccount().getUUID().toString(), null, () -> { 37 | try { 38 | return AuthService.isSubscribedYouTube(getGatekeeper().getService().getServerToken(), getAccount().getUUID()) ? TRUE : FALSE; 39 | } catch (LookupException e) { 40 | e.printStackTrace(); 41 | return FALSE; 42 | } 43 | }); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/me/minecraftauth/plugin/common/service/AuthenticationService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.common.service; 18 | 19 | import alexh.weak.Dynamic; 20 | import github.scarsz.configuralize.DynamicConfig; 21 | import github.scarsz.configuralize.ParseException; 22 | import lombok.Getter; 23 | import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; 24 | import me.minecraftauth.lib.exception.LookupException; 25 | import me.minecraftauth.plugin.common.abstracted.Logger; 26 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 27 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperFeature; 28 | import me.minecraftauth.plugin.common.feature.gatekeeper.GatekeeperResult; 29 | 30 | import java.io.IOException; 31 | 32 | public class AuthenticationService { 33 | 34 | @Getter private final DynamicConfig config; 35 | @Getter private final Logger logger; 36 | @Getter private final GatekeeperFeature gatekeeperFeature; 37 | @Getter private String serverToken; 38 | 39 | private AuthenticationService(DynamicConfig config, Logger logger) throws IOException, ParseException { 40 | this.config = config; 41 | this.logger = logger; 42 | this.gatekeeperFeature = new GatekeeperFeature(this); 43 | reload(); 44 | 45 | logger.info("Minecraft Authentication service ready"); 46 | } 47 | 48 | public void reload() throws IOException, ParseException { 49 | config.loadAll(); 50 | Dynamic authenticationDynamic = config.dget("Authentication"); 51 | serverToken = authenticationDynamic.isPresent() ? authenticationDynamic.convert().intoString() : null; 52 | } 53 | 54 | public void fullReload() throws IOException, ParseException { 55 | reload(); 56 | gatekeeperFeature.reload(); 57 | } 58 | 59 | public void handleRealmJoinEvent(RealmJoinEvent event) throws LookupException { 60 | GatekeeperResult gatekeeperResult = gatekeeperFeature.verify(new MinecraftAccount(event.getUuid(), event.getName()), event.isAdmin(), event.getServer()); 61 | 62 | if (gatekeeperResult.getType().willDenyLogin()) { 63 | event.disallow(gatekeeperResult.getMessage()); 64 | } 65 | } 66 | 67 | public static class Builder { 68 | 69 | private DynamicConfig config; 70 | private Logger logger; 71 | 72 | public Builder withConfig(DynamicConfig config) { 73 | this.config = config; 74 | return this; 75 | } 76 | 77 | public Builder withLogger(Logger logger) { 78 | this.logger = logger; 79 | return this; 80 | } 81 | 82 | public AuthenticationService build() throws IOException, ParseException { 83 | return new AuthenticationService(config, logger); 84 | } 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /common/src/main/resources/game-config/en.yml: -------------------------------------------------------------------------------- 1 | Authentication: token 2 | 3 | Gatekeeper: 4 | Bypass: 5 | - d7c1db4d-e57b-488b-b8bc-4462fe49a3e8 # Scarsz 6 | Admin bypass: true 7 | 8 | Kick message: "You must be following me on Twitch to join my Minecraft server!" 9 | Conditions: 10 | - TwitchFollower() 11 | # - TwitchSubscriber(3) 12 | # - TwitchSubscriber() and not(DiscordRole("naughty")) 13 | # - GlimpseSponsor() 14 | # - GlimpseSponsor("minecraft") 15 | # - PatreonMember() 16 | # - PatreonMember("gold") 17 | # - DiscordRole("000000000000000000") 18 | # - DiscordServer("000000000000000000") 19 | # - YouTubeSubscriber() 20 | # - YouTubeMember() 21 | # - DiscordServer("000000000000000000") and TwitchSubscriber() 22 | -------------------------------------------------------------------------------- /common/src/main/resources/proxy-config/en.yml: -------------------------------------------------------------------------------- 1 | Authentication: token 2 | 3 | Gatekeeper: 4 | Bypass: 5 | - d7c1db4d-e57b-488b-b8bc-4462fe49a3e8 # Scarsz 6 | Admin bypass: true 7 | 8 | Kick message: "You must be in my Discord server to join the network!" 9 | Conditions: 10 | - DiscordServer("000000000000000000") 11 | # - TwitchFollower() 12 | # - TwitchSubscriber(3) 13 | # - TwitchSubscriber() and not(DiscordRole("naughty")) 14 | # - GlimpseSponsor() 15 | # - GlimpseSponsor("minecraft") 16 | # - PatreonMember() 17 | # - PatreonMember("gold") 18 | # - DiscordRole("000000000000000000") 19 | # - YouTubeSubscriber() 20 | # - YouTubeMember() 21 | # - DiscordServer("000000000000000000") and TwitchSubscriber() 22 | 23 | Servers: 24 | event: 25 | Kick message: "You must be following me on Twitch to join the event server!" 26 | Conditions: 27 | - TwitchFollower() 28 | 29 | # survival: 30 | # Kick message: "You must be a tier 3 Twitch subscriber to join the survival server!" 31 | # Conditions: 32 | # - TwitchSubscriber(3) 33 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | modid=minecraftauth 2 | org.gradle.daemon=false 3 | org.gradle.parallel=true 4 | org.gradle.jvmargs=-Xmx4G 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinecraftAuthentication/plugin/166bf8d9ad182538a8b3a7d7f49e830a15caba32/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.1.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /proxy/bungeecord/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.ReplaceTokens 2 | 3 | repositories { 4 | maven { 5 | url 'https://oss.sonatype.org/content/groups/public/' 6 | } 7 | maven { 8 | url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' 9 | } 10 | } 11 | 12 | dependencies { 13 | shaded project(':common') 14 | 15 | compileOnly 'net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT' 16 | } 17 | 18 | jar { 19 | archivesBaseName = 'MinecraftAuth-BungeeCord' 20 | } 21 | 22 | processResources { 23 | filter(ReplaceTokens, tokens: ['VERSION': project.version]) 24 | } 25 | -------------------------------------------------------------------------------- /proxy/bungeecord/src/main/java/me/minecraftauth/plugin/bungee/BungeeEventsListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bungee; 18 | 19 | import me.minecraftauth.lib.exception.LookupException; 20 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 21 | import net.md_5.bungee.api.ChatColor; 22 | import net.md_5.bungee.api.chat.TextComponent; 23 | import net.md_5.bungee.api.connection.ProxiedPlayer; 24 | import net.md_5.bungee.api.event.LoginEvent; 25 | import net.md_5.bungee.api.event.ServerConnectEvent; 26 | import net.md_5.bungee.api.plugin.Listener; 27 | import net.md_5.bungee.event.EventHandler; 28 | import net.md_5.bungee.event.EventPriority; 29 | 30 | public class BungeeEventsListener implements Listener { 31 | 32 | @EventHandler(priority = EventPriority.LOWEST) 33 | public void onLogin(LoginEvent event) { 34 | try { 35 | boolean admin = event.getConnection() instanceof ProxiedPlayer && ((ProxiedPlayer) event.getConnection()).getGroups().contains("admin"); 36 | MinecraftAuthBungee.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent(event.getConnection().getUniqueId(), event.getConnection().getName(), admin, null) { 37 | @Override 38 | public void disallow(String message) { 39 | event.setCancelled(true); 40 | event.setCancelReason(TextComponent.fromLegacyText(message)); 41 | } 42 | }); 43 | } catch (LookupException e) { 44 | event.setCancelled(true); 45 | event.setCancelReason(TextComponent.fromLegacyText(ChatColor.RED + "Unable to verify linked account")); 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | @EventHandler(priority = EventPriority.LOWEST) 51 | public void onServerConnect(ServerConnectEvent event) { 52 | try { 53 | boolean admin = event.getPlayer().getGroups().contains("admin"); 54 | MinecraftAuthBungee.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent(event.getPlayer().getUniqueId(), event.getPlayer().getName(), admin, null) { 55 | @Override 56 | public void disallow(String message) { 57 | event.setCancelled(true); 58 | event.getPlayer().sendMessage(TextComponent.fromLegacyText(message)); 59 | } 60 | }); 61 | } catch (LookupException e) { 62 | event.setCancelled(true); 63 | event.getPlayer().sendMessage(TextComponent.fromLegacyText(ChatColor.RED + "Unable to verify linked account")); 64 | e.printStackTrace(); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /proxy/bungeecord/src/main/java/me/minecraftauth/plugin/bungee/BungeeLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bungee; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import me.minecraftauth.plugin.common.abstracted.Logger; 21 | 22 | public class BungeeLogger implements Logger { 23 | 24 | private final DynamicConfig config; 25 | private final java.util.logging.Logger logger; 26 | 27 | public BungeeLogger(DynamicConfig config, java.util.logging.Logger logger) { 28 | this.config = config; 29 | this.logger = logger; 30 | } 31 | 32 | @Override 33 | public void info(String message) { 34 | logger.info(message); 35 | } 36 | 37 | @Override 38 | public void warning(String message) { 39 | logger.warning(message); 40 | } 41 | 42 | @Override 43 | public void error(String message) { 44 | logger.severe(message); 45 | } 46 | 47 | @Override 48 | public void debug(String message) { 49 | if (config.getBooleanElse("Debug", false)) { 50 | info("[DEBUG] " + message); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /proxy/bungeecord/src/main/java/me/minecraftauth/plugin/bungee/MinecraftAuthBungee.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bungee; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import net.md_5.bungee.api.ProxyServer; 24 | import net.md_5.bungee.api.plugin.Plugin; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | 29 | public final class MinecraftAuthBungee extends Plugin { 30 | 31 | @Getter private static MinecraftAuthBungee instance; 32 | @Getter private AuthenticationService service; 33 | 34 | @Override 35 | public void onEnable() { 36 | MinecraftAuthBungee.instance = this; 37 | 38 | DynamicConfig config = new DynamicConfig(); 39 | try { 40 | config.addSource(MinecraftAuthBungee.class, "proxy-config", new File(getDataFolder(), "config.yml")); 41 | config.saveAllDefaults(); 42 | config.loadAll(); 43 | } catch (IOException | ParseException e) { 44 | e.printStackTrace(); 45 | return; 46 | } 47 | 48 | try { 49 | service = new AuthenticationService.Builder() 50 | .withConfig(config) 51 | .withLogger(new BungeeLogger(config, getLogger())) 52 | .build(); 53 | } catch (IOException | ParseException e) { 54 | e.printStackTrace(); 55 | return; 56 | } 57 | 58 | ProxyServer.getInstance().getPluginManager().registerListener(this, new BungeeEventsListener()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /proxy/bungeecord/src/main/resources/bungee.yml: -------------------------------------------------------------------------------- 1 | name: MinecraftAuth 2 | version: @VERSION@ 3 | main: me.minecraftauth.plugin.bungee.MinecraftAuthBungee 4 | authors: [ MinecraftAuth ] 5 | description: Authenticate players in your Minecraft server to various services 6 | website: https://minecraftauth.me 7 | -------------------------------------------------------------------------------- /proxy/velocity/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | maven { 3 | url 'https://repo.papermc.io/repository/maven-public/' 4 | } 5 | } 6 | 7 | java.toolchain.languageVersion = JavaLanguageVersion.of(11) // velocity requires 11+ 8 | 9 | dependencies { 10 | shaded project(':common') 11 | 12 | compileOnly 'com.velocitypowered:velocity-api:3.2.0-SNAPSHOT' 13 | annotationProcessor 'com.velocitypowered:velocity-api:3.2.0-SNAPSHOT' 14 | } 15 | 16 | jar { 17 | archivesBaseName = 'MinecraftAuth-Velocity' 18 | } 19 | -------------------------------------------------------------------------------- /proxy/velocity/src/main/java/me/minecraftauth/plugin/velocity/MinecraftAuthVelocity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.velocity; 18 | 19 | import com.google.inject.Inject; 20 | import com.velocitypowered.api.event.Subscribe; 21 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 22 | import com.velocitypowered.api.plugin.Plugin; 23 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 24 | import com.velocitypowered.api.proxy.ProxyServer; 25 | import github.scarsz.configuralize.DynamicConfig; 26 | import github.scarsz.configuralize.ParseException; 27 | import lombok.Getter; 28 | import me.minecraftauth.plugin.common.service.AuthenticationService; 29 | import org.slf4j.Logger; 30 | 31 | import java.io.File; 32 | import java.io.IOException; 33 | import java.nio.file.Path; 34 | 35 | @Plugin( 36 | id = "minecraftauth", 37 | name = "Minecraft Authentication", 38 | url = "https://minecraftauth.me", 39 | description = "Authenticate players in your Minecraft server to various services", 40 | authors = {"MinecraftAuth"} 41 | ) 42 | public class MinecraftAuthVelocity { 43 | 44 | @Getter private static MinecraftAuthVelocity instance; 45 | @Getter private AuthenticationService service; 46 | 47 | private final ProxyServer server; 48 | private final Logger logger; 49 | private final Path dataDirectory; 50 | 51 | @Inject 52 | public MinecraftAuthVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { 53 | this.server = server; 54 | this.logger = logger; 55 | this.dataDirectory = dataDirectory; 56 | } 57 | 58 | @Subscribe 59 | public void onProxyInitialization(ProxyInitializeEvent event) { 60 | MinecraftAuthVelocity.instance = this; 61 | 62 | DynamicConfig config = new DynamicConfig(); 63 | try { 64 | config.addSource(MinecraftAuthVelocity.class, "proxy-config", new File(dataDirectory.toFile(), "MinecraftAuth.yml")); 65 | config.saveAllDefaults(); 66 | config.loadAll(); 67 | } catch (IOException | ParseException e) { 68 | e.printStackTrace(); 69 | return; 70 | } 71 | 72 | try { 73 | service = new AuthenticationService.Builder() 74 | .withConfig(config) 75 | .withLogger(new VelocityLogger(config, logger)) 76 | .build(); 77 | } catch (IOException | ParseException e) { 78 | e.printStackTrace(); 79 | return; 80 | } 81 | 82 | server.getEventManager().register(this, new VelocityEventsListener()); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /proxy/velocity/src/main/java/me/minecraftauth/plugin/velocity/VelocityEventsListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.velocity; 18 | 19 | import com.velocitypowered.api.event.PostOrder; 20 | import com.velocitypowered.api.event.ResultedEvent; 21 | import com.velocitypowered.api.event.Subscribe; 22 | import com.velocitypowered.api.event.connection.LoginEvent; 23 | import com.velocitypowered.api.event.player.ServerPreConnectEvent; 24 | import me.minecraftauth.lib.exception.LookupException; 25 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 26 | import net.kyori.adventure.text.Component; 27 | import net.kyori.adventure.text.format.NamedTextColor; 28 | 29 | public class VelocityEventsListener { 30 | 31 | @Subscribe(order = PostOrder.FIRST, async = false) 32 | public void onLogin(LoginEvent event) { 33 | try { 34 | MinecraftAuthVelocity.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 35 | event.getPlayer().getUniqueId(), 36 | event.getPlayer().getUsername(), 37 | event.getPlayer().hasPermission("minecraftauth.admin"), 38 | null 39 | ) { 40 | @Override 41 | public void disallow(String message) { 42 | event.setResult(ResultedEvent.ComponentResult.denied(Component.text(message).color(NamedTextColor.RED))); 43 | } 44 | }); 45 | } catch (LookupException e) { 46 | event.setResult(ResultedEvent.ComponentResult.denied(Component.text("Unable to verify linked account").color(NamedTextColor.RED))); 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | @Subscribe(order = PostOrder.FIRST, async = false) 52 | public void onServerConnect(ServerPreConnectEvent event) { 53 | try { 54 | MinecraftAuthVelocity.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 55 | event.getPlayer().getUniqueId(), 56 | event.getPlayer().getUsername(), 57 | event.getPlayer().hasPermission("minecraftauth.admin"), 58 | event.getOriginalServer().getServerInfo().getName() 59 | ) { 60 | @Override 61 | public void disallow(String message) { 62 | event.setResult(ServerPreConnectEvent.ServerResult.denied()); 63 | event.getPlayer().sendMessage(Component.text(message).color(NamedTextColor.RED)); 64 | } 65 | }); 66 | } catch (LookupException e) { 67 | event.setResult(ServerPreConnectEvent.ServerResult.denied()); 68 | event.getPlayer().sendMessage(Component.text("Unable to verify linked account").color(NamedTextColor.RED)); 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /proxy/velocity/src/main/java/me/minecraftauth/plugin/velocity/VelocityLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.velocity; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import me.minecraftauth.plugin.common.abstracted.Logger; 21 | 22 | public class VelocityLogger implements Logger { 23 | 24 | private final DynamicConfig config; 25 | private final org.slf4j.Logger logger; 26 | 27 | public VelocityLogger(DynamicConfig config, org.slf4j.Logger logger) { 28 | this.config = config; 29 | this.logger = logger; 30 | } 31 | 32 | @Override 33 | public void info(String message) { 34 | logger.info(message); 35 | } 36 | 37 | @Override 38 | public void warning(String message) { 39 | logger.warn(message); 40 | } 41 | 42 | @Override 43 | public void error(String message) { 44 | logger.error(message); 45 | } 46 | 47 | @Override 48 | public void debug(String message) { 49 | if (config.getBooleanElse("Debug", false)) { 50 | info("[DEBUG] " + message); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /server/bukkit/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.ReplaceTokens 2 | 3 | repositories { 4 | maven { 5 | url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' 6 | } 7 | } 8 | 9 | dependencies { 10 | shaded project(':common') 11 | 12 | compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' 13 | } 14 | 15 | jar { 16 | archivesBaseName = 'MinecraftAuth-Bukkit' 17 | } 18 | 19 | processResources { 20 | filter(ReplaceTokens, tokens: ['VERSION': project.version]) 21 | } 22 | -------------------------------------------------------------------------------- /server/bukkit/src/main/java/me/minecraftauth/plugin/bukkit/BukkitEventsListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bukkit; 18 | 19 | import me.minecraftauth.lib.exception.LookupException; 20 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 21 | import org.bukkit.Bukkit; 22 | import org.bukkit.ChatColor; 23 | import org.bukkit.event.EventHandler; 24 | import org.bukkit.event.Listener; 25 | import org.bukkit.event.player.AsyncPlayerPreLoginEvent; 26 | 27 | public class BukkitEventsListener implements Listener { 28 | 29 | @EventHandler 30 | public void onPlayerLoginEvent(AsyncPlayerPreLoginEvent event) { 31 | try { 32 | boolean op = Bukkit.getOperators().stream().anyMatch(offlinePlayer -> offlinePlayer.getUniqueId().equals(event.getUniqueId())); 33 | MinecraftAuthBukkit.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent(event.getUniqueId(), event.getName(), op, null) { 34 | @Override 35 | public void disallow(String message) { 36 | event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST, message); 37 | } 38 | }); 39 | } catch (LookupException e) { 40 | event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, ChatColor.RED + "Unable to verify linked account"); 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /server/bukkit/src/main/java/me/minecraftauth/plugin/bukkit/BukkitLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bukkit; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import me.minecraftauth.plugin.common.abstracted.Logger; 21 | 22 | public class BukkitLogger implements Logger { 23 | 24 | private final DynamicConfig config; 25 | private final java.util.logging.Logger logger; 26 | 27 | public BukkitLogger(DynamicConfig config, java.util.logging.Logger logger) { 28 | this.config = config; 29 | this.logger = logger; 30 | } 31 | 32 | @Override 33 | public void info(String message) { 34 | logger.info(message); 35 | } 36 | 37 | @Override 38 | public void warning(String message) { 39 | logger.warning(message); 40 | } 41 | 42 | @Override 43 | public void error(String message) { 44 | logger.severe(message); 45 | } 46 | 47 | @Override 48 | public void debug(String message) { 49 | if (config.getBooleanElse("Debug", false)) { 50 | info("[DEBUG] " + message); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /server/bukkit/src/main/java/me/minecraftauth/plugin/bukkit/MinecraftAuthBukkit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.bukkit; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import org.bukkit.Bukkit; 24 | import org.bukkit.ChatColor; 25 | import org.bukkit.command.Command; 26 | import org.bukkit.command.CommandSender; 27 | import org.bukkit.plugin.java.JavaPlugin; 28 | 29 | import java.io.File; 30 | import java.io.IOException; 31 | import java.util.Locale; 32 | 33 | public final class MinecraftAuthBukkit extends JavaPlugin { 34 | 35 | @Getter private static MinecraftAuthBukkit instance; 36 | @Getter private AuthenticationService service; 37 | 38 | @Override 39 | public void onEnable() { 40 | MinecraftAuthBukkit.instance = this; 41 | 42 | DynamicConfig config = new DynamicConfig(); 43 | try { 44 | config.addSource(MinecraftAuthBukkit.class, "game-config", new File(getDataFolder(), "config.yml")); 45 | config.saveAllDefaults(); 46 | config.loadAll(); 47 | } catch (IOException | ParseException e) { 48 | e.printStackTrace(); 49 | Bukkit.getPluginManager().disablePlugin(this); 50 | return; 51 | } 52 | 53 | try { 54 | service = new AuthenticationService.Builder() 55 | .withConfig(config) 56 | .withLogger(new BukkitLogger(config, getLogger())) 57 | .build(); 58 | } catch (IOException | ParseException e) { 59 | e.printStackTrace(); 60 | Bukkit.getPluginManager().disablePlugin(this); 61 | return; 62 | } 63 | 64 | Bukkit.getPluginManager().registerEvents(new BukkitEventsListener(), this); 65 | Bukkit.getPluginCommand("minecraftauth").setExecutor(this); 66 | } 67 | 68 | @Override 69 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 70 | switch (args[0].toLowerCase(Locale.ROOT)) { 71 | case "reload": 72 | if (sender.isOp()) { 73 | try { 74 | service.fullReload(); 75 | sender.sendMessage("MinecraftAuth config reloaded"); 76 | } catch (IOException e) { 77 | sender.sendMessage("IO exception while reading config: " + e.getMessage()); 78 | e.printStackTrace(); 79 | } catch (ParseException e) { 80 | sender.sendMessage("Exception while parsing config:"); 81 | for (String line : e.getMessage().split("\n")) sender.sendMessage(line); 82 | e.printStackTrace(); 83 | } 84 | } else { 85 | sender.sendMessage(ChatColor.RED + "Server operator-only command"); 86 | } 87 | break; 88 | default: 89 | sender.sendMessage(ChatColor.RED + "Unknown subcommand"); 90 | return false; 91 | } 92 | 93 | return true; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /server/bukkit/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MinecraftAuth 2 | version: @VERSION@ 3 | main: me.minecraftauth.plugin.bukkit.MinecraftAuthBukkit 4 | api-version: 1.13 5 | authors: [ MinecraftAuth ] 6 | description: Authenticate players in your Minecraft server to various services 7 | website: https://minecraftauth.me 8 | commands: 9 | minecraftauth: 10 | description: Administrative commands for MinecraftAuth 11 | aliases: [mcauth] 12 | usage: /minecraftauth 13 | -------------------------------------------------------------------------------- /server/forge/1.16.5/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { url = 'https://maven.minecraftforge.net' } 5 | maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } 6 | } 7 | dependencies { 8 | classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' 9 | } 10 | } 11 | 12 | plugins { 13 | id 'eclipse' 14 | id 'idea' 15 | id 'net.minecraftforge.gradle' version '[6.0,6.2)' 16 | } 17 | 18 | version = "1.16.5" 19 | group = "me.minecraftauth" 20 | archivesBaseName = "${modid}" 21 | 22 | java.toolchain.languageVersion = JavaLanguageVersion.of(8) 23 | println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" 24 | minecraft { 25 | // snapshot YYYYMMDD Snapshot are built nightly. 26 | // stable # Stables are built at the discretion of the MCP team. 27 | // official MCVersion Official field/method names from Mojang mapping files 28 | mappings channel: "official", version: "1.16.5" 29 | //makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. 30 | //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') 31 | 32 | runs { 33 | server { 34 | properties 'mixin.env.remapRefMap': 'true' 35 | property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" 36 | workingDirectory project.file('run') 37 | arg "-mixin.config="+archivesBaseName+".mixins.json" 38 | 39 | property 'forge.logging.console.level', 'debug' 40 | 41 | mods { 42 | minecraftauth { 43 | source sourceSets.main 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | repositories{ 51 | mavenCentral() 52 | } 53 | 54 | dependencies { 55 | shaded project(':common') 56 | minecraft "net.minecraftforge:forge:1.16.5-36.2.0" 57 | annotationProcessor 'org.spongepowered:mixin:0.8.4:processor' 58 | } 59 | 60 | sourceSets { 61 | main.resources.srcDirs += 'src/generated/resources' 62 | } 63 | 64 | jar { 65 | archivesBaseName = 'MinecraftAuth-Forge' 66 | 67 | manifest { 68 | attributes([ 69 | "Specification-Title": "${modid}", 70 | "Specification-Vendor": "minecraftauth", 71 | "Specification-Version": "1", // We are version 1 of ourselves 72 | "Implementation-Title": project.name, 73 | "Implementation-Version": "${version}", 74 | "Implementation-Vendor" :"minecraftauth", 75 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), 76 | "MixinConfigs": "${modid}.mixins.json" 77 | ]) 78 | } 79 | } 80 | 81 | apply plugin: 'org.spongepowered.mixin' 82 | mixin { 83 | add sourceSets.main, "${modid}.refmap.json" 84 | } 85 | 86 | // ensure shadowJar gets re-obfuscated 87 | tasks.shadowJar.dependsOn "reobfJar" 88 | reobf { shadowJar {} } 89 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/java/me/minecraftauth/forge/server/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import com.mojang.brigadier.CommandDispatcher; 20 | import com.mojang.brigadier.context.CommandContext; 21 | import github.scarsz.configuralize.ParseException; 22 | import net.minecraft.command.CommandSource; 23 | import net.minecraft.command.Commands; 24 | import net.minecraft.util.text.StringTextComponent; 25 | import net.minecraft.util.text.TextFormatting; 26 | 27 | import java.io.IOException; 28 | 29 | public class Command { 30 | 31 | public Command(CommandDispatcher dispatcher) { 32 | dispatcher.register(Commands.literal("minecraftauth") 33 | .then(Commands.literal("reload") 34 | .requires(cs -> cs.hasPermission(3)) 35 | .executes(context -> reload(context, context.getSource())) 36 | ) 37 | ); 38 | } 39 | 40 | private int reload(CommandContext context, CommandSource source) { 41 | try { 42 | MinecraftAuthMod.getInstance().getService().fullReload(); 43 | source.sendSuccess(new StringTextComponent("MinecraftAuth config reloaded").withStyle(TextFormatting.RED), true); 44 | return 1; 45 | } catch (IOException e) { 46 | source.sendFailure(new StringTextComponent("IO exception while reading config: " + e.getMessage()).withStyle(TextFormatting.RED)); 47 | e.printStackTrace(); 48 | } catch (ParseException e) { 49 | source.sendFailure(new StringTextComponent("Exception while parsing config: " + e.getMessage()).withStyle(TextFormatting.RED)); 50 | e.printStackTrace(); 51 | } 52 | 53 | return -1; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/java/me/minecraftauth/forge/server/MinecraftAuthMod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import net.minecraftforge.common.MinecraftForge; 24 | import net.minecraftforge.event.RegisterCommandsEvent; 25 | import net.minecraftforge.eventbus.api.SubscribeEvent; 26 | import net.minecraftforge.fml.ExtensionPoint; 27 | import net.minecraftforge.fml.ModLoadingContext; 28 | import net.minecraftforge.fml.common.Mod; 29 | import net.minecraftforge.fml.network.FMLNetworkConstants; 30 | import net.minecraftforge.server.command.ConfigCommand; 31 | import org.apache.commons.lang3.tuple.Pair; 32 | import org.apache.logging.log4j.LogManager; 33 | import org.apache.logging.log4j.Logger; 34 | 35 | import java.io.File; 36 | import java.io.IOException; 37 | 38 | @Mod(MinecraftAuthMod.MOD_ID) 39 | public class MinecraftAuthMod { 40 | 41 | public static final String MOD_ID = "minecraftauth"; 42 | @Getter private static final Logger logger = LogManager.getLogger(); 43 | @Getter private static MinecraftAuthMod instance; 44 | 45 | @Getter private AuthenticationService service; 46 | 47 | public MinecraftAuthMod() { 48 | MinecraftAuthMod.instance = this; 49 | MinecraftForge.EVENT_BUS.register(this); 50 | 51 | // inform mod loader that this is a server-only mod and isn't required on clients 52 | ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); 53 | 54 | DynamicConfig config = new DynamicConfig(); 55 | try { 56 | config.addSource(MinecraftAuthMod.class, "game-config", new File("config", "MinecraftAuth.yml")); 57 | config.saveAllDefaults(); 58 | config.loadAll(); 59 | } catch (IOException | ParseException e) { 60 | e.printStackTrace(); 61 | return; 62 | } 63 | 64 | try { 65 | service = new AuthenticationService.Builder() 66 | .withConfig(config) 67 | .withLogger(new me.minecraftauth.plugin.common.abstracted.Logger() { 68 | @Override 69 | public void info(String message) { 70 | logger.info(message); 71 | } 72 | @Override 73 | public void warning(String message) { 74 | logger.warn(message); 75 | } 76 | @Override 77 | public void error(String message) { 78 | logger.error(message); 79 | } 80 | @Override 81 | public void debug(String message) { 82 | logger.debug(message); 83 | } 84 | }) 85 | .build(); 86 | } catch (IOException | ParseException e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | 91 | @SubscribeEvent 92 | public void onRegisterCommands(RegisterCommandsEvent event) { 93 | new Command(event.getDispatcher()); 94 | ConfigCommand.register(event.getDispatcher()); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/java/me/minecraftauth/forge/server/mixin/LoginMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server.mixin; 18 | 19 | import com.mojang.authlib.GameProfile; 20 | import me.minecraftauth.forge.server.MinecraftAuthMod; 21 | import me.minecraftauth.lib.exception.LookupException; 22 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 23 | import net.minecraft.server.management.PlayerList; 24 | import net.minecraft.util.text.IFormattableTextComponent; 25 | import net.minecraft.util.text.ITextComponent; 26 | import net.minecraft.util.text.StringTextComponent; 27 | import net.minecraft.util.text.TextFormatting; 28 | import net.minecraftforge.fml.server.ServerLifecycleHooks; 29 | import org.spongepowered.asm.mixin.Mixin; 30 | import org.spongepowered.asm.mixin.injection.At; 31 | import org.spongepowered.asm.mixin.injection.Inject; 32 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 33 | 34 | import java.net.SocketAddress; 35 | 36 | @Mixin(PlayerList.class) 37 | public abstract class LoginMixin { 38 | 39 | @Inject(at = @At("RETURN"), method = "canPlayerLogin", cancellable = true) 40 | private void init(SocketAddress address, GameProfile profile, CallbackInfoReturnable returnedMessage) { 41 | if (returnedMessage.getReturnValue() == null) { 42 | // System.out.println("Player " + profile.getName() + "[" + profile.getId() + "] is logging in @ " + address); 43 | 44 | try { 45 | MinecraftAuthMod.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 46 | profile.getId(), 47 | profile.getName(), 48 | ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(profile), 49 | null 50 | ) { 51 | @Override 52 | public void disallow(String message) { 53 | returnedMessage.setReturnValue(errorComponent(message)); 54 | } 55 | }); 56 | } catch (LookupException e) { 57 | returnedMessage.setReturnValue(errorComponent("Unable to verify linked account")); 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | 63 | private IFormattableTextComponent errorComponent(String message) { 64 | return new StringTextComponent(message).withStyle(TextFormatting.RED); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[36,)" 3 | license="Apache License, Version 2.0" 4 | 5 | [[mods]] 6 | modId="minecraftauth" 7 | version="1.16.5" 8 | displayName="Minecraft Authentication" 9 | description="Authenticate players in your Minecraft server to various services" 10 | authors="Minecraft Authentication" 11 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/resources/minecraftauth.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "me.minecraftauth.forge.server.mixin", 4 | "compatibilityLevel": "JAVA_8", 5 | "refmap": "minecraftauth.refmap.json", 6 | "server": [ 7 | "LoginMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | }, 12 | "minVersion": "0.8" 13 | } 14 | -------------------------------------------------------------------------------- /server/forge/1.16.5/src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "MinecraftAuth resources", 4 | "pack_format": 6, 5 | "_comment": "A pack_format of 6 requires json lang files. Note: we require v6 pack meta for all mods." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /server/forge/1.18.2/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { url = 'https://maven.minecraftforge.net' } 5 | maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } 6 | } 7 | dependencies { 8 | classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' 9 | } 10 | } 11 | 12 | plugins { 13 | id 'eclipse' 14 | id 'idea' 15 | id 'net.minecraftforge.gradle' version '[6.0,6.2)' 16 | } 17 | 18 | version = "1.18.2" 19 | group = "me.minecraftauth" 20 | archivesBaseName = "${modid}" 21 | 22 | java.toolchain.languageVersion = JavaLanguageVersion.of(17) 23 | println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" 24 | minecraft { 25 | // snapshot YYYYMMDD Snapshot are built nightly. 26 | // stable # Stables are built at the discretion of the MCP team. 27 | // official MCVersion Official field/method names from Mojang mapping files 28 | mappings channel: 'official', version: '1.18.2' 29 | //makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. 30 | //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') 31 | 32 | runs { 33 | server { 34 | properties 'mixin.env.remapRefMap': 'true' 35 | property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" 36 | workingDirectory project.file('run') 37 | arg "-mixin.config="+archivesBaseName+".mixins.json" 38 | 39 | property 'forge.logging.console.level', 'debug' 40 | 41 | mods { 42 | minecraftauth { 43 | source sourceSets.main 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | repositories{ 51 | mavenCentral() 52 | } 53 | 54 | dependencies { 55 | shaded project(':common') 56 | minecraft 'net.minecraftforge:forge:1.18.2-40.1.21' 57 | annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' 58 | } 59 | 60 | sourceSets { 61 | main.resources.srcDirs += 'src/generated/resources' 62 | } 63 | 64 | jar { 65 | archivesBaseName = 'MinecraftAuth-Forge' 66 | 67 | manifest { 68 | attributes([ 69 | "Specification-Title": "${modid}", 70 | "Specification-Vendor": "minecraftauth", 71 | "Specification-Version": "1", // We are version 1 of ourselves 72 | "Implementation-Title": project.name, 73 | "Implementation-Version": "${version}", 74 | "Implementation-Vendor" :"minecraftauth", 75 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), 76 | "MixinConfigs": "${modid}.mixins.json" 77 | ]) 78 | } 79 | } 80 | 81 | apply plugin: 'org.spongepowered.mixin' 82 | mixin { 83 | add sourceSets.main, "${modid}.refmap.json" 84 | } 85 | 86 | // ensure shadowJar gets re-obfuscated 87 | tasks.shadowJar.dependsOn "reobfJar" 88 | reobf { shadowJar {} } 89 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/java/me/minecraftauth/forge/server/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import com.mojang.brigadier.CommandDispatcher; 20 | import com.mojang.brigadier.context.CommandContext; 21 | import github.scarsz.configuralize.ParseException; 22 | import net.minecraft.ChatFormatting; 23 | import net.minecraft.commands.CommandSourceStack; 24 | import net.minecraft.commands.Commands; 25 | import net.minecraft.network.chat.TextComponent; 26 | 27 | import java.io.IOException; 28 | 29 | public class Command { 30 | 31 | public Command(CommandDispatcher dispatcher) { 32 | dispatcher.register(Commands.literal("minecraftauth") 33 | .then(Commands.literal("reload") 34 | .requires(cs -> cs.hasPermission(3)) 35 | .executes(context -> reload(context, context.getSource())) 36 | ) 37 | ); 38 | } 39 | 40 | private int reload(CommandContext context, CommandSourceStack source) { 41 | try { 42 | MinecraftAuthMod.getInstance().getService().fullReload(); 43 | source.sendSuccess(new TextComponent("MinecraftAuth config reloaded").withStyle(ChatFormatting.RED), true); 44 | return 1; 45 | } catch (IOException e) { 46 | source.sendFailure(new TextComponent("IO exception while reading config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 47 | e.printStackTrace(); 48 | } catch (ParseException e) { 49 | source.sendFailure(new TextComponent("Exception while parsing config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 50 | e.printStackTrace(); 51 | } 52 | return -1; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/java/me/minecraftauth/forge/server/MinecraftAuthMod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import net.minecraftforge.common.MinecraftForge; 24 | import net.minecraftforge.event.RegisterCommandsEvent; 25 | import net.minecraftforge.eventbus.api.SubscribeEvent; 26 | import net.minecraftforge.fml.IExtensionPoint; 27 | import net.minecraftforge.fml.ModLoadingContext; 28 | import net.minecraftforge.fml.common.Mod; 29 | import net.minecraftforge.network.NetworkConstants; 30 | import net.minecraftforge.server.command.ConfigCommand; 31 | import org.apache.logging.log4j.LogManager; 32 | import org.apache.logging.log4j.Logger; 33 | 34 | import java.io.File; 35 | import java.io.IOException; 36 | 37 | @Mod(MinecraftAuthMod.MOD_ID) 38 | public class MinecraftAuthMod { 39 | 40 | public static final String MOD_ID = "minecraftauth"; 41 | @Getter private static final Logger logger = LogManager.getLogger(); 42 | @Getter private static MinecraftAuthMod instance; 43 | 44 | @Getter private AuthenticationService service; 45 | 46 | public MinecraftAuthMod() { 47 | MinecraftAuthMod.instance = this; 48 | MinecraftForge.EVENT_BUS.register(this); 49 | 50 | // inform mod loader that this is a server-only mod and isn't required on clients 51 | ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); 52 | 53 | DynamicConfig config = new DynamicConfig(); 54 | try { 55 | config.addSource(MinecraftAuthMod.class, "game-config", new File("config", "MinecraftAuth.yml")); 56 | config.saveAllDefaults(); 57 | config.loadAll(); 58 | } catch (IOException | ParseException e) { 59 | e.printStackTrace(); 60 | return; 61 | } 62 | 63 | try { 64 | service = new AuthenticationService.Builder() 65 | .withConfig(config) 66 | .withLogger(new me.minecraftauth.plugin.common.abstracted.Logger() { 67 | @Override 68 | public void info(String message) { 69 | logger.info(message); 70 | } 71 | @Override 72 | public void warning(String message) { 73 | logger.warn(message); 74 | } 75 | @Override 76 | public void error(String message) { 77 | logger.error(message); 78 | } 79 | @Override 80 | public void debug(String message) { 81 | logger.debug(message); 82 | } 83 | }) 84 | .build(); 85 | } catch (IOException | ParseException e) { 86 | e.printStackTrace(); 87 | } 88 | } 89 | 90 | @SubscribeEvent 91 | public void onRegisterCommands(RegisterCommandsEvent event) { 92 | new Command(event.getDispatcher()); 93 | ConfigCommand.register(event.getDispatcher()); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/java/me/minecraftauth/forge/server/mixin/LoginMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server.mixin; 18 | 19 | import com.mojang.authlib.GameProfile; 20 | import me.minecraftauth.forge.server.MinecraftAuthMod; 21 | import me.minecraftauth.lib.exception.LookupException; 22 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 23 | import net.minecraft.ChatFormatting; 24 | import net.minecraft.network.chat.Component; 25 | import net.minecraft.network.chat.MutableComponent; 26 | import net.minecraft.network.chat.TextComponent; 27 | import net.minecraft.server.players.PlayerList; 28 | import net.minecraftforge.server.ServerLifecycleHooks; 29 | import org.spongepowered.asm.mixin.Mixin; 30 | import org.spongepowered.asm.mixin.injection.At; 31 | import org.spongepowered.asm.mixin.injection.Inject; 32 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 33 | 34 | import java.net.SocketAddress; 35 | 36 | @Mixin(PlayerList.class) 37 | public abstract class LoginMixin { 38 | 39 | @Inject(at = @At("RETURN"), method = "canPlayerLogin", cancellable = true) 40 | private void init(SocketAddress address, GameProfile profile, CallbackInfoReturnable returnedMessage) { 41 | if (returnedMessage.getReturnValue() == null) { 42 | // System.out.println("Player " + profile.getName() + "[" + profile.getId() + "] is logging in @ " + address); 43 | 44 | try { 45 | MinecraftAuthMod.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 46 | profile.getId(), 47 | profile.getName(), 48 | ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(profile), 49 | null 50 | ) { 51 | @Override 52 | public void disallow(String message) { 53 | returnedMessage.setReturnValue(errorComponent(message)); 54 | } 55 | }); 56 | } catch (LookupException e) { 57 | returnedMessage.setReturnValue(errorComponent("Unable to verify linked account")); 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | 63 | private MutableComponent errorComponent(String message) { 64 | return new TextComponent(message).withStyle(ChatFormatting.RED); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[36,)" 3 | license="Apache License, Version 2.0" 4 | 5 | [[mods]] 6 | modId="minecraftauth" 7 | version="1.18.2" 8 | displayName="Minecraft Authentication" 9 | description="Authenticate players in your Minecraft server to various services" 10 | authors="Minecraft Authentication" 11 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/resources/minecraftauth.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "me.minecraftauth.forge.server.mixin", 4 | "compatibilityLevel": "JAVA_17", 5 | "refmap": "minecraftauth.refmap.json", 6 | "server": [ 7 | "LoginMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | }, 12 | "minVersion": "0.8" 13 | } 14 | -------------------------------------------------------------------------------- /server/forge/1.18.2/src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "MinecraftAuth resources", 4 | "pack_format": 6, 5 | "_comment": "A pack_format of 6 requires json lang files. Note: we require v6 pack meta for all mods." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /server/forge/1.19.3/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { url = 'https://maven.minecraftforge.net' } 5 | maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } 6 | } 7 | dependencies { 8 | classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' 9 | } 10 | } 11 | 12 | plugins { 13 | id 'eclipse' 14 | id 'idea' 15 | id 'net.minecraftforge.gradle' version '[6.0,6.2)' 16 | } 17 | 18 | version = "1.19.3" 19 | group = "me.minecraftauth" 20 | archivesBaseName = "${modid}" 21 | 22 | java.toolchain.languageVersion = JavaLanguageVersion.of(17) 23 | println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" 24 | minecraft { 25 | // snapshot YYYYMMDD Snapshot are built nightly. 26 | // stable # Stables are built at the discretion of the MCP team. 27 | // official MCVersion Official field/method names from Mojang mapping files 28 | mappings channel: 'official', version: '1.19.3' 29 | //makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. 30 | //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') 31 | 32 | runs { 33 | server { 34 | properties 'mixin.env.remapRefMap': 'true' 35 | property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" 36 | workingDirectory project.file('run') 37 | arg "-mixin.config="+archivesBaseName+".mixins.json" 38 | 39 | property 'forge.logging.console.level', 'debug' 40 | 41 | mods { 42 | minecraftauth { 43 | source sourceSets.main 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | repositories{ 51 | mavenCentral() 52 | } 53 | 54 | dependencies { 55 | shaded project(':common') 56 | minecraft 'net.minecraftforge:forge:1.19.3-44.1.0' 57 | annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' 58 | } 59 | 60 | sourceSets { 61 | main.resources.srcDirs += 'src/generated/resources' 62 | } 63 | 64 | jar { 65 | archivesBaseName = 'MinecraftAuth-Forge' 66 | 67 | manifest { 68 | attributes([ 69 | "Specification-Title": "${modid}", 70 | "Specification-Vendor": "minecraftauth", 71 | "Specification-Version": "1", // We are version 1 of ourselves 72 | "Implementation-Title": project.name, 73 | "Implementation-Version": "${version}", 74 | "Implementation-Vendor" :"minecraftauth", 75 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), 76 | "MixinConfigs": "${modid}.mixins.json" 77 | ]) 78 | } 79 | } 80 | 81 | apply plugin: 'org.spongepowered.mixin' 82 | mixin { 83 | add sourceSets.main, "${modid}.refmap.json" 84 | } 85 | 86 | // ensure shadowJar gets re-obfuscated 87 | tasks.shadowJar.dependsOn "reobfJar" 88 | reobf { shadowJar {} } 89 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/java/me/minecraftauth/forge/server/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import com.mojang.brigadier.CommandDispatcher; 20 | import com.mojang.brigadier.context.CommandContext; 21 | import github.scarsz.configuralize.ParseException; 22 | import net.minecraft.ChatFormatting; 23 | import net.minecraft.commands.CommandSourceStack; 24 | import net.minecraft.commands.Commands; 25 | import net.minecraft.network.chat.Component; 26 | 27 | import java.io.IOException; 28 | 29 | public class Command { 30 | 31 | public Command(CommandDispatcher dispatcher) { 32 | dispatcher.register(Commands.literal("minecraftauth") 33 | .then(Commands.literal("reload") 34 | .requires(cs -> cs.hasPermission(3)) 35 | .executes(context -> reload(context, context.getSource())) 36 | ) 37 | ); 38 | } 39 | 40 | private int reload(CommandContext context, CommandSourceStack source) { 41 | try { 42 | MinecraftAuthMod.getInstance().getService().fullReload(); 43 | source.sendSuccess(Component.literal("MinecraftAuth config reloaded").withStyle(ChatFormatting.RED), true); 44 | return 1; 45 | } catch (IOException e) { 46 | source.sendFailure(Component.literal("IO exception while reading config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 47 | e.printStackTrace(); 48 | } catch (ParseException e) { 49 | source.sendFailure(Component.literal("Exception while parsing config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 50 | e.printStackTrace(); 51 | } 52 | return -1; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/java/me/minecraftauth/forge/server/MinecraftAuthMod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import net.minecraftforge.common.MinecraftForge; 24 | import net.minecraftforge.event.RegisterCommandsEvent; 25 | import net.minecraftforge.eventbus.api.SubscribeEvent; 26 | import net.minecraftforge.fml.IExtensionPoint; 27 | import net.minecraftforge.fml.ModLoadingContext; 28 | import net.minecraftforge.fml.common.Mod; 29 | import net.minecraftforge.network.NetworkConstants; 30 | import net.minecraftforge.server.command.ConfigCommand; 31 | import org.apache.logging.log4j.LogManager; 32 | import org.apache.logging.log4j.Logger; 33 | 34 | import java.io.File; 35 | import java.io.IOException; 36 | 37 | @Mod(MinecraftAuthMod.MOD_ID) 38 | public class MinecraftAuthMod { 39 | 40 | public static final String MOD_ID = "minecraftauth"; 41 | @Getter private static final Logger logger = LogManager.getLogger(); 42 | @Getter private static MinecraftAuthMod instance; 43 | 44 | @Getter private AuthenticationService service; 45 | 46 | public MinecraftAuthMod() { 47 | MinecraftAuthMod.instance = this; 48 | MinecraftForge.EVENT_BUS.register(this); 49 | 50 | // inform mod loader that this is a server-only mod and isn't required on clients 51 | ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); 52 | 53 | DynamicConfig config = new DynamicConfig(); 54 | try { 55 | config.addSource(MinecraftAuthMod.class, "game-config", new File("config", "MinecraftAuth.yml")); 56 | config.saveAllDefaults(); 57 | config.loadAll(); 58 | } catch (IOException | ParseException e) { 59 | e.printStackTrace(); 60 | return; 61 | } 62 | 63 | try { 64 | service = new AuthenticationService.Builder() 65 | .withConfig(config) 66 | .withLogger(new me.minecraftauth.plugin.common.abstracted.Logger() { 67 | @Override 68 | public void info(String message) { 69 | logger.info(message); 70 | } 71 | @Override 72 | public void warning(String message) { 73 | logger.warn(message); 74 | } 75 | @Override 76 | public void error(String message) { 77 | logger.error(message); 78 | } 79 | @Override 80 | public void debug(String message) { 81 | logger.debug(message); 82 | } 83 | }) 84 | .build(); 85 | } catch (IOException | ParseException e) { 86 | e.printStackTrace(); 87 | } 88 | } 89 | 90 | @SubscribeEvent 91 | public void onRegisterCommands(RegisterCommandsEvent event) { 92 | new Command(event.getDispatcher()); 93 | ConfigCommand.register(event.getDispatcher()); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/java/me/minecraftauth/forge/server/mixin/LoginMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server.mixin; 18 | 19 | import com.mojang.authlib.GameProfile; 20 | import me.minecraftauth.forge.server.MinecraftAuthMod; 21 | import me.minecraftauth.lib.exception.LookupException; 22 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 23 | import net.minecraft.ChatFormatting; 24 | import net.minecraft.network.chat.Component; 25 | import net.minecraft.network.chat.MutableComponent; 26 | import net.minecraft.server.players.PlayerList; 27 | import net.minecraftforge.server.ServerLifecycleHooks; 28 | import org.spongepowered.asm.mixin.Mixin; 29 | import org.spongepowered.asm.mixin.injection.At; 30 | import org.spongepowered.asm.mixin.injection.Inject; 31 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 32 | 33 | import java.net.SocketAddress; 34 | 35 | @Mixin(PlayerList.class) 36 | public abstract class LoginMixin { 37 | 38 | @Inject(at = @At("RETURN"), method = "canPlayerLogin", cancellable = true) 39 | private void init(SocketAddress address, GameProfile profile, CallbackInfoReturnable returnedMessage) { 40 | if (returnedMessage.getReturnValue() == null) { 41 | // System.out.println("Player " + profile.getName() + "[" + profile.getId() + "] is logging in @ " + address); 42 | 43 | try { 44 | MinecraftAuthMod.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 45 | profile.getId(), 46 | profile.getName(), 47 | ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(profile), 48 | null 49 | ) { 50 | @Override 51 | public void disallow(String message) { 52 | returnedMessage.setReturnValue(errorComponent(message)); 53 | } 54 | }); 55 | } catch (LookupException e) { 56 | returnedMessage.setReturnValue(errorComponent("Unable to verify linked account")); 57 | e.printStackTrace(); 58 | } 59 | } 60 | } 61 | 62 | private MutableComponent errorComponent(String message) { 63 | return Component.literal(message).withStyle(ChatFormatting.RED); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[36,)" 3 | license="Apache License, Version 2.0" 4 | 5 | [[mods]] 6 | modId="minecraftauth" 7 | version="1.19.3" 8 | displayName="Minecraft Authentication" 9 | description="Authenticate players in your Minecraft server to various services" 10 | authors="Minecraft Authentication" 11 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/resources/minecraftauth.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "me.minecraftauth.forge.server.mixin", 4 | "compatibilityLevel": "JAVA_17", 5 | "refmap": "minecraftauth.refmap.json", 6 | "server": [ 7 | "LoginMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | }, 12 | "minVersion": "0.8" 13 | } 14 | -------------------------------------------------------------------------------- /server/forge/1.19.3/src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "MinecraftAuth resources", 4 | "pack_format": 6, 5 | "_comment": "A pack_format of 6 requires json lang files. Note: we require v6 pack meta for all mods." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /server/forge/1.20.1/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { url = 'https://maven.minecraftforge.net' } 5 | maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } 6 | } 7 | dependencies { 8 | classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' 9 | } 10 | } 11 | 12 | plugins { 13 | id 'eclipse' 14 | id 'idea' 15 | id 'net.minecraftforge.gradle' version '[6.0,6.2)' 16 | } 17 | 18 | version = "1.20.1" 19 | group = "me.minecraftauth" 20 | archivesBaseName = "${modid}" 21 | 22 | java.toolchain.languageVersion = JavaLanguageVersion.of(17) 23 | println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" 24 | minecraft { 25 | // snapshot YYYYMMDD Snapshot are built nightly. 26 | // stable # Stables are built at the discretion of the MCP team. 27 | // official MCVersion Official field/method names from Mojang mapping files 28 | mappings channel: 'official', version: '1.20.1' 29 | //makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. 30 | //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') 31 | 32 | runs { 33 | server { 34 | properties 'mixin.env.remapRefMap': 'true' 35 | property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" 36 | workingDirectory project.file('run') 37 | arg "-mixin.config="+archivesBaseName+".mixins.json" 38 | 39 | property 'forge.logging.console.level', 'debug' 40 | 41 | mods { 42 | minecraftauth { 43 | source sourceSets.main 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | repositories{ 51 | mavenCentral() 52 | } 53 | 54 | dependencies { 55 | shaded project(':common') 56 | minecraft 'net.minecraftforge:forge:1.20.1-47.2.20' 57 | annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' 58 | } 59 | 60 | sourceSets { 61 | main.resources.srcDirs += 'src/generated/resources' 62 | } 63 | 64 | jar { 65 | archivesBaseName = 'MinecraftAuth-Forge' 66 | 67 | manifest { 68 | attributes([ 69 | "Specification-Title": "${modid}", 70 | "Specification-Vendor": "minecraftauth", 71 | "Specification-Version": "1", // We are version 1 of ourselves 72 | "Implementation-Title": project.name, 73 | "Implementation-Version": "${version}", 74 | "Implementation-Vendor" :"minecraftauth", 75 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), 76 | "MixinConfigs": "${modid}.mixins.json" 77 | ]) 78 | } 79 | } 80 | 81 | apply plugin: 'org.spongepowered.mixin' 82 | mixin { 83 | add sourceSets.main, "${modid}.refmap.json" 84 | } 85 | 86 | // ensure shadowJar gets re-obfuscated 87 | tasks.shadowJar.dependsOn "reobfJar" 88 | reobf { shadowJar {} } 89 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/java/me/minecraftauth/forge/server/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import com.google.common.base.Suppliers; 20 | import com.mojang.brigadier.CommandDispatcher; 21 | import com.mojang.brigadier.context.CommandContext; 22 | import github.scarsz.configuralize.ParseException; 23 | import net.minecraft.ChatFormatting; 24 | import net.minecraft.commands.CommandSourceStack; 25 | import net.minecraft.commands.Commands; 26 | import net.minecraft.network.chat.Component; 27 | 28 | import java.io.IOException; 29 | 30 | public class Command { 31 | 32 | public Command(CommandDispatcher dispatcher) { 33 | dispatcher.register(Commands.literal("minecraftauth") 34 | .then(Commands.literal("reload") 35 | .requires(cs -> cs.hasPermission(3)) 36 | .executes(context -> reload(context, context.getSource())) 37 | ) 38 | ); 39 | } 40 | 41 | private int reload(CommandContext context, CommandSourceStack source) { 42 | try { 43 | MinecraftAuthMod.getInstance().getService().fullReload(); 44 | source.sendSuccess(Suppliers.ofInstance(Component.literal("MinecraftAuth config reloaded").withStyle(ChatFormatting.RED)), true); 45 | return 1; 46 | } catch (IOException e) { 47 | source.sendFailure(Component.literal("IO exception while reading config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 48 | e.printStackTrace(); 49 | } catch (ParseException e) { 50 | source.sendFailure(Component.literal("Exception while parsing config: " + e.getMessage()).withStyle(ChatFormatting.RED)); 51 | e.printStackTrace(); 52 | } 53 | return -1; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/java/me/minecraftauth/forge/server/MinecraftAuthMod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import github.scarsz.configuralize.ParseException; 21 | import lombok.Getter; 22 | import me.minecraftauth.plugin.common.service.AuthenticationService; 23 | import net.minecraftforge.common.MinecraftForge; 24 | import net.minecraftforge.event.RegisterCommandsEvent; 25 | import net.minecraftforge.eventbus.api.SubscribeEvent; 26 | import net.minecraftforge.fml.IExtensionPoint; 27 | import net.minecraftforge.fml.ModLoadingContext; 28 | import net.minecraftforge.fml.common.Mod; 29 | import net.minecraftforge.network.NetworkConstants; 30 | import net.minecraftforge.server.command.ConfigCommand; 31 | import org.apache.logging.log4j.LogManager; 32 | import org.apache.logging.log4j.Logger; 33 | 34 | import java.io.File; 35 | import java.io.IOException; 36 | 37 | @Mod(MinecraftAuthMod.MOD_ID) 38 | public class MinecraftAuthMod { 39 | 40 | public static final String MOD_ID = "minecraftauth"; 41 | @Getter private static final Logger logger = LogManager.getLogger(); 42 | @Getter private static MinecraftAuthMod instance; 43 | 44 | @Getter private AuthenticationService service; 45 | 46 | public MinecraftAuthMod() { 47 | MinecraftAuthMod.instance = this; 48 | MinecraftForge.EVENT_BUS.register(this); 49 | 50 | // inform mod loader that this is a server-only mod and isn't required on clients 51 | ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); 52 | 53 | DynamicConfig config = new DynamicConfig(); 54 | try { 55 | config.addSource(MinecraftAuthMod.class, "game-config", new File("config", "MinecraftAuth.yml")); 56 | config.saveAllDefaults(); 57 | config.loadAll(); 58 | } catch (IOException | ParseException e) { 59 | e.printStackTrace(); 60 | return; 61 | } 62 | 63 | try { 64 | service = new AuthenticationService.Builder() 65 | .withConfig(config) 66 | .withLogger(new me.minecraftauth.plugin.common.abstracted.Logger() { 67 | @Override 68 | public void info(String message) { 69 | logger.info(message); 70 | } 71 | @Override 72 | public void warning(String message) { 73 | logger.warn(message); 74 | } 75 | @Override 76 | public void error(String message) { 77 | logger.error(message); 78 | } 79 | @Override 80 | public void debug(String message) { 81 | logger.debug(message); 82 | } 83 | }) 84 | .build(); 85 | } catch (IOException | ParseException e) { 86 | e.printStackTrace(); 87 | } 88 | } 89 | 90 | @SubscribeEvent 91 | public void onRegisterCommands(RegisterCommandsEvent event) { 92 | new Command(event.getDispatcher()); 93 | ConfigCommand.register(event.getDispatcher()); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/java/me/minecraftauth/forge/server/mixin/LoginMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.forge.server.mixin; 18 | 19 | import com.mojang.authlib.GameProfile; 20 | import me.minecraftauth.forge.server.MinecraftAuthMod; 21 | import me.minecraftauth.lib.exception.LookupException; 22 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 23 | import net.minecraft.ChatFormatting; 24 | import net.minecraft.network.chat.Component; 25 | import net.minecraft.network.chat.MutableComponent; 26 | import net.minecraft.server.players.PlayerList; 27 | import net.minecraftforge.server.ServerLifecycleHooks; 28 | import org.spongepowered.asm.mixin.Mixin; 29 | import org.spongepowered.asm.mixin.injection.At; 30 | import org.spongepowered.asm.mixin.injection.Inject; 31 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 32 | 33 | import java.net.SocketAddress; 34 | 35 | @Mixin(PlayerList.class) 36 | public abstract class LoginMixin { 37 | 38 | @Inject(at = @At("RETURN"), method = "canPlayerLogin", cancellable = true) 39 | private void init(SocketAddress address, GameProfile profile, CallbackInfoReturnable returnedMessage) { 40 | if (returnedMessage.getReturnValue() == null) { 41 | // System.out.println("Player " + profile.getName() + "[" + profile.getId() + "] is logging in @ " + address); 42 | 43 | try { 44 | MinecraftAuthMod.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 45 | profile.getId(), 46 | profile.getName(), 47 | ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(profile), 48 | null 49 | ) { 50 | @Override 51 | public void disallow(String message) { 52 | returnedMessage.setReturnValue(errorComponent(message)); 53 | } 54 | }); 55 | } catch (LookupException e) { 56 | returnedMessage.setReturnValue(errorComponent("Unable to verify linked account")); 57 | e.printStackTrace(); 58 | } 59 | } 60 | } 61 | 62 | private MutableComponent errorComponent(String message) { 63 | return Component.literal(message).withStyle(ChatFormatting.RED); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[36,)" 3 | license="Apache License, Version 2.0" 4 | 5 | [[mods]] 6 | modId="minecraftauth" 7 | version="1.20.1" 8 | displayName="Minecraft Authentication" 9 | description="Authenticate players in your Minecraft server to various services" 10 | authors="Minecraft Authentication" 11 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/resources/minecraftauth.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "me.minecraftauth.forge.server.mixin", 4 | "compatibilityLevel": "JAVA_17", 5 | "refmap": "minecraftauth.refmap.json", 6 | "server": [ 7 | "LoginMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | }, 12 | "minVersion": "0.8" 13 | } 14 | -------------------------------------------------------------------------------- /server/forge/1.20.1/src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "MinecraftAuth resources", 4 | "pack_format": 6, 5 | "_comment": "A pack_format of 6 requires json lang files. Note: we require v6 pack meta for all mods." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /server/sponge/build.gradle: -------------------------------------------------------------------------------- 1 | import org.spongepowered.gradle.plugin.config.PluginLoaders 2 | 3 | plugins { 4 | id 'org.spongepowered.gradle.plugin' version '1.1.0' 5 | } 6 | 7 | repositories { 8 | maven { 9 | url 'https://repo.spongepowered.org/maven/' 10 | } 11 | } 12 | 13 | dependencies { 14 | shaded project(':common') 15 | compileOnly 'org.spongepowered:spongeapi:7.3.0' 16 | } 17 | 18 | jar { 19 | archivesBaseName = 'MinecraftAuth-Sponge' 20 | } 21 | 22 | sponge { 23 | apiVersion('7.3.0') 24 | plugin('minecraftauth') { 25 | loader(PluginLoaders.JAVA_PLAIN) 26 | mainClass('me.minecraftauth.plugin.sponge') 27 | version(project.version) 28 | description('Authenticate players in your Minecraft server to various services') 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /server/sponge/src/main/java/me/minecraftauth/plugin/sponge/MinecraftAuthSponge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.sponge; 18 | 19 | import com.google.inject.Inject; 20 | import github.scarsz.configuralize.DynamicConfig; 21 | import github.scarsz.configuralize.ParseException; 22 | import lombok.Getter; 23 | import me.minecraftauth.plugin.common.service.AuthenticationService; 24 | import org.slf4j.Logger; 25 | import org.spongepowered.api.Sponge; 26 | import org.spongepowered.api.config.ConfigDir; 27 | import org.spongepowered.api.event.Listener; 28 | import org.spongepowered.api.event.game.state.GameStartedServerEvent; 29 | import org.spongepowered.api.plugin.Plugin; 30 | 31 | import java.io.File; 32 | import java.io.IOException; 33 | import java.nio.file.Path; 34 | 35 | @Plugin( 36 | id = "minecraftauth", 37 | name = "MinecraftAuth", 38 | url = "https://minecraftauth.me", 39 | description = "Authenticate players in your Minecraft server to various services", 40 | authors = {"MinecraftAuth"} 41 | ) 42 | public class MinecraftAuthSponge { 43 | 44 | @Getter private static MinecraftAuthSponge instance; 45 | @Getter private AuthenticationService service; 46 | 47 | @Inject private Logger logger; 48 | @Inject @ConfigDir(sharedRoot = true) private Path sharedConfigDir; 49 | 50 | @Listener 51 | public void onServerStart(GameStartedServerEvent event) { 52 | MinecraftAuthSponge.instance = this; 53 | 54 | DynamicConfig config = new DynamicConfig(); 55 | try { 56 | config.addSource(MinecraftAuthSponge.class, "game-config", new File(sharedConfigDir.toFile(), "MinecraftAuth.yml")); 57 | config.saveAllDefaults(); 58 | config.loadAll(); 59 | } catch (IOException | ParseException e) { 60 | e.printStackTrace(); 61 | return; 62 | } 63 | 64 | try { 65 | service = new AuthenticationService.Builder() 66 | .withConfig(config) 67 | .withLogger(new SpongeLogger(config, logger)) 68 | .build(); 69 | } catch (IOException | ParseException e) { 70 | e.printStackTrace(); 71 | return; 72 | } 73 | 74 | Sponge.getEventManager().registerListeners(this, new SpongeEventsListener()); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /server/sponge/src/main/java/me/minecraftauth/plugin/sponge/SpongeEventsListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.sponge; 18 | 19 | import me.minecraftauth.lib.exception.LookupException; 20 | import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent; 21 | import org.spongepowered.api.event.Listener; 22 | import org.spongepowered.api.event.Order; 23 | import org.spongepowered.api.event.network.ClientConnectionEvent; 24 | import org.spongepowered.api.text.Text; 25 | import org.spongepowered.api.text.format.TextColors; 26 | 27 | public class SpongeEventsListener { 28 | 29 | @Listener(order = Order.FIRST) 30 | public void onClientConnectionLogin(ClientConnectionEvent.Login event) { 31 | try { 32 | MinecraftAuthSponge.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent( 33 | event.getProfile().getUniqueId(), 34 | event.getProfile().getName().orElse(""), 35 | false, // sponge has no concept of "ops", 36 | null 37 | ) { 38 | @Override 39 | public void disallow(String message) { 40 | event.setCancelled(true); 41 | event.setMessage(Text.builder(message).color(TextColors.RED)); 42 | } 43 | }); 44 | } catch (LookupException e) { 45 | event.setCancelled(true); 46 | event.setMessage(Text.builder("Unable to verify linked account").color(TextColors.RED)); 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /server/sponge/src/main/java/me/minecraftauth/plugin/sponge/SpongeLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 MinecraftAuth.me 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.minecraftauth.plugin.sponge; 18 | 19 | import github.scarsz.configuralize.DynamicConfig; 20 | import me.minecraftauth.plugin.common.abstracted.Logger; 21 | 22 | public class SpongeLogger implements Logger { 23 | 24 | private final DynamicConfig config; 25 | private final org.slf4j.Logger logger; 26 | 27 | public SpongeLogger(DynamicConfig config, org.slf4j.Logger logger) { 28 | this.config = config; 29 | this.logger = logger; 30 | } 31 | 32 | @Override 33 | public void info(String message) { 34 | logger.info(message); 35 | } 36 | 37 | @Override 38 | public void warning(String message) { 39 | logger.warn(message); 40 | } 41 | 42 | @Override 43 | public void error(String message) { 44 | logger.error(message); 45 | } 46 | 47 | @Override 48 | public void debug(String message) { 49 | if (config.getBooleanElse("Debug", false)) { 50 | info("[DEBUG] " + message); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | maven { 5 | name = 'MinecraftForge' 6 | url = 'https://maven.minecraftforge.net/' 7 | } 8 | maven { 9 | name = 'Fabric' 10 | url = 'https://maven.fabricmc.net/' 11 | } 12 | } 13 | } 14 | 15 | rootProject.name = 'MinecraftAuthentication-Plugin' 16 | 17 | include 'common' 18 | include 'server:bukkit', 'server:sponge', 'server:forge:1.16.5', 'server:forge:1.18.2', 'server:forge:1.19.3', 'server:forge:1.20.1' 19 | include 'proxy:bungeecord', 'proxy:velocity' 20 | --------------------------------------------------------------------------------