├── bungee ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── minekube │ │ │ └── connect │ │ │ ├── util │ │ │ ├── BungeeUserAudience.java │ │ │ └── BungeePlatformUtils.java │ │ │ ├── listener │ │ │ └── BungeeListenerRegistration.java │ │ │ ├── module │ │ │ └── BungeeListenerModule.java │ │ │ ├── BungeePlugin.java │ │ │ └── inject │ │ │ └── bungee │ │ │ └── ConnectIoHandlerWrapper.java │ │ └── resources │ │ └── plugin.yml └── build.gradle.kts ├── .vscode └── settings.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .idea ├── codeStyles │ └── codeStyleConfig.xml └── copyright │ ├── profiles_settings.xml │ └── GeyserMC.xml ├── core ├── src │ └── main │ │ ├── proto │ │ ├── README.md │ │ └── com │ │ │ └── minekube │ │ │ └── connect │ │ │ └── v1alpha1 │ │ │ └── tunnel_service.proto │ │ ├── resources │ │ ├── languages │ │ │ └── texts │ │ │ │ └── en_US.properties │ │ ├── proxy-config.yml │ │ └── config.yml │ │ └── java │ │ └── com │ │ └── minekube │ │ └── connect │ │ ├── platform │ │ ├── util │ │ │ └── PlatformUtils.java │ │ ├── listener │ │ │ └── ListenerRegistration.java │ │ └── command │ │ │ ├── TranslatableMessage.java │ │ │ └── ConnectCommand.java │ │ ├── command │ │ ├── util │ │ │ ├── PermissionDefault.java │ │ │ └── Permission.java │ │ ├── CommonCommandMessage.java │ │ └── TestCommand.java │ │ ├── skin │ │ ├── SkinApplier.java │ │ └── SkinData.java │ │ ├── config │ │ ├── ProxyConnectConfig.java │ │ ├── ConfigHolder.java │ │ └── ConnectConfig.java │ │ ├── api │ │ └── ProxyConnectApi.java │ │ ├── watch │ │ ├── Watcher.java │ │ └── SessionProposal.java │ │ ├── addon │ │ ├── debug │ │ │ ├── State.java │ │ │ ├── ChannelInDebugHandler.java │ │ │ └── ChannelOutDebugHandler.java │ │ ├── AddonManagerAddon.java │ │ ├── packethandler │ │ │ ├── ChannelInPacketHandler.java │ │ │ └── ChannelOutPacketHandler.java │ │ ├── data │ │ │ └── CommonDataHandler.java │ │ ├── PacketHandlerAddon.java │ │ └── DebugAddon.java │ │ ├── util │ │ ├── backoff │ │ │ ├── NanoClock.java │ │ │ └── BackOff.java │ │ ├── InjectorHolder.java │ │ └── Constants.java │ │ ├── module │ │ ├── WatcherModule.java │ │ ├── PostInitializeModule.java │ │ ├── ConfigLoadedModule.java │ │ ├── ServerCommonModule.java │ │ ├── CommandModule.java │ │ └── ProxyCommonModule.java │ │ ├── network │ │ └── netty │ │ │ ├── DefaultChannelPipelinePublic.java │ │ │ ├── LocalChannelWithSessionContext.java │ │ │ ├── LocalServerChannelWrapper.java │ │ │ ├── LocalChannelWrapper.java │ │ │ └── TunnelHandler.java │ │ ├── player │ │ ├── audience │ │ │ └── ProfileAudience.java │ │ ├── ConnectPlayerImpl.java │ │ └── ConnectCommandPreprocessor.java │ │ ├── register │ │ ├── AddonRegister.java │ │ ├── ListenerRegister.java │ │ └── CommandRegister.java │ │ ├── tunnel │ │ └── TunnelConn.java │ │ └── logger │ │ └── JavaUtilConnectLogger.java └── build.gradle.kts ├── spigot ├── src │ └── main │ │ ├── resources │ │ └── plugin.yml │ │ └── java │ │ └── com │ │ └── minekube │ │ └── connect │ │ ├── util │ │ ├── SpigotPlatformUtils.java │ │ ├── ProxyUtils.java │ │ └── SpigotVersionSpecificMethods.java │ │ ├── listener │ │ ├── SpigotListenerRegistration.java │ │ ├── PaperProfileListener.java │ │ └── SpigotListener.java │ │ ├── module │ │ ├── PaperListenerModule.java │ │ ├── SpigotListenerModule.java │ │ └── SpigotAddonModule.java │ │ ├── SpigotPlatform.java │ │ └── addon │ │ └── data │ │ └── SpigotDataAddon.java └── build.gradle.kts ├── velocity ├── src │ └── main │ │ ├── resources │ │ └── velocity-plugin.json │ │ └── java │ │ └── com │ │ └── minekube │ │ └── connect │ │ ├── util │ │ ├── VelocityPlatformUtils.java │ │ └── VelocitySkinApplier.java │ │ ├── listener │ │ └── VelocityListenerRegistration.java │ │ ├── module │ │ └── VelocityListenerModule.java │ │ ├── inject │ │ └── velocity │ │ │ └── ConnectWatchedSingleThreadIoEventLoop.java │ │ ├── VelocityPlugin.java │ │ └── logger │ │ └── Slf4JConnectLogger.java └── build.gradle.kts ├── api ├── build.gradle.kts └── src │ └── main │ └── java │ └── com │ └── minekube │ └── connect │ └── api │ ├── player │ ├── Auth.java │ ├── GameProfile.java │ └── ConnectPlayer.java │ ├── packet │ ├── PacketHandler.java │ └── PacketHandlers.java │ ├── InstanceHolder.java │ ├── ConnectApi.java │ ├── inject │ ├── InjectorAddon.java │ └── PlatformInjector.java │ └── util │ └── TriFunction.java ├── LICENSE ├── .github └── workflows │ ├── pullrequest.yml │ └── release.yml ├── ruleset.xml ├── settings.gradle.kts └── gradlew.bat /bungee/src/main/java/com/minekube/connect/util/BungeeUserAudience.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.compile.nullAnalysis.mode": "automatic" 3 | } 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minekube/connect-java/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.configureondemand=true 2 | org.gradle.caching=true 3 | org.gradle.parallel=true 4 | version=2.2.3-SNAPSHOT -------------------------------------------------------------------------------- /bungee/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ${name} 2 | description: ${description} 3 | version: ${version} 4 | author: ${author} 5 | main: com.minekube.connect.BungeePlugin -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /core/src/main/proto/README.md: -------------------------------------------------------------------------------- 1 | ProtoBuf definitions are taken from Connect main 2 | repo https://github.com/minekube/connect/tree/main/api. We keep them in sync manually until we have 3 | a more clean way, though changes in our proto are rare. -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /spigot/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ${name} 2 | description: ${description} 3 | version: ${version} 4 | author: ${author} 5 | website: ${url} 6 | main: com.minekube.connect.SpigotPlugin 7 | api-version: 1.13 8 | folia-supported: false # TODO support folia 9 | softdepend: [ProtocolSupport] -------------------------------------------------------------------------------- /velocity/src/main/resources/velocity-plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "${id}", 3 | "name": "${name}", 4 | "version": "${version}", 5 | "description": "${description}", 6 | "url": "${url}", 7 | "authors": [ 8 | "${author}" 9 | ], 10 | "main": "com.minekube.connect.VelocityPlugin" 11 | } -------------------------------------------------------------------------------- /core/src/main/resources/languages/texts/en_US.properties: -------------------------------------------------------------------------------- 1 | connect.core.finish=Took {0}ms to boot Connect 2 | 3 | connect.ingame.disconnect_name=Connect tunneled player {0} disconnected 4 | connect.ingame.login_name=Connect tunneled player logged in as {0} (UUID: {1}) 5 | 6 | connect.watch.started=Started watching for new player sessions -------------------------------------------------------------------------------- /api/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 2 | 3 | dependencies { 4 | api("com.google.code.gson", "gson", Versions.gsonVersion) 5 | 6 | compileOnly("io.netty", "netty-transport", Versions.nettyVersion) 7 | } 8 | 9 | tasks { 10 | named("jar") { 11 | archiveClassifier.set("") 12 | } 13 | named("shadowJar") { 14 | archiveClassifier.set("shaded") 15 | } 16 | } -------------------------------------------------------------------------------- /bungee/build.gradle.kts: -------------------------------------------------------------------------------- 1 | var bungeeVersion = "1.21-R0.1-SNAPSHOT" 2 | var gsonVersion = "2.8.0" 3 | var guavaVersion = "21.0" 4 | 5 | dependencies { 6 | api(projects.core) 7 | implementation("cloud.commandframework", "cloud-bungee", Versions.cloudVersion) 8 | } 9 | 10 | relocate("com.google.inject") 11 | relocate("com.google.protobuf") 12 | relocate("net.kyori") 13 | relocate("cloud.commandframework") 14 | // used in cloud 15 | relocate("io.leangen.geantyref") 16 | // since 1.20 17 | relocate("org.yaml") 18 | 19 | // these dependencies are already present on the platform 20 | provided("net.md-5", "bungeecord-proxy", bungeeVersion) 21 | provided("com.google.code.gson", "gson", gsonVersion) 22 | provided("com.google.guava", "guava", guavaVersion) 23 | -------------------------------------------------------------------------------- /core/src/main/proto/com/minekube/connect/v1alpha1/tunnel_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package minekube.connect.v1alpha1; 4 | 5 | service TunnelService { 6 | // Tunnel the connection of a session. 7 | rpc Tunnel(stream TunnelRequest) returns (stream TunnelResponse); 8 | } 9 | 10 | message TunnelRequest { 11 | // This is a raw client bound chunk of data. 12 | // 13 | // The data is just a chunk of the stream and it should 14 | // never be assumed it contains a complete single packet. 15 | bytes data = 1; 16 | } 17 | 18 | message TunnelResponse { 19 | // This is a raw server bound chunk of data. 20 | // 21 | // The data is just a chunk of the stream and it should 22 | // never be assumed it contains a complete single packet. 23 | bytes data = 1; 24 | } 25 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/util/SpigotPlatformUtils.java: -------------------------------------------------------------------------------- 1 | package com.minekube.connect.util; 2 | 3 | import com.minekube.connect.platform.util.PlatformUtils; 4 | import org.bukkit.Bukkit; 5 | 6 | public class SpigotPlatformUtils extends PlatformUtils { 7 | @Override 8 | public AuthType authType() { 9 | if (Bukkit.getOnlineMode()) { 10 | return AuthType.ONLINE; 11 | } 12 | return ProxyUtils.isProxyData() ? AuthType.PROXIED : AuthType.OFFLINE; 13 | } 14 | 15 | @Override 16 | public String minecraftVersion() { 17 | return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0]; 18 | } 19 | 20 | @Override 21 | public String serverImplementationName() { 22 | return Bukkit.getServer().getName(); 23 | } 24 | 25 | @Override 26 | public int getPlayerCount() { 27 | return Bukkit.getServer().getOnlinePlayers().size(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/util/VelocityPlatformUtils.java: -------------------------------------------------------------------------------- 1 | package com.minekube.connect.util; 2 | 3 | import com.google.inject.Inject; 4 | import com.minekube.connect.platform.util.PlatformUtils; 5 | import com.velocitypowered.api.network.ProtocolVersion; 6 | import com.velocitypowered.api.proxy.ProxyServer; 7 | 8 | public final class VelocityPlatformUtils extends PlatformUtils { 9 | @Inject 10 | private ProxyServer server; 11 | 12 | @Override 13 | public AuthType authType() { 14 | return server.getConfiguration().isOnlineMode() ? AuthType.ONLINE : AuthType.OFFLINE; 15 | } 16 | 17 | @Override 18 | public String minecraftVersion() { 19 | return ProtocolVersion.MAXIMUM_VERSION.getMostRecentSupportedVersion(); 20 | } 21 | 22 | @Override 23 | public String serverImplementationName() { 24 | return server.getVersion().getName(); 25 | } 26 | 27 | @Override 28 | public int getPlayerCount() { 29 | return server.getPlayerCount(); 30 | } 31 | } -------------------------------------------------------------------------------- /velocity/build.gradle.kts: -------------------------------------------------------------------------------- 1 | var velocityVersion = "3.2.0-SNAPSHOT" 2 | var log4jVersion = "2.11.2" 3 | var gsonVersion = "2.8.8" 4 | var guavaVersion = "25.1-jre" 5 | 6 | java { 7 | // For Velocity API 8 | sourceCompatibility = JavaVersion.VERSION_11 9 | targetCompatibility = JavaVersion.VERSION_11 10 | } 11 | 12 | dependencies { 13 | api(projects.core) 14 | implementation("cloud.commandframework", "cloud-velocity", Versions.cloudVersion) 15 | } 16 | 17 | relocate("cloud.commandframework") 18 | // used in cloud 19 | relocate("io.leangen.geantyref") 20 | 21 | 22 | // these dependencies are already present on the platform 23 | provided("com.google.code.gson", "gson", gsonVersion) 24 | provided("com.google.guava", "guava", guavaVersion) 25 | provided("com.google.inject", "guice", Versions.guiceVersion) 26 | provided("org.yaml", "snakeyaml", Versions.snakeyamlVersion) // included in Configurate 27 | provided("com.velocitypowered", "velocity-api", velocityVersion) 28 | provided("org.apache.logging.log4j", "log4j-core", log4jVersion) 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2022 Minekube 4 | Copyright (c) 2019-2022 GeyserMC 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/platform/util/PlatformUtils.java: -------------------------------------------------------------------------------- 1 | package com.minekube.connect.platform.util; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | 5 | @RequiredArgsConstructor 6 | public abstract class PlatformUtils { 7 | /** 8 | * Returns the authentication type used on the platform 9 | * 10 | * @return the authentication type 11 | */ 12 | public abstract AuthType authType(); 13 | 14 | /** 15 | * Returns the Minecraft version the server is based on (or the most recent supported version 16 | * for proxy platforms) 17 | * 18 | * @return the Minecraft version 19 | */ 20 | public abstract String minecraftVersion(); 21 | 22 | 23 | /** 24 | * Returns the platform name 25 | * 26 | * @return the platform name 27 | */ 28 | public abstract String serverImplementationName(); 29 | 30 | /** 31 | * Returns the amount of players currently online, 32 | * including Connect players. 33 | * 34 | * @return the amount of players online 35 | */ 36 | public abstract int getPlayerCount(); 37 | 38 | public enum AuthType { 39 | ONLINE, 40 | PROXIED, 41 | OFFLINE 42 | } 43 | } -------------------------------------------------------------------------------- /.github/workflows/pullrequest.yml: -------------------------------------------------------------------------------- 1 | name: Build Pull Request 2 | 3 | on: [ pull_request ] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout repository and submodules 12 | uses: actions/checkout@v4 13 | with: 14 | submodules: recursive 15 | 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v2 18 | with: 19 | distribution: 'temurin' 20 | java-version: '17' 21 | cache: 'gradle' 22 | 23 | - name: Build with Maven 24 | run: ./gradlew build 25 | 26 | - name: Archive artifacts (Floodgate Bungee) 27 | uses: actions/upload-artifact@v4 28 | if: success() 29 | with: 30 | name: Floodgate Bungee 31 | path: bungee/build/libs/connect-bungee.jar 32 | 33 | - name: Archive artifacts (Floodgate Spigot) 34 | uses: actions/upload-artifact@v4 35 | if: success() 36 | with: 37 | name: Floodgate Spigot 38 | path: spigot/build/libs/connect-spigot.jar 39 | 40 | - name: Archive artifacts (Floodgate Velocity) 41 | uses: actions/upload-artifact@v4 42 | if: success() 43 | with: 44 | name: Floodgate Velocity 45 | path: velocity/build/libs/connect-velocity.jar 46 | -------------------------------------------------------------------------------- /core/src/main/resources/proxy-config.yml: -------------------------------------------------------------------------------- 1 | # The endpoint name of this server/proxy instance registered on startup with the Connect network. 2 | # Default is a random string. You can change it to a custom endpoint name. 3 | endpoint: ${endpoint} 4 | 5 | # This setting is only relevant if you want to allow cracked players to join. 6 | # If left blank, the correct mode will be securely detected automatically. 7 | allow-offline-mode-players: false 8 | 9 | # The default locale for Connect. By default, Connect uses the system locale 10 | #default-locale: en_US 11 | 12 | # Super endpoints are authorized to control this endpoint via Connect API. 13 | # e.g. disconnect players from this endpoint, send messages to players, etc. 14 | # 15 | # You can add as many super endpoint names as you want. 16 | #super-endpoints: 17 | # - pvp-endpoint 18 | # - someones-hub 19 | 20 | # bStats is a stat tracker that is entirely anonymous and tracks only basic information 21 | # about Connect, such as how many people are online, how many servers are using Connect, 22 | # what OS is being used, etc. You can learn more about bStats here: https://bstats.org/. 23 | metrics: 24 | # If metrics should be disabled. 25 | disabled: false 26 | # The unique id that should be consistent for a server/proxy. 27 | uuid: ${metrics.uuid} 28 | 29 | # Do not change this 30 | config-version: 1 31 | -------------------------------------------------------------------------------- /.idea/copyright/GeyserMC.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /core/src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | # The endpoint name of this server/proxy instance registered on startup with the Connect network. 2 | # Default is a random string. You can change it to a custom endpoint name. 3 | endpoint: ${endpoint} 4 | 5 | # This setting is only relevant if you want to allow cracked players to join. 6 | # This should not be irritated by offline-mode servers behind an online-mode proxy, keep this setting disabled. 7 | # If left blank, the correct mode will be securely detected automatically. 8 | allow-offline-mode-players: false 9 | 10 | # Super endpoints are authorized to control this endpoint via Connect API. 11 | # e.g. disconnect players from this endpoint, send messages to players, etc. 12 | # 13 | # You can add as many super endpoint names as you want. 14 | #super-endpoints: 15 | # - pvp-endpoint 16 | # - someones-hub 17 | 18 | # The default locale for Connect. By default, Connect uses the system locale 19 | #default-locale: en_US 20 | 21 | # bStats is a stat tracker that is entirely anonymous and tracks only basic information 22 | # about Connect, such as how many people are online, how many servers are using Connect, 23 | # what OS is being used, etc. You can learn more about bStats here: https://bstats.org/. 24 | metrics: 25 | # If metrics should be disabled. 26 | disabled: false 27 | # The unique id that should be consistent for a server/proxy. 28 | uuid: ${metrics.uuid} 29 | 30 | # Do not change this 31 | config-version: 1 32 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/command/util/PermissionDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.command.util; 27 | 28 | public enum PermissionDefault { 29 | TRUE, FALSE, OP, NOT_OP 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/skin/SkinApplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.skin; 27 | 28 | import com.minekube.connect.api.player.ConnectPlayer; 29 | 30 | public interface SkinApplier { 31 | void applySkin(ConnectPlayer connectPlayer, SkinData skinData); 32 | } 33 | -------------------------------------------------------------------------------- /spigot/build.gradle.kts: -------------------------------------------------------------------------------- 1 | var authlibVersion = "1.5.21" 2 | var guavaVersion = "31.1-jre" 3 | var gsonVersion = "2.8.5" 4 | 5 | //java { 6 | // For Folia 7 | // targetCompatibility = JavaVersion.VERSION_1_8 8 | // toolchain { 9 | // languageVersion.set(JavaLanguageVersion.of(17)) 10 | // } 11 | //} 12 | 13 | dependencies { 14 | api(projects.core) 15 | 16 | implementation("cloud.commandframework", "cloud-bukkit", Versions.cloudVersion) 17 | // hack to make pre 1.12 work 18 | implementation("com.google.guava", "guava", guavaVersion) 19 | 20 | compileOnlyApi("dev.folia", "folia-api", Versions.spigotVersion) { 21 | attributes { 22 | attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17) 23 | } 24 | } 25 | } 26 | 27 | relocate("com.google.inject") 28 | relocate("com.google.protobuf") 29 | relocate("net.kyori") 30 | relocate("cloud.commandframework") 31 | relocate("io.leangen.geantyref") // used in cloud 32 | // hack to make pre 1.12 work 33 | relocate("com.google.common") 34 | relocate("com.google.guava") 35 | // hack to make (old versions? of) Paper work 36 | relocate("it.unimi") 37 | // since 1.20 38 | relocate("org.yaml") 39 | 40 | // these dependencies are already present on the platform 41 | provided("com.mojang", "authlib", authlibVersion) 42 | provided("io.netty", "netty-transport", Versions.nettyVersion) 43 | provided("io.netty", "netty-codec", Versions.nettyVersion) 44 | provided("com.google.code.gson", "gson", gsonVersion) 45 | provided("com.viaversion", "viaversion-bukkit", Versions.viaVersionVersion) 46 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/config/ProxyConnectConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.config; 27 | 28 | import lombok.Getter; 29 | 30 | /** 31 | * The configuration used by proxy platforms, currently Velocity and BungeeCord. 32 | */ 33 | @Getter 34 | public final class ProxyConnectConfig extends ConnectConfig { 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/api/ProxyConnectApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api; 27 | 28 | import com.minekube.connect.api.logger.ConnectLogger; 29 | 30 | 31 | public final class ProxyConnectApi extends SimpleConnectApi { 32 | 33 | public ProxyConnectApi(ConnectLogger logger) { 34 | super(logger); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/watch/Watcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.watch; 27 | 28 | public interface Watcher { 29 | 30 | void onProposal(SessionProposal proposal); 31 | 32 | void onError(final Throwable t); 33 | 34 | default void onCompleted() { 35 | } 36 | 37 | default void onOpen() { 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/debug/State.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.debug; 27 | 28 | public enum State { 29 | HANDSHAKE, STATUS, LOGIN, PLAY; 30 | 31 | private static final State[] VALUES = values(); 32 | 33 | public static State getById(int id) { 34 | return id < VALUES.length ? VALUES[id] : null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/util/backoff/NanoClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. 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 distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package com.minekube.connect.util.backoff; 16 | 17 | /** 18 | * Nano clock which can be used to measure elapsed time in nanoseconds. 19 | * 20 | *

The default system implementation can be accessed at {@link #SYSTEM}. Alternative 21 | * implementations may be used for testing. 22 | * 23 | * @author Yaniv Inbar 24 | * @since 1.14 25 | */ 26 | public interface NanoClock { 27 | 28 | /** 29 | * Returns the current value of the most precise available system timer, in nanoseconds for use 30 | * to measure elapsed time, to match the behavior of {@link System#nanoTime()}. 31 | */ 32 | long nanoTime(); 33 | 34 | /** 35 | * Provides the default System implementation of a nano clock by using {@link 36 | * System#nanoTime()}. 37 | */ 38 | NanoClock SYSTEM = 39 | new NanoClock() { 40 | public long nanoTime() { 41 | return System.nanoTime(); 42 | } 43 | }; 44 | } -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/util/InjectorHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.util; 27 | 28 | import com.google.inject.Injector; 29 | 30 | public class InjectorHolder { 31 | private Injector injector; 32 | 33 | public Injector get() { 34 | return injector; 35 | } 36 | 37 | public void set(Injector injector) { 38 | this.injector = injector; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/player/Auth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.api.player; 27 | 28 | 29 | import lombok.Data; 30 | 31 | /** 32 | * @see Proto 33 | */ 34 | @Data 35 | public class Auth { 36 | private final boolean passthrough; 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/WatcherModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.minekube.connect.register.WatcherRegister; 30 | 31 | public class WatcherModule extends AbstractModule { 32 | 33 | @Override 34 | protected void configure() { 35 | bind(WatcherRegister.class).asEagerSingleton(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/network/netty/DefaultChannelPipelinePublic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.network.netty; 27 | 28 | import io.netty.channel.Channel; 29 | import io.netty.channel.DefaultChannelPipeline; 30 | 31 | /** 32 | * Exists solely to make DefaultChannelPipeline's protected constructor public 33 | */ 34 | public class DefaultChannelPipelinePublic extends DefaultChannelPipeline { 35 | public DefaultChannelPipelinePublic(Channel channel) { 36 | super(channel); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/player/GameProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.api.player; 27 | 28 | import java.util.List; 29 | import java.util.UUID; 30 | import lombok.Data; 31 | 32 | @Data 33 | public class GameProfile { 34 | private final String username; 35 | private final UUID uniqueId; 36 | private final List properties; 37 | 38 | @Data 39 | public static class Property { 40 | private final String name; 41 | private final String value; 42 | private final String signature; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/PostInitializeModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Module; 30 | import lombok.RequiredArgsConstructor; 31 | 32 | @RequiredArgsConstructor 33 | public final class PostInitializeModule extends AbstractModule { 34 | private final Module[] postInitializeModules; 35 | 36 | @Override 37 | protected void configure() { 38 | for (Module module : postInitializeModules) { 39 | install(module); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/network/netty/LocalChannelWithSessionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.network.netty; 27 | 28 | import com.minekube.connect.network.netty.LocalSession.Context; 29 | import io.netty.channel.local.LocalChannel; 30 | import lombok.AccessLevel; 31 | import lombok.Getter; 32 | import lombok.Setter; 33 | 34 | /** 35 | * Client -> server storing session context on a channel. 36 | */ 37 | public class LocalChannelWithSessionContext extends LocalChannel { 38 | @Getter 39 | @Setter(AccessLevel.PACKAGE) 40 | private Context context; 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/player/audience/ProfileAudience.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.player.audience; 27 | 28 | import java.util.UUID; 29 | import lombok.Getter; 30 | import lombok.experimental.Accessors; 31 | import org.checkerframework.checker.nullness.qual.Nullable; 32 | 33 | @Getter 34 | @Accessors(fluent = true) 35 | public final class ProfileAudience { 36 | private final @Nullable UUID uuid; 37 | private final @Nullable String username; 38 | 39 | public ProfileAudience(@Nullable UUID uuid, @Nullable String username) { 40 | this.uuid = uuid; 41 | this.username = username; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/util/ProxyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.util; 27 | 28 | public final class ProxyUtils { 29 | 30 | public static boolean isProxyData() { 31 | return isBungeeData() || isVelocitySupport(); 32 | } 33 | 34 | public static boolean isBungeeData() { 35 | return ReflectionUtils.castedStaticBooleanValue(ClassNames.BUNGEE); 36 | } 37 | 38 | public static boolean isVelocitySupport() { 39 | if (ClassNames.PAPER_VELOCITY_SUPPORT == null) { 40 | return false; 41 | } 42 | 43 | return ClassNames.PAPER_VELOCITY_SUPPORT.getAsBoolean(); 44 | } 45 | } -------------------------------------------------------------------------------- /bungee/src/main/java/com/minekube/connect/util/BungeePlatformUtils.java: -------------------------------------------------------------------------------- 1 | package com.minekube.connect.util; 2 | 3 | import com.minekube.connect.platform.util.PlatformUtils; 4 | import java.lang.reflect.Field; 5 | import java.util.List; 6 | import net.md_5.bungee.api.ProxyServer; 7 | import net.md_5.bungee.protocol.ProtocolConstants; 8 | 9 | @SuppressWarnings("ConstantConditions") 10 | public final class BungeePlatformUtils extends PlatformUtils { 11 | private static final String LATEST_SUPPORTED_VERSION; 12 | private final ProxyServer proxyServer = ProxyServer.getInstance(); 13 | 14 | static { 15 | int protocolNumber = -1; 16 | String versionName = ""; 17 | 18 | for (Field field : ProtocolConstants.class.getFields()) { 19 | if (!field.getName().startsWith("MINECRAFT_")) { 20 | continue; 21 | } 22 | 23 | int fieldValue = ReflectionUtils.castedStaticValue(field); 24 | if (fieldValue > protocolNumber) { 25 | protocolNumber = fieldValue; 26 | versionName = field.getName().substring(10).replace('_', '.'); 27 | } 28 | } 29 | 30 | if (protocolNumber == -1) { 31 | List versions = ProtocolConstants.SUPPORTED_VERSIONS; 32 | versionName = versions.get(versions.size() - 1); 33 | } 34 | LATEST_SUPPORTED_VERSION = versionName; 35 | } 36 | 37 | @Override 38 | public AuthType authType() { 39 | return proxyServer.getConfig().isOnlineMode() ? AuthType.ONLINE : AuthType.OFFLINE; 40 | } 41 | 42 | @Override 43 | public String minecraftVersion() { 44 | return LATEST_SUPPORTED_VERSION; 45 | } 46 | 47 | @Override 48 | public String serverImplementationName() { 49 | return proxyServer.getName(); 50 | } 51 | 52 | @Override 53 | public int getPlayerCount() { 54 | return proxyServer.getOnlineCount(); 55 | } 56 | } -------------------------------------------------------------------------------- /ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | Connect Code ruleset 9 | 10 | 11 | 12 | .*/ConnectConfig.* 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/listener/VelocityListenerRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.listener; 27 | 28 | import com.minekube.connect.VelocityPlugin; 29 | import com.minekube.connect.platform.listener.ListenerRegistration; 30 | import com.velocitypowered.api.event.EventManager; 31 | import lombok.RequiredArgsConstructor; 32 | 33 | @RequiredArgsConstructor 34 | public final class VelocityListenerRegistration implements ListenerRegistration { 35 | private final EventManager eventManager; 36 | private final VelocityPlugin plugin; 37 | 38 | @Override 39 | public void register(Object listener) { 40 | eventManager.register(plugin, listener); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/register/AddonRegister.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.register; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.Injector; 30 | import com.minekube.connect.api.inject.InjectorAddon; 31 | import com.minekube.connect.api.inject.PlatformInjector; 32 | import java.util.Set; 33 | 34 | public final class AddonRegister { 35 | @Inject private Injector guice; 36 | @Inject private PlatformInjector injector; 37 | 38 | @Inject 39 | public void registerAddons(Set addons) { 40 | for (InjectorAddon addon : addons) { 41 | guice.injectMembers(addon); 42 | injector.addAddon(addon); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/platform/listener/ListenerRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.platform.listener; 27 | 28 | /** 29 | * This class is responsible for registering listeners to the listener manager of the platform that 30 | * is currently in use. Unfortunately due to the major differences between the platforms (when it 31 | * comes to listeners) every Floodgate platform has to implement their own listeners. 32 | * 33 | * @param the platform-specific listener class 34 | */ 35 | public interface ListenerRegistration { 36 | /** 37 | * This method will register the specified listener. 38 | * 39 | * @param listener the listener to register 40 | */ 41 | void register(T listener); 42 | } 43 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/listener/SpigotListenerRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.listener; 27 | 28 | import com.google.inject.Inject; 29 | import com.minekube.connect.platform.listener.ListenerRegistration; 30 | import lombok.RequiredArgsConstructor; 31 | import org.bukkit.Bukkit; 32 | import org.bukkit.event.Listener; 33 | import org.bukkit.plugin.java.JavaPlugin; 34 | 35 | @RequiredArgsConstructor(onConstructor = @__(@Inject)) 36 | public final class SpigotListenerRegistration implements ListenerRegistration { 37 | private final JavaPlugin plugin; 38 | 39 | @Override 40 | public void register(Listener listener) { 41 | Bukkit.getServer().getPluginManager().registerEvents(listener, plugin); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/skin/SkinData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.skin; 27 | 28 | import com.google.gson.JsonObject; 29 | import lombok.Getter; 30 | import lombok.RequiredArgsConstructor; 31 | 32 | @Getter 33 | @RequiredArgsConstructor 34 | public class SkinData { 35 | private final String value; 36 | private final String signature; 37 | 38 | public static SkinData from(JsonObject data) { 39 | if (data.has("signature") && !data.get("signature").isJsonNull()) { 40 | return new SkinData( 41 | data.get("value").getAsString(), 42 | data.get("signature").getAsString() 43 | ); 44 | } 45 | return new SkinData(data.get("value").getAsString(), null); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/packet/PacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api.packet; 27 | 28 | import io.netty.channel.ChannelHandlerContext; 29 | 30 | /** 31 | * For advanced users only! You shouldn't play with this unless you know what you're doing. 32 | */ 33 | public interface PacketHandler { 34 | /** 35 | * Called when a registered packet has been seen. 36 | * 37 | * @param ctx the channel handler context of the connection 38 | * @param packet the packet instance 39 | * @param serverbound if the packet is serverbound 40 | * @return the packet it should forward. Can be null or a different packet / instance 41 | */ 42 | Object handle(ChannelHandlerContext ctx, Object packet, boolean serverbound); 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/config/ConfigHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.config; 27 | 28 | public class ConfigHolder { 29 | private ConnectConfig config; 30 | 31 | public boolean has() { 32 | return config != null; 33 | } 34 | 35 | public boolean isProxy() { 36 | return config instanceof ProxyConnectConfig; 37 | } 38 | 39 | public ConnectConfig get() { 40 | return config; 41 | } 42 | 43 | public ProxyConnectConfig getAsProxy() { 44 | return getAs(); 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | public T getAs() { 49 | return (T) config; 50 | } 51 | 52 | public void set(ConnectConfig config) { 53 | this.config = config; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /bungee/src/main/java/com/minekube/connect/listener/BungeeListenerRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.listener; 27 | 28 | import com.google.inject.Inject; 29 | import com.minekube.connect.BungeePlugin; 30 | import com.minekube.connect.platform.listener.ListenerRegistration; 31 | import lombok.RequiredArgsConstructor; 32 | import net.md_5.bungee.api.ProxyServer; 33 | import net.md_5.bungee.api.plugin.Listener; 34 | 35 | @RequiredArgsConstructor(onConstructor = @__(@Inject)) 36 | public final class BungeeListenerRegistration implements ListenerRegistration { 37 | private final BungeePlugin plugin; 38 | 39 | @Override 40 | public void register(Listener listener) { 41 | ProxyServer.getInstance().getPluginManager().registerListener(plugin, listener); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/module/PaperListenerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.Singleton; 29 | import com.google.inject.TypeLiteral; 30 | import com.google.inject.multibindings.ProvidesIntoSet; 31 | import com.minekube.connect.listener.PaperProfileListener; 32 | import com.minekube.connect.register.ListenerRegister; 33 | import org.bukkit.event.Listener; 34 | 35 | public class PaperListenerModule extends SpigotListenerModule { 36 | @Override 37 | protected void configure() { 38 | bind(new TypeLiteral>() {}).asEagerSingleton(); 39 | } 40 | 41 | @Singleton 42 | @ProvidesIntoSet 43 | public Listener paperProfileListener() { 44 | return new PaperProfileListener(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/module/VelocityListenerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.TypeLiteral; 31 | import com.google.inject.multibindings.ProvidesIntoSet; 32 | import com.minekube.connect.listener.VelocityListener; 33 | import com.minekube.connect.register.ListenerRegister; 34 | 35 | public final class VelocityListenerModule extends AbstractModule { 36 | @Override 37 | protected void configure() { 38 | bind(new TypeLiteral>() {}).asEagerSingleton(); 39 | } 40 | 41 | @Singleton 42 | @ProvidesIntoSet 43 | public Object velocityListener() { 44 | return new VelocityListener(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/player/ConnectPlayerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.player; 27 | 28 | import com.minekube.connect.api.player.Auth; 29 | import com.minekube.connect.api.player.ConnectPlayer; 30 | import com.minekube.connect.api.player.GameProfile; 31 | import java.util.UUID; 32 | import lombok.Data; 33 | 34 | @Data 35 | public final class ConnectPlayerImpl implements ConnectPlayer { 36 | private final String sessionId; 37 | private final GameProfile gameProfile; 38 | private final Auth auth; 39 | private final String languageTag; 40 | 41 | @Override 42 | public UUID getUniqueId() { 43 | return gameProfile.getUniqueId(); 44 | } 45 | 46 | @Override 47 | public String getUsername() { 48 | return gameProfile.getUsername(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | @file:Suppress("UnstableApiUsage") 2 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 3 | 4 | dependencyResolutionManagement { 5 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 6 | repositories { 7 | // Geyser, Cumulus etc. TODO remove 8 | maven("https://repo.opencollab.dev/maven-releases") { 9 | mavenContent { releasesOnly() } 10 | } 11 | maven("https://repo.opencollab.dev/maven-snapshots") { 12 | mavenContent { snapshotsOnly() } 13 | } 14 | 15 | // Paper, Velocity 16 | // maven("https://papermc.io/repo/repository/maven-public") 17 | maven("https://repo.papermc.io/repository/maven-public") 18 | // Spigot 19 | maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots") { 20 | mavenContent { snapshotsOnly() } 21 | } 22 | 23 | // BungeeCord 24 | maven("https://oss.sonatype.org/content/repositories/snapshots") { 25 | mavenContent { snapshotsOnly() } 26 | } 27 | 28 | maven("https://libraries.minecraft.net") { 29 | name = "minecraft" 30 | mavenContent { releasesOnly() } 31 | } 32 | 33 | mavenCentral() 34 | 35 | maven("https://repo.viaversion.com") { 36 | name = "viaversion-repo" 37 | } 38 | 39 | maven("https://jitpack.io") { 40 | content { includeGroupByRegex("com\\.github\\..*") } 41 | } 42 | 43 | } 44 | } 45 | 46 | pluginManagement { 47 | repositories { 48 | gradlePluginPortal() 49 | } 50 | repositories { 51 | maven("https://plugins.gradle.org/m2/") 52 | } 53 | plugins { 54 | id("net.kyori.blossom") version "1.2.0" 55 | id("net.kyori.indra") 56 | id("net.kyori.indra.git") 57 | id("com.google.protobuf") version "0.8.18" 58 | } 59 | includeBuild("build-logic") 60 | } 61 | 62 | rootProject.name = "connect-parent" 63 | 64 | include(":api") 65 | include(":core") 66 | include(":bungee") 67 | include(":spigot") 68 | include(":velocity") -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/module/SpigotListenerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.TypeLiteral; 31 | import com.google.inject.multibindings.ProvidesIntoSet; 32 | import com.minekube.connect.listener.SpigotListener; 33 | import com.minekube.connect.register.ListenerRegister; 34 | import org.bukkit.event.Listener; 35 | 36 | public class SpigotListenerModule extends AbstractModule { 37 | @Override 38 | protected void configure() { 39 | bind(new TypeLiteral>() {}).asEagerSingleton(); 40 | } 41 | 42 | @Singleton 43 | @ProvidesIntoSet 44 | public Listener spigotListener() { 45 | return new SpigotListener(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /bungee/src/main/java/com/minekube/connect/module/BungeeListenerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.TypeLiteral; 31 | import com.google.inject.multibindings.ProvidesIntoSet; 32 | import com.minekube.connect.listener.BungeeListener; 33 | import com.minekube.connect.register.ListenerRegister; 34 | import net.md_5.bungee.api.plugin.Listener; 35 | 36 | public final class BungeeListenerModule extends AbstractModule { 37 | @Override 38 | protected void configure() { 39 | bind(new TypeLiteral>() {}).asEagerSingleton(); 40 | } 41 | 42 | @Singleton 43 | @ProvidesIntoSet 44 | public Listener bungeeListener() { 45 | return new BungeeListener(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/tunnel/TunnelConn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.tunnel; 27 | 28 | public abstract class TunnelConn { 29 | 30 | public interface Handler { 31 | void onReceive(byte[] data); 32 | 33 | void onError(Throwable t); 34 | 35 | default void onClose() { 36 | } 37 | } 38 | 39 | public abstract void write(byte[] data); 40 | 41 | public abstract void close(Throwable t); 42 | 43 | public void close() { 44 | close(null); 45 | } 46 | 47 | /** 48 | * Indicated whether this tunnel was ever opened at some point. 49 | * Does not indicate the current active state. 50 | * 51 | * @return whether the tunnel was successfully opened at some point in time 52 | */ 53 | public boolean opened() { 54 | return false; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/ConfigLoadedModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Provides; 30 | import com.google.inject.Singleton; 31 | import com.minekube.connect.config.ConnectConfig; 32 | import com.minekube.connect.config.ProxyConnectConfig; 33 | import lombok.RequiredArgsConstructor; 34 | 35 | @RequiredArgsConstructor 36 | public final class ConfigLoadedModule extends AbstractModule { 37 | private final ConnectConfig config; 38 | 39 | @Override 40 | protected void configure() { 41 | if (config instanceof ProxyConnectConfig) { 42 | bind(ProxyConnectConfig.class).toInstance((ProxyConnectConfig) config); 43 | } 44 | } 45 | 46 | @Provides 47 | @Singleton 48 | public ConnectConfig config() { 49 | return config; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/register/ListenerRegister.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.register; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.Injector; 30 | import com.minekube.connect.platform.listener.ListenerRegistration; 31 | import java.util.Set; 32 | 33 | public final class ListenerRegister { 34 | private final ListenerRegistration registration; 35 | private final Injector guice; 36 | 37 | @Inject 38 | public ListenerRegister(ListenerRegistration registration, Injector guice) { 39 | this.registration = registration; 40 | this.guice = guice; 41 | } 42 | 43 | @Inject 44 | public void registerListeners(Set foundListeners) { 45 | for (T listener : foundListeners) { 46 | guice.injectMembers(listener); 47 | registration.register(listener); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/AddonManagerAddon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon; 27 | 28 | import com.google.inject.Inject; 29 | import com.minekube.connect.api.inject.InjectorAddon; 30 | import com.minekube.connect.inject.CommonPlatformInjector; 31 | import io.netty.channel.Channel; 32 | 33 | public final class AddonManagerAddon implements InjectorAddon { 34 | @Inject private CommonPlatformInjector injector; 35 | 36 | @Override 37 | public void onInject(Channel channel, boolean toServer) { 38 | channel.closeFuture().addListener(listener -> { 39 | injector.channelClosedCall(channel); 40 | injector.removeInjectedClient(channel); 41 | }); 42 | } 43 | 44 | @Override 45 | public void onRemoveInject(Channel channel) { 46 | } 47 | 48 | @Override 49 | public boolean shouldInject() { 50 | return true; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/util/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.util; 27 | 28 | public final class Constants { 29 | public static final String VERSION = "${connectVersion}"; 30 | public static final int BUILD_NUMBER = Integer.parseInt("${buildNumber}"); 31 | public static final String GIT_BRANCH = "${branch}"; 32 | public static final int METRICS_ID = 14794; 33 | 34 | public static final char COLOR_CHAR = '§'; 35 | 36 | public static final boolean DEBUG_MODE = false; 37 | public static final boolean PRINT_ALL_PACKETS = false; 38 | 39 | 40 | private static final String API_BASE_URL = "s://api.geysermc.org"; 41 | public static final String HEALTH_URL = "http" + API_BASE_URL + "/health"; 42 | 43 | public static final int HANDSHAKE_PACKET_ID = 0; 44 | public static final int LOGIN_SUCCESS_PACKET_ID = 2; 45 | public static final int SET_COMPRESSION_PACKET_ID = 3; 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/ServerCommonModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.Provides; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.name.Named; 31 | import com.minekube.connect.api.SimpleConnectApi; 32 | import com.minekube.connect.api.logger.ConnectLogger; 33 | import com.minekube.connect.config.ConnectConfig; 34 | import java.nio.file.Path; 35 | 36 | public final class ServerCommonModule extends CommonModule { 37 | public ServerCommonModule(Path dataDirectory) { 38 | super(dataDirectory); 39 | } 40 | 41 | @Provides 42 | @Singleton 43 | @Named("configClass") 44 | public Class configClass() { 45 | return ConnectConfig.class; 46 | } 47 | 48 | @Provides 49 | @Singleton 50 | public SimpleConnectApi api(ConnectLogger logger) { 51 | return new SimpleConnectApi(logger); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/CommandModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.multibindings.ProvidesIntoSet; 31 | import com.minekube.connect.command.TestCommand; 32 | import com.minekube.connect.command.main.MainCommand; 33 | import com.minekube.connect.platform.command.ConnectCommand; 34 | import com.minekube.connect.register.CommandRegister; 35 | 36 | public class CommandModule extends AbstractModule { 37 | @Override 38 | protected void configure() { 39 | bind(CommandRegister.class).asEagerSingleton(); 40 | } 41 | 42 | @Singleton 43 | @ProvidesIntoSet 44 | public ConnectCommand testCommand() { 45 | return new TestCommand(); 46 | } 47 | 48 | @Singleton 49 | @ProvidesIntoSet 50 | public ConnectCommand mainCommand() { 51 | return new MainCommand(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/player/ConnectCommandPreprocessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.player; 27 | 28 | import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; 29 | import cloud.commandframework.execution.preprocessor.CommandPreprocessor; 30 | import com.minekube.connect.platform.command.CommandUtil; 31 | import lombok.RequiredArgsConstructor; 32 | import org.checkerframework.checker.nullness.qual.NonNull; 33 | 34 | /** 35 | * Command preprocessor which decorated incoming {@link cloud.commandframework.context.CommandContext} 36 | * with Connect specific objects 37 | * 38 | * @param Command sender type 39 | * @since 2.0 40 | */ 41 | @RequiredArgsConstructor 42 | public final class ConnectCommandPreprocessor implements CommandPreprocessor { 43 | private final CommandUtil commandUtil; 44 | 45 | @Override 46 | public void accept(@NonNull CommandPreprocessingContext context) { 47 | context.getCommandContext().store("CommandUtil", commandUtil); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/util/VelocitySkinApplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.util; 27 | 28 | import com.minekube.connect.api.player.ConnectPlayer; 29 | import com.minekube.connect.skin.SkinApplier; 30 | import com.minekube.connect.skin.SkinData; 31 | import com.velocitypowered.api.proxy.ProxyServer; 32 | import com.velocitypowered.api.util.GameProfile.Property; 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | import lombok.RequiredArgsConstructor; 36 | 37 | @RequiredArgsConstructor 38 | public class VelocitySkinApplier implements SkinApplier { 39 | private final ProxyServer server; 40 | 41 | @Override 42 | public void applySkin(ConnectPlayer connectPlayer, SkinData skinData) { 43 | server.getPlayer(connectPlayer.getUniqueId()).ifPresent(player -> { 44 | List properties = new ArrayList<>(player.getGameProfileProperties()); 45 | properties.add(new Property("textures", skinData.getValue(), skinData.getSignature())); 46 | player.setGameProfileProperties(properties); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.google.protobuf.gradle.* 2 | import net.kyori.blossom.BlossomExtension 3 | 4 | plugins { 5 | idea // used to let Intellij recognize protobuf generated sources 6 | id("net.kyori.blossom") 7 | id("com.google.protobuf") 8 | } 9 | 10 | dependencies { 11 | api(projects.api) 12 | api("org.geysermc.configutils", "configutils", Versions.configUtilsVersion) 13 | 14 | api("com.google.inject", "guice", Versions.guiceVersion) 15 | api("cloud.commandframework", "cloud-core", Versions.cloudVersion) 16 | api("org.bstats", "bstats-base", Versions.bstatsVersion) 17 | 18 | implementation("com.squareup.okhttp3:okhttp:4.9.3") 19 | runtimeOnly("io.grpc", "grpc-netty-shaded", Versions.gRPCVersion) 20 | implementation("io.grpc", "grpc-protobuf", Versions.gRPCVersion) 21 | implementation("io.grpc", "grpc-stub", Versions.gRPCVersion) 22 | implementation("javax.annotation", "javax.annotation-api", "1.3.2") 23 | } 24 | 25 | // present on all platforms 26 | provided("io.netty", "netty-transport", Versions.nettyVersion) 27 | provided("io.netty", "netty-codec", Versions.nettyVersion) 28 | provided("io.netty", "netty-transport-native-unix-common", Versions.nettyVersion) 29 | 30 | relocate("org.bstats") 31 | 32 | configure { 33 | val constantsFile = "src/main/java/com/minekube/connect/util/Constants.java" 34 | replaceToken("\${connectVersion}", fullVersion(), constantsFile) 35 | replaceToken("\${branch}", branchName(), constantsFile) 36 | replaceToken("\${buildNumber}", buildNumber(), constantsFile) 37 | } 38 | 39 | protobuf { 40 | protoc { 41 | // The artifact spec for the Protobuf Compiler 42 | artifact = "com.google.protobuf:protoc:${Versions.protocVersion}" 43 | } 44 | plugins { 45 | // Optional: an artifact spec for a protoc plugin, with "grpc" as 46 | // the identifier, which can be referred to in the "plugins" 47 | // container of the "generateProtoTasks" closure. 48 | id("grpc") { 49 | artifact = "io.grpc:protoc-gen-grpc-java:${Versions.gRPCVersion}" 50 | } 51 | } 52 | generateProtoTasks { 53 | ofSourceSet("main").forEach { 54 | it.plugins { 55 | // Apply the "grpc" plugin whose spec is defined above, without options. 56 | id("grpc") 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/InstanceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api; 27 | 28 | import com.minekube.connect.api.inject.PlatformInjector; 29 | import com.minekube.connect.api.packet.PacketHandlers; 30 | import java.util.UUID; 31 | import lombok.Getter; 32 | 33 | public final class InstanceHolder { 34 | @Getter private static ConnectApi api; 35 | 36 | @Getter private static PlatformInjector injector; 37 | @Getter private static PacketHandlers packetHandlers; 38 | private static UUID storedKey; 39 | 40 | public static boolean set( 41 | ConnectApi connectApi, 42 | PlatformInjector platformInjector, 43 | PacketHandlers packetHandlers, 44 | UUID key) { 45 | 46 | if (storedKey != null) { 47 | if (!storedKey.equals(key)) { 48 | return false; 49 | } 50 | } else { 51 | storedKey = key; 52 | } 53 | 54 | api = connectApi; 55 | injector = platformInjector; 56 | InstanceHolder.packetHandlers = packetHandlers; 57 | return true; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/SpigotPlatform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.Injector; 30 | import com.google.inject.Module; 31 | import com.minekube.connect.api.ConnectApi; 32 | import com.minekube.connect.api.inject.PlatformInjector; 33 | import com.minekube.connect.api.logger.ConnectLogger; 34 | import org.bukkit.Bukkit; 35 | import org.bukkit.plugin.java.JavaPlugin; 36 | 37 | public final class SpigotPlatform extends ConnectPlatform { 38 | @Inject private JavaPlugin plugin; 39 | 40 | @Inject 41 | public SpigotPlatform(ConnectApi api, PlatformInjector platformInjector, 42 | ConnectLogger logger, Injector injector) { 43 | super(api, platformInjector, logger, injector); 44 | } 45 | 46 | @Override 47 | public boolean enable(Module... postInitializeModules) { 48 | boolean success = super.enable(postInitializeModules); 49 | if (!success) { 50 | Bukkit.getPluginManager().disablePlugin(plugin); 51 | return false; 52 | } 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/command/CommonCommandMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.command; 27 | 28 | import com.minekube.connect.platform.command.TranslatableMessage; 29 | import lombok.Getter; 30 | 31 | /** 32 | * Messages (or part of messages) that are used in two or more commands and thus are 'commonly 33 | * used' 34 | */ 35 | @Getter 36 | public enum CommonCommandMessage implements TranslatableMessage { 37 | LINKING_DISABLED("connect.commands.linking_disabled"), 38 | NOT_A_PLAYER("connect.commands.not_a_player"), 39 | CHECK_CONSOLE("connect.commands.check_console"), 40 | IS_LINKED_ERROR("connect.commands.is_linked_error"), 41 | LOCAL_LINKING_NOTICE("connect.commands.local_linking_notice"), 42 | GLOBAL_LINKING_NOTICE("connect.commands.global_linking_notice"); 43 | 44 | private final String rawMessage; 45 | private final String[] translateParts; 46 | 47 | CommonCommandMessage(String rawMessage) { 48 | this.rawMessage = rawMessage; 49 | this.translateParts = rawMessage.split(" "); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return getRawMessage(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/network/netty/LocalServerChannelWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.network.netty; 27 | 28 | import io.netty.channel.local.LocalChannel; 29 | import io.netty.channel.local.LocalServerChannel; 30 | 31 | /** 32 | * If the incoming channel is an instance of LocalChannelWithRemoteAddress, this server creates a 33 | * LocalChannelWrapper for the other end and attaches the spoofed remote address 34 | */ 35 | public class LocalServerChannelWrapper extends LocalServerChannel { 36 | @Override 37 | protected LocalChannel newLocalChannel(LocalChannel peer) { 38 | // LocalChannel here should be an instance of LocalChannelWithSessionContext, 39 | // which we can use to set the "remote address" on the other end 40 | // and access related session data from the channel 41 | if (peer instanceof LocalChannelWithSessionContext) { 42 | LocalChannelWrapper channel = new LocalChannelWrapper(this, peer); 43 | channel.wrapper().setContext(((LocalChannelWithSessionContext) peer).getContext()); 44 | return channel; 45 | } 46 | return super.newLocalChannel(peer); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/watch/SessionProposal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.watch; 27 | 28 | import java.util.concurrent.atomic.AtomicReference; 29 | import java.util.function.Consumer; 30 | import lombok.Getter; 31 | import lombok.RequiredArgsConstructor; 32 | import lombok.Setter; 33 | import minekube.connect.v1alpha1.WatchServiceOuterClass.Session; 34 | 35 | @RequiredArgsConstructor 36 | public class SessionProposal { 37 | 38 | @Getter 39 | private final Session session; 40 | private final Consumer reject; 41 | 42 | private final AtomicReference state = new AtomicReference<>(State.ACCEPTED); 43 | 44 | public enum State { 45 | ACCEPTED, 46 | REJECTED 47 | } 48 | 49 | public void reject(com.google.rpc.Status reason) { 50 | if (state.compareAndSet(State.ACCEPTED, State.REJECTED)) { 51 | reject.accept(reason); 52 | } 53 | } 54 | 55 | public State getState() { 56 | return state.get(); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "SessionProposal{" + 62 | "session=" + session + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/module/ProxyCommonModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.Provides; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.name.Named; 31 | import com.minekube.connect.api.ProxyConnectApi; 32 | import com.minekube.connect.api.SimpleConnectApi; 33 | import com.minekube.connect.api.logger.ConnectLogger; 34 | import com.minekube.connect.config.ConnectConfig; 35 | import com.minekube.connect.config.ProxyConnectConfig; 36 | import java.nio.file.Path; 37 | 38 | public final class ProxyCommonModule extends CommonModule { 39 | public ProxyCommonModule(Path dataDirectory) { 40 | super(dataDirectory); 41 | } 42 | 43 | @Override 44 | protected void configure() { 45 | super.configure(); 46 | bind(SimpleConnectApi.class).to(ProxyConnectApi.class); 47 | } 48 | 49 | @Provides 50 | @Singleton 51 | @Named("configClass") 52 | public Class configClass() { 53 | return ProxyConnectConfig.class; 54 | } 55 | 56 | @Provides 57 | @Singleton 58 | public ProxyConnectApi proxyApi( 59 | ConnectLogger logger 60 | ) { 61 | return new ProxyConnectApi(logger); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/ConnectApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api; 27 | 28 | import com.minekube.connect.api.player.ConnectPlayer; 29 | import java.util.Collection; 30 | import java.util.UUID; 31 | 32 | public interface ConnectApi { 33 | /** 34 | * Returns the Connect API instance. 35 | */ 36 | static ConnectApi getInstance() { 37 | return InstanceHolder.getApi(); 38 | } 39 | 40 | /** 41 | * Returns all the online Connect players. 42 | */ 43 | Collection getPlayers(); 44 | 45 | /** 46 | * Returns the number of Connect players who are currently online. 47 | */ 48 | int getPlayerCount(); 49 | 50 | /** 51 | * Method to determine if the given online player is a bedrock player 52 | * 53 | * @param uuid The uuid of the online player 54 | * @return true if the given online player is tunneled by Connect 55 | */ 56 | boolean isConnectPlayer(UUID uuid); 57 | 58 | /** 59 | * Get info about the given player. 60 | * 61 | * @param uuid the uuid of the online player 62 | * @return ConnectPlayer if the given uuid is a player tunneled by Connect 63 | */ 64 | ConnectPlayer getPlayer(UUID uuid); 65 | } 66 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/command/util/Permission.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.command.util; 27 | 28 | import static com.minekube.connect.command.util.PermissionDefault.OP; 29 | import static com.minekube.connect.command.util.PermissionDefault.TRUE; 30 | 31 | public enum Permission { 32 | COMMAND_MAIN("connect.command.connect", TRUE), 33 | COMMAND_MAIN_FIREWALL(COMMAND_MAIN, "firewall", OP), 34 | COMMAND_LINK("connect.command.linkaccount", TRUE), 35 | COMMAND_UNLINK("connect.command.unlinkaccount", TRUE), 36 | COMMAND_WHITELIST("connect.command.fwhitelist", OP), 37 | 38 | NEWS_RECEIVE("connect.news.receive", OP); 39 | 40 | private final String permission; 41 | private final PermissionDefault defaultValue; 42 | 43 | Permission(String permission, PermissionDefault defaultValue) { 44 | this.permission = permission; 45 | this.defaultValue = defaultValue; 46 | } 47 | 48 | Permission(Permission parent, String child, PermissionDefault defaultValue) { 49 | this(parent.get() + "." + child, defaultValue); 50 | } 51 | 52 | public String get() { 53 | return permission; 54 | } 55 | 56 | public PermissionDefault defaultValue() { 57 | return defaultValue; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/packethandler/ChannelInPacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.packethandler; 27 | 28 | import com.minekube.connect.api.util.TriFunction; 29 | import com.minekube.connect.packet.PacketHandlersImpl; 30 | import io.netty.channel.ChannelHandlerContext; 31 | import io.netty.channel.SimpleChannelInboundHandler; 32 | 33 | public class ChannelInPacketHandler extends SimpleChannelInboundHandler { 34 | private final PacketHandlersImpl packetHandlers; 35 | private final boolean toServer; 36 | 37 | public ChannelInPacketHandler(PacketHandlersImpl packetHandlers, boolean toServer) { 38 | this.packetHandlers = packetHandlers; 39 | this.toServer = toServer; 40 | } 41 | 42 | @Override 43 | protected void channelRead0(ChannelHandlerContext ctx, Object msg) { 44 | Object packet = msg; 45 | for (TriFunction consumer : 46 | packetHandlers.getPacketHandlers(msg.getClass())) { 47 | 48 | Object res = consumer.apply(ctx, msg, toServer); 49 | if (!res.equals(msg)) { 50 | packet = res; 51 | } 52 | } 53 | 54 | ctx.fireChannelRead(packet); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/command/TestCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.command; 27 | 28 | import cloud.commandframework.Command; 29 | import cloud.commandframework.CommandManager; 30 | import cloud.commandframework.context.CommandContext; 31 | import com.minekube.connect.api.ConnectApi; 32 | import com.minekube.connect.config.ConnectConfig; 33 | import com.minekube.connect.platform.command.ConnectCommand; 34 | import com.minekube.connect.player.UserAudience; 35 | import com.minekube.connect.util.Constants; 36 | 37 | public class TestCommand implements ConnectCommand { 38 | @Override 39 | public Command buildCommand(CommandManager commandManager) { 40 | return commandManager.commandBuilder("connect-test") 41 | .senderType(UserAudience.class) 42 | .handler(this::execute) 43 | .build(); 44 | } 45 | 46 | @Override 47 | public void execute(CommandContext context) { 48 | int players = ConnectApi.getInstance().getPlayers().size(); 49 | context.getSender().sendMessage(String.valueOf(players)); 50 | } 51 | 52 | @Override 53 | public boolean shouldRegister(ConnectConfig config) { 54 | return Constants.DEBUG_MODE; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/packethandler/ChannelOutPacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.packethandler; 27 | 28 | import com.minekube.connect.api.util.TriFunction; 29 | import com.minekube.connect.packet.PacketHandlersImpl; 30 | import io.netty.channel.ChannelHandlerContext; 31 | import io.netty.handler.codec.MessageToMessageEncoder; 32 | import java.util.List; 33 | 34 | public class ChannelOutPacketHandler extends MessageToMessageEncoder { 35 | private final PacketHandlersImpl packetHandlers; 36 | private final boolean toServer; 37 | 38 | public ChannelOutPacketHandler(PacketHandlersImpl packetHandlers, boolean toServer) { 39 | this.packetHandlers = packetHandlers; 40 | this.toServer = toServer; 41 | } 42 | 43 | @Override 44 | protected void encode(ChannelHandlerContext ctx, Object msg, List out) { 45 | Object packet = msg; 46 | for (TriFunction consumer : 47 | packetHandlers.getPacketHandlers(msg.getClass())) { 48 | 49 | Object res = consumer.apply(ctx, msg, toServer); 50 | if (!res.equals(msg)) { 51 | packet = res; 52 | } 53 | } 54 | 55 | out.add(packet); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/player/ConnectPlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.api.player; 27 | 28 | import java.util.UUID; 29 | 30 | public interface ConnectPlayer { 31 | /** 32 | * Returns the Minecraft uuid of that player. 33 | */ 34 | UUID getUniqueId(); 35 | 36 | /** 37 | * Returns the Minecraft username of that player. 38 | */ 39 | String getUsername(); 40 | 41 | /** 42 | * Returns the game profile of that player. 43 | */ 44 | GameProfile getGameProfile(); 45 | 46 | /** 47 | * Returns the language tag of the player. If it is unknown it returns an empty string. 48 | */ 49 | String getLanguageTag(); 50 | 51 | /** 52 | * Returns the session id sent by Connect WatchService. 53 | */ 54 | String getSessionId(); 55 | 56 | /** 57 | * Returns the authentication mode of the player connection. 58 | */ 59 | Auth getAuth(); 60 | 61 | /** 62 | * Casts the ConnectPlayer instance to a class that extends ConnectPlayer. 63 | * 64 | * @param The instance to cast to. 65 | * @return The ConnectPlayer casted to the given class 66 | * @throws ClassCastException when it can't cast the instance to the given class 67 | */ 68 | default T as(Class clazz) { 69 | return clazz.cast(this); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/platform/command/TranslatableMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.platform.command; 27 | 28 | import com.minekube.connect.util.LanguageManager; 29 | 30 | /** 31 | * TranslatableMessage is the interface for a message that can be translated. Messages are generally 32 | * implemented using enums. 33 | */ 34 | public interface TranslatableMessage { 35 | /** 36 | * Returns the message attached to the enum identifier 37 | */ 38 | String getRawMessage(); 39 | 40 | /** 41 | * Returns the parts of this message (getRawMessage() split on " ") 42 | */ 43 | String[] getTranslateParts(); 44 | 45 | default String translateMessage(LanguageManager manager, String locale, Object... args) { 46 | String[] translateParts = getTranslateParts(); 47 | if (translateParts.length == 1) { 48 | return manager.getString(getRawMessage(), locale, args); 49 | } 50 | // todo only works when one section has arguments 51 | StringBuilder builder = new StringBuilder(); 52 | for (int i = 0; i < translateParts.length; i++) { 53 | builder.append(manager.getString(translateParts[i], locale, args)); 54 | if (translateParts.length != i + 1) { 55 | builder.append(' '); 56 | } 57 | } 58 | return builder.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/module/SpigotAddonModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.module; 27 | 28 | import com.google.inject.AbstractModule; 29 | import com.google.inject.Singleton; 30 | import com.google.inject.multibindings.ProvidesIntoSet; 31 | import com.minekube.connect.addon.AddonManagerAddon; 32 | import com.minekube.connect.addon.DebugAddon; 33 | import com.minekube.connect.addon.PacketHandlerAddon; 34 | import com.minekube.connect.addon.data.SpigotDataAddon; 35 | import com.minekube.connect.api.inject.InjectorAddon; 36 | import com.minekube.connect.register.AddonRegister; 37 | 38 | public final class SpigotAddonModule extends AbstractModule { 39 | @Override 40 | protected void configure() { 41 | bind(AddonRegister.class).asEagerSingleton(); 42 | } 43 | 44 | @Singleton 45 | @ProvidesIntoSet 46 | public InjectorAddon managerAddon() { 47 | return new AddonManagerAddon(); 48 | } 49 | 50 | @Singleton 51 | @ProvidesIntoSet 52 | public InjectorAddon dataAddon() { 53 | return new SpigotDataAddon(); 54 | } 55 | 56 | @Singleton 57 | @ProvidesIntoSet 58 | public InjectorAddon debugAddon() { 59 | return new DebugAddon(); 60 | } 61 | 62 | @Singleton 63 | @ProvidesIntoSet 64 | public InjectorAddon packetHandlerAddon() { 65 | return new PacketHandlerAddon(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/data/CommonDataHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.data; 27 | 28 | import com.minekube.connect.config.ConnectConfig; 29 | import io.netty.channel.ChannelHandlerContext; 30 | import io.netty.channel.ChannelInboundHandlerAdapter; 31 | import lombok.RequiredArgsConstructor; 32 | 33 | @RequiredArgsConstructor 34 | public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter { 35 | protected final ConnectConfig config; 36 | protected ChannelHandlerContext ctx; 37 | 38 | protected abstract boolean channelRead(Object packet) throws Exception; 39 | 40 | @Override 41 | public void handlerAdded(ChannelHandlerContext ctx) throws Exception { 42 | super.handlerAdded(ctx); 43 | this.ctx = ctx; 44 | } 45 | 46 | @Override 47 | public void channelRead(ChannelHandlerContext ctx, Object packet) { 48 | try { 49 | if (channelRead(packet)) { 50 | ctx.fireChannelRead(packet); 51 | } 52 | } catch (Exception exception) { 53 | exception.printStackTrace(); 54 | ctx.close(); 55 | } 56 | } 57 | 58 | @Override 59 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 60 | super.exceptionCaught(ctx, cause); 61 | if (config.isDebug()) { 62 | cause.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/platform/command/ConnectCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.platform.command; 27 | 28 | import cloud.commandframework.Command; 29 | import cloud.commandframework.CommandManager; 30 | import cloud.commandframework.context.CommandContext; 31 | import com.minekube.connect.config.ConnectConfig; 32 | import com.minekube.connect.player.UserAudience; 33 | 34 | /** 35 | * The base class for every Connect command. 36 | */ 37 | public interface ConnectCommand { 38 | /** 39 | * Called by the CommandRegister when it wants you to build the command which he can add. 40 | * 41 | * @param commandManager the manager to create a command 42 | * @return the command to register 43 | */ 44 | Command buildCommand(CommandManager commandManager); 45 | 46 | /** 47 | * Called when the command created in {@link #buildCommand(CommandManager)} is executed. 48 | * 49 | * @param context the context of the executed command 50 | */ 51 | void execute(CommandContext context); 52 | 53 | /** 54 | * Called by the CommandRegister to check if the command should be added given the config. 55 | * 56 | * @param config the config to check if a command should be added 57 | * @return true if it should be added 58 | */ 59 | default boolean shouldRegister(ConnectConfig config) { 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/listener/PaperProfileListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.listener; 27 | 28 | import com.destroystokyo.paper.event.profile.PreFillProfileEvent; 29 | import com.destroystokyo.paper.profile.ProfileProperty; 30 | import com.google.inject.Inject; 31 | import com.minekube.connect.api.SimpleConnectApi; 32 | import java.util.HashSet; 33 | import java.util.Set; 34 | import java.util.UUID; 35 | import org.bukkit.event.EventHandler; 36 | import org.bukkit.event.Listener; 37 | 38 | public final class PaperProfileListener implements Listener { 39 | @Inject private SimpleConnectApi api; 40 | 41 | @EventHandler // TODO robin: remove or replace with session proposal player props 42 | public void onFill(PreFillProfileEvent event) { 43 | UUID id = event.getPlayerProfile().getId(); 44 | // back when this event got added the PlayerProfile class didn't have the 45 | // hasProperty / hasTextures methods 46 | if (id == null || !this.api.isConnectPlayer(id) || 47 | event.getPlayerProfile().getProperties().stream().anyMatch( 48 | prop -> "textures".equals(prop.getName()))) { 49 | return; 50 | } 51 | 52 | Set properties = new HashSet<>(event.getPlayerProfile().getProperties()); 53 | properties.add(new ProfileProperty("textures", "", "")); 54 | event.setProperties(properties); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/util/backoff/BackOff.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. 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 distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package com.minekube.connect.util.backoff; 16 | 17 | import java.io.IOException; 18 | 19 | /** 20 | * Back-off policy when retrying an operation. 21 | * 22 | * @author Ravi Mistry 23 | * @since 1.15 24 | */ 25 | public interface BackOff { 26 | 27 | /** 28 | * Indicates that no more retries should be made for use in {@link #nextBackOffMillis()}. 29 | */ 30 | static final long STOP = -1L; 31 | 32 | /** 33 | * Reset to initial state. 34 | */ 35 | void reset() throws IOException; 36 | 37 | /** 38 | * Gets the number of milliseconds to wait before retrying the operation or {@link #STOP} to 39 | * indicate that no retries should be made. 40 | * 41 | *

Example usage: 42 | * 43 | *

44 |      * long backOffMillis = backoff.nextBackOffMillis();
45 |      * if (backOffMillis == Backoff.STOP) {
46 |      * // do not retry operation
47 |      * } else {
48 |      * // sleep for backOffMillis milliseconds and retry operation
49 |      * }
50 |      * 
51 | */ 52 | long nextBackOffMillis() throws IOException; 53 | 54 | /** 55 | * Fixed back-off policy whose back-off time is always zero, meaning that the operation is 56 | * retried immediately without waiting. 57 | */ 58 | BackOff ZERO_BACKOFF = 59 | new BackOff() { 60 | 61 | public void reset() throws IOException { 62 | } 63 | 64 | public long nextBackOffMillis() throws IOException { 65 | return 0; 66 | } 67 | }; 68 | 69 | /** 70 | * Fixed back-off policy that always returns {@code #STOP} for {@link #nextBackOffMillis()}, 71 | * meaning that the operation should not be retried. 72 | */ 73 | BackOff STOP_BACKOFF = 74 | new BackOff() { 75 | 76 | public void reset() throws IOException { 77 | } 78 | 79 | public long nextBackOffMillis() throws IOException { 80 | return STOP; 81 | } 82 | }; 83 | } -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/network/netty/LocalChannelWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.network.netty; 27 | 28 | import io.netty.channel.DefaultChannelPipeline; 29 | import io.netty.channel.local.LocalChannel; 30 | import io.netty.channel.local.LocalServerChannel; 31 | 32 | public class LocalChannelWrapper extends LocalChannel { 33 | private final ChannelWrapper wrapper; 34 | /** 35 | * {@link #newChannelPipeline()} is called during super, so this exists until the wrapper can be 36 | * initialized. 37 | */ 38 | private volatile ChannelWrapper tempWrapper; 39 | 40 | public LocalChannelWrapper() { 41 | wrapper = new ChannelWrapper(this); 42 | } 43 | 44 | public LocalChannelWrapper(LocalServerChannel parent, LocalChannel peer) { 45 | super(parent, peer); 46 | if (tempWrapper == null) { 47 | this.wrapper = new ChannelWrapper(this); 48 | } else { 49 | this.wrapper = tempWrapper; 50 | } 51 | } 52 | 53 | public ChannelWrapper wrapper() { 54 | return wrapper; 55 | } 56 | 57 | @Override 58 | protected DefaultChannelPipeline newChannelPipeline() { 59 | if (wrapper != null) { 60 | return new DefaultChannelPipelinePublic(wrapper); 61 | } else if (tempWrapper != null) { 62 | return new DefaultChannelPipelinePublic(tempWrapper); 63 | } else { 64 | tempWrapper = new ChannelWrapper(this); 65 | return new DefaultChannelPipelinePublic(tempWrapper); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/network/netty/TunnelHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Minekube. https://minekube.com 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author Minekube 23 | * @link https://github.com/minekube/connect-java 24 | */ 25 | 26 | package com.minekube.connect.network.netty; 27 | 28 | import com.minekube.connect.api.logger.ConnectLogger; 29 | import com.minekube.connect.tunnel.TunnelConn.Handler; 30 | import io.grpc.Status; 31 | import io.grpc.Status.Code; 32 | import io.netty.buffer.ByteBuf; 33 | import io.netty.buffer.Unpooled; 34 | import io.netty.channel.Channel; 35 | import lombok.RequiredArgsConstructor; 36 | 37 | @RequiredArgsConstructor 38 | class TunnelHandler implements Handler { 39 | private final ConnectLogger logger; 40 | private final Channel downstreamServerConn; // local server connection 41 | 42 | @Override 43 | public void onReceive(byte[] data) { 44 | // TunnelService -> local session server -> downstream server 45 | ByteBuf buf = Unpooled.wrappedBuffer(data); 46 | downstreamServerConn.writeAndFlush(buf); 47 | } 48 | 49 | @Override 50 | public void onError(Throwable t) { 51 | // error connecting to tunnel service 52 | Status status = Status.fromThrowable(t); 53 | if (status.getCode() == Code.CANCELLED) { 54 | return; 55 | } 56 | logger.error("Connection error with TunnelService: " + 57 | t + ( 58 | t.getCause() == null ? "" 59 | : " (cause: " + t.getCause().toString() + ")" 60 | ) 61 | ); 62 | } 63 | 64 | @Override 65 | public void onClose() { 66 | // disconnect from downstream server 67 | downstreamServerConn.close(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/register/CommandRegister.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.register; 27 | 28 | import cloud.commandframework.CommandManager; 29 | import com.google.inject.Inject; 30 | import com.google.inject.Injector; 31 | import com.google.inject.Key; 32 | import com.minekube.connect.config.ConnectConfig; 33 | import com.minekube.connect.platform.command.ConnectCommand; 34 | import com.minekube.connect.player.UserAudience; 35 | import java.util.Set; 36 | 37 | /** 38 | * This class is responsible for registering commands to the command register of the platform that 39 | * is currently in use. So that the commands only have to be written once (in the common module) and 40 | * can be used across all platforms without the need of adding platform specific commands. 41 | */ 42 | public final class CommandRegister { 43 | private final CommandManager commandManager; 44 | private final ConnectConfig config; 45 | private final Injector guice; 46 | 47 | @Inject 48 | public CommandRegister(Injector guice) { 49 | this.commandManager = guice.getInstance(new Key>() {}); 50 | this.config = guice.getInstance(ConnectConfig.class); 51 | this.guice = guice; 52 | } 53 | 54 | @Inject 55 | public void registerCommands(Set foundCommands) { 56 | for (ConnectCommand command : foundCommands) { 57 | guice.injectMembers(command); 58 | if (command.shouldRegister(config)) { 59 | commandManager.command(command.buildCommand(commandManager)); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/packet/PacketHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api.packet; 27 | 28 | import com.minekube.connect.api.util.TriFunction; 29 | import io.netty.channel.ChannelHandlerContext; 30 | 31 | public interface PacketHandlers { 32 | /** 33 | * Register a specific class for a specific consumer. 34 | * 35 | * @param handler the packet handler instance 36 | * @param packetClass the class to start listening for 37 | * @param consumer the consumer to call once the packet has been seen 38 | */ 39 | void register( 40 | PacketHandler handler, 41 | Class packetClass, 42 | TriFunction consumer); 43 | 44 | /** 45 | * Register a specific class for the given packet handler's {@link 46 | * PacketHandler#handle(ChannelHandlerContext, Object, boolean)}. 47 | * 48 | * @param handler the packet handler instance 49 | * @param packetClass the class to start listening for 50 | */ 51 | default void register(PacketHandler handler, Class packetClass) { 52 | register(handler, packetClass, handler::handle); 53 | } 54 | 55 | /** 56 | * Register every packet for the given packet handler's {@link PacketHandler#handle(ChannelHandlerContext, 57 | * Object, boolean)} 58 | */ 59 | void registerAll(PacketHandler handler); 60 | 61 | /** 62 | * Unregisters all handlers registered under the given packet handler 63 | * 64 | * @param handler the packet handler instance 65 | */ 66 | void deregister(PacketHandler handler); 67 | } 68 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/inject/InjectorAddon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api.inject; 27 | 28 | import io.netty.channel.Channel; 29 | 30 | public interface InjectorAddon { 31 | /** 32 | * Called when injecting a specific channel (every client that is connected to the server has 33 | * his own channel). Internally used for the debugger and data handler but can also be used for 34 | * third party things. 35 | * 36 | * @param channel the channel that the injector is injecting 37 | * @param toServer if the connection is between a proxy and a server 38 | */ 39 | void onInject(Channel channel, boolean toServer); 40 | 41 | /** 42 | * Called when the channel has been closed. Note that this method will be called for every 43 | * closed connection (if it is injected), so it'll also run this method for closed connections 44 | * between a server and the proxy (when Connect is running on a proxy). 45 | * 46 | * @param channel the channel that the injector injected 47 | */ 48 | default void onChannelClosed(Channel channel) { 49 | } 50 | 51 | /** 52 | * Called when Connect is removing the injection from the server. The addon should remove his 53 | * traces otherwise it is likely that an error will popup after the server is injected again. 54 | * 55 | * @param channel the channel that the injector injected 56 | */ 57 | void onRemoveInject(Channel channel); 58 | 59 | /** 60 | * If the Injector should call {@link #onInject(Channel, boolean)} 61 | * 62 | * @return true if it should, false otherwise 63 | */ 64 | boolean shouldInject(); 65 | } 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/PacketHandlerAddon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.name.Named; 30 | import com.minekube.connect.addon.packethandler.ChannelInPacketHandler; 31 | import com.minekube.connect.addon.packethandler.ChannelOutPacketHandler; 32 | import com.minekube.connect.api.inject.InjectorAddon; 33 | import com.minekube.connect.packet.PacketHandlersImpl; 34 | import com.minekube.connect.util.Utils; 35 | import io.netty.channel.Channel; 36 | import io.netty.channel.ChannelPipeline; 37 | 38 | public class PacketHandlerAddon implements InjectorAddon { 39 | @Inject private PacketHandlersImpl packetHandlers; 40 | 41 | @Inject 42 | @Named("packetEncoder") 43 | private String packetEncoder; 44 | 45 | @Inject 46 | @Named("packetDecoder") 47 | private String packetDecoder; 48 | 49 | @Override 50 | public void onInject(Channel channel, boolean toServer) { 51 | channel.pipeline().addAfter( 52 | packetEncoder, "connect_phaddon_out", 53 | new ChannelOutPacketHandler(packetHandlers, toServer) 54 | ).addAfter( 55 | packetDecoder, "connect_phaddon_in", 56 | new ChannelInPacketHandler(packetHandlers, toServer) 57 | ); 58 | } 59 | 60 | @Override 61 | public void onRemoveInject(Channel channel) { 62 | ChannelPipeline pipeline = channel.pipeline(); 63 | 64 | Utils.removeHandler(pipeline, "connect_phaddon_out"); 65 | Utils.removeHandler(pipeline, "connect_phaddon_in"); 66 | } 67 | 68 | @Override 69 | public boolean shouldInject() { 70 | // this means that there has to be at least one PacketHandler registered to inject 71 | return packetHandlers.hasHandlers(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/addon/data/SpigotDataAddon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.data; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.name.Named; 30 | import com.minekube.connect.api.SimpleConnectApi; 31 | import com.minekube.connect.api.inject.InjectorAddon; 32 | import com.minekube.connect.api.logger.ConnectLogger; 33 | import com.minekube.connect.config.ConnectConfig; 34 | import com.minekube.connect.network.netty.LocalChannelInboundHandler; 35 | import com.minekube.connect.network.netty.LocalSession; 36 | import io.netty.channel.Channel; 37 | 38 | public final class SpigotDataAddon implements InjectorAddon { 39 | @Inject private ConnectConfig config; 40 | @Inject private SimpleConnectApi api; 41 | @Inject private ConnectLogger logger; 42 | 43 | @Inject 44 | @Named("packetHandler") 45 | private String packetHandlerName; 46 | 47 | @Override 48 | public void onInject(Channel channel, boolean toServer) { 49 | // At this point channel must be a local session 50 | LocalSession.context(channel, ctx -> { 51 | // we have to add the packet blocker in the data handler, otherwise ProtocolSupport breaks 52 | channel.pipeline().addBefore( 53 | packetHandlerName, "connect_data_handler", 54 | new SpigotDataHandler(ctx, 55 | packetHandlerName, 56 | config) 57 | ); 58 | }); 59 | } 60 | 61 | @Override 62 | public void onChannelClosed(Channel channel) { 63 | LocalSession.context(channel, ctx -> LocalChannelInboundHandler.onChannelClosed(ctx, api, logger)); 64 | } 65 | 66 | @Override 67 | public void onRemoveInject(Channel channel) { 68 | } 69 | 70 | @Override 71 | public boolean shouldInject() { 72 | return true; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/inject/velocity/ConnectWatchedSingleThreadIoEventLoop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Geyser 24 | */ 25 | 26 | package com.minekube.connect.inject.velocity; 27 | 28 | import io.netty.channel.Channel; 29 | import io.netty.channel.ChannelFuture; 30 | import io.netty.channel.EventLoopGroup; 31 | import io.netty.channel.IoEventLoopGroup; 32 | import io.netty.channel.IoHandlerFactory; 33 | import io.netty.channel.SingleThreadIoEventLoop; 34 | 35 | import java.util.concurrent.Executor; 36 | 37 | public class ConnectWatchedSingleThreadIoEventLoop extends SingleThreadIoEventLoop { 38 | private final EventLoopGroup trueWorkerGroup; 39 | 40 | public ConnectWatchedSingleThreadIoEventLoop(EventLoopGroup trueWorkerGroup, IoEventLoopGroup parent, 41 | Executor executor, IoHandlerFactory ioHandlerFactory) { 42 | super(parent, executor, ioHandlerFactory); 43 | this.trueWorkerGroup = trueWorkerGroup; 44 | } 45 | 46 | @Override 47 | @SuppressWarnings("deprecation") 48 | public ChannelFuture register(Channel channel) { 49 | if (channel.getClass().getName().startsWith("com.minekube.connect")) { 50 | return super.register(channel); 51 | } 52 | // Starting with Netty 4.2, channels/event loops are very picky with what can be accepted for each. 53 | // For example, IoUringIoHandler (on a Linux machine, what Velocity's worker group will be) 54 | // will not accept LocalChannels on bootstrap creation in VelocityInjector. 55 | // And using a MultiThreadEventLoopGroup with LocalIoHandler will throw an error when trying to 56 | // connect to the backend server. 57 | // Inserting ourselves here allows our local channels to use the event loop made for LocalChannels, 58 | // while re-using the settings and style of Velocity. 59 | return this.trueWorkerGroup.register(channel); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /bungee/src/main/java/com/minekube/connect/BungeePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect; 27 | 28 | import com.google.inject.Guice; 29 | import com.google.inject.Injector; 30 | import com.minekube.connect.api.logger.ConnectLogger; 31 | import com.minekube.connect.module.BungeeListenerModule; 32 | import com.minekube.connect.module.BungeePlatformModule; 33 | import com.minekube.connect.module.CommandModule; 34 | import com.minekube.connect.module.ProxyCommonModule; 35 | import com.minekube.connect.module.WatcherModule; 36 | import com.minekube.connect.util.ReflectionUtils; 37 | import net.md_5.bungee.api.plugin.Plugin; 38 | 39 | public final class BungeePlugin extends Plugin { 40 | private ConnectPlatform platform; 41 | 42 | @Override 43 | public void onLoad() { 44 | ReflectionUtils.setPrefix("net.md_5.bungee"); 45 | 46 | long ctm = System.currentTimeMillis(); 47 | Injector injector = Guice.createInjector( 48 | new ProxyCommonModule(getDataFolder().toPath()), 49 | new BungeePlatformModule(this) 50 | ); 51 | 52 | // BungeeCord doesn't have a build-in function to disable plugins, 53 | // so there is no need to have a custom Platform class like Spigot 54 | platform = injector.getInstance(ConnectPlatform.class); 55 | 56 | long endCtm = System.currentTimeMillis(); 57 | injector.getInstance(ConnectLogger.class) 58 | .translatedInfo("connect.core.finish", endCtm - ctm); 59 | } 60 | 61 | @Override 62 | public void onEnable() { 63 | platform.enable( 64 | new CommandModule(), 65 | new BungeeListenerModule(), 66 | // new BungeeAddonModule(), - don't need proxy-side data injection 67 | new WatcherModule() 68 | ); 69 | } 70 | 71 | @Override 72 | public void onDisable() { 73 | platform.disable(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/VelocityPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.Injector; 30 | import com.minekube.connect.api.logger.ConnectLogger; 31 | import com.minekube.connect.module.CommandModule; 32 | import com.minekube.connect.module.ProxyCommonModule; 33 | import com.minekube.connect.module.VelocityListenerModule; 34 | import com.minekube.connect.module.VelocityPlatformModule; 35 | import com.minekube.connect.module.WatcherModule; 36 | import com.minekube.connect.util.ReflectionUtils; 37 | import com.velocitypowered.api.event.Subscribe; 38 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 39 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 40 | import java.nio.file.Path; 41 | 42 | public final class VelocityPlugin { 43 | private final ConnectPlatform platform; 44 | 45 | @Inject 46 | public VelocityPlugin(@DataDirectory Path dataDirectory, Injector guice) { 47 | ReflectionUtils.setPrefix("com.velocitypowered.proxy"); 48 | 49 | long ctm = System.currentTimeMillis(); 50 | Injector injector = guice.createChildInjector( 51 | new ProxyCommonModule(dataDirectory), 52 | new VelocityPlatformModule(guice) 53 | ); 54 | 55 | platform = injector.getInstance(ConnectPlatform.class); 56 | 57 | long endCtm = System.currentTimeMillis(); 58 | injector.getInstance(ConnectLogger.class) 59 | .translatedInfo("connect.core.finish", endCtm - ctm); 60 | } 61 | 62 | @Subscribe 63 | public void onProxyInitialization(ProxyInitializeEvent event) { 64 | platform.enable( 65 | new CommandModule(), 66 | new VelocityListenerModule(), 67 | // new VelocityAddonModule(), - don't need proxy-side data injection 68 | new WatcherModule() 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/debug/ChannelInDebugHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.debug; 27 | 28 | import com.minekube.connect.api.logger.ConnectLogger; 29 | import com.minekube.connect.util.Utils; 30 | import io.netty.buffer.ByteBuf; 31 | import io.netty.buffer.ByteBufUtil; 32 | import io.netty.channel.ChannelHandler.Sharable; 33 | import io.netty.channel.ChannelHandlerContext; 34 | import io.netty.channel.SimpleChannelInboundHandler; 35 | import java.util.concurrent.atomic.AtomicInteger; 36 | 37 | @Sharable 38 | public final class ChannelInDebugHandler extends SimpleChannelInboundHandler { 39 | private final String direction; 40 | private final ConnectLogger logger; 41 | 42 | private final boolean toServer; 43 | private final AtomicInteger packetCount; 44 | 45 | public ChannelInDebugHandler( 46 | String implementationType, 47 | boolean toServer, 48 | AtomicInteger changeDetector, 49 | ConnectLogger logger) { 50 | this.direction = (toServer ? "Server -> " : "Player -> ") + implementationType; 51 | this.logger = logger; 52 | this.toServer = toServer; 53 | this.packetCount = changeDetector; 54 | } 55 | 56 | @Override 57 | protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) { 58 | try { 59 | int index = msg.readerIndex(); 60 | 61 | if (packetCount.getAndIncrement() < Utils.MAX_DEBUG_PACKET_COUNT) { 62 | logger.info("{} {}:\n{}", 63 | direction, 64 | packetCount.get(), 65 | ByteBufUtil.prettyHexDump(msg) 66 | ); 67 | } 68 | 69 | // reset index 70 | msg.readerIndex(index); 71 | 72 | ctx.fireChannelRead(msg.retain()); 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/debug/ChannelOutDebugHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon.debug; 27 | 28 | import com.minekube.connect.api.logger.ConnectLogger; 29 | import com.minekube.connect.util.Utils; 30 | import io.netty.buffer.ByteBuf; 31 | import io.netty.buffer.ByteBufUtil; 32 | import io.netty.channel.ChannelHandler.Sharable; 33 | import io.netty.channel.ChannelHandlerContext; 34 | import io.netty.handler.codec.MessageToByteEncoder; 35 | import java.util.concurrent.atomic.AtomicInteger; 36 | 37 | @Sharable 38 | public final class ChannelOutDebugHandler extends MessageToByteEncoder { 39 | private final String direction; 40 | private final ConnectLogger logger; 41 | 42 | private final boolean toServer; 43 | private final AtomicInteger packetCount; 44 | 45 | public ChannelOutDebugHandler( 46 | String implementationType, 47 | boolean toServer, 48 | AtomicInteger changeDetector, 49 | ConnectLogger logger) { 50 | this.direction = implementationType + (toServer ? " -> Server" : " -> Player"); 51 | this.logger = logger; 52 | this.toServer = toServer; 53 | this.packetCount = changeDetector; 54 | } 55 | 56 | @Override 57 | protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) { 58 | try { 59 | int index = msg.readerIndex(); 60 | 61 | if (packetCount.getAndIncrement() < Utils.MAX_DEBUG_PACKET_COUNT) { 62 | logger.info( 63 | "{} {}:\n{}", 64 | direction, 65 | packetCount.get(), 66 | ByteBufUtil.prettyHexDump(msg) 67 | ); 68 | } 69 | 70 | // reset index 71 | msg.readerIndex(index); 72 | 73 | out.writeBytes(msg); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/listener/SpigotListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.listener; 27 | 28 | import com.google.inject.Inject; 29 | import com.minekube.connect.api.SimpleConnectApi; 30 | import com.minekube.connect.api.logger.ConnectLogger; 31 | import com.minekube.connect.api.player.ConnectPlayer; 32 | import com.minekube.connect.util.LanguageManager; 33 | import java.util.UUID; 34 | import org.bukkit.event.EventHandler; 35 | import org.bukkit.event.EventPriority; 36 | import org.bukkit.event.Listener; 37 | import org.bukkit.event.player.PlayerLoginEvent; 38 | import org.bukkit.event.player.PlayerQuitEvent; 39 | 40 | public final class SpigotListener implements Listener { 41 | @Inject private SimpleConnectApi api; 42 | @Inject private LanguageManager languageManager; 43 | @Inject private ConnectLogger logger; 44 | 45 | @EventHandler(priority = EventPriority.MONITOR) 46 | public void onPlayerLogin(PlayerLoginEvent event) { 47 | UUID uniqueId = event.getPlayer().getUniqueId(); 48 | if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { 49 | return; 50 | } 51 | 52 | // if there was another player with the same uuid online, 53 | // he would've been disconnected by now 54 | ConnectPlayer player = api.getPlayer(uniqueId); 55 | if (player != null) { 56 | //todo we should probably move this log message earlier in the process, so that we know 57 | // that Connect has done its job 58 | logger.translatedInfo( 59 | "connect.ingame.login_name", 60 | player.getUsername(), player.getUniqueId() 61 | ); 62 | languageManager.loadLocale(player.getLanguageTag()); 63 | } 64 | } 65 | 66 | @EventHandler(priority = EventPriority.MONITOR) 67 | public void onPlayerQuit(PlayerQuitEvent event) { 68 | api.playerRemoved(event.getPlayer().getUniqueId()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /bungee/src/main/java/com/minekube/connect/inject/bungee/ConnectIoHandlerWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Wrapper around IoHandler that delegates between LocalIoHandler and native handler 3 | * Based on Geyser's approach for handling LocalServerChannel with BungeeCord. 4 | */ 5 | package com.minekube.connect.inject.bungee; 6 | 7 | import io.netty.channel.IoHandle; 8 | import io.netty.channel.IoHandler; 9 | import io.netty.channel.IoHandlerContext; 10 | import io.netty.channel.IoRegistration; 11 | 12 | public class ConnectIoHandlerWrapper implements IoHandler { 13 | private final IoHandler localHandler; 14 | private final IoHandler nativeHandler; 15 | private final IoHandlerContextWrapper contextWrapper = new IoHandlerContextWrapper(); 16 | 17 | public ConnectIoHandlerWrapper(IoHandler localHandler, IoHandler nativeHandler) { 18 | this.localHandler = localHandler; 19 | this.nativeHandler = nativeHandler; 20 | } 21 | 22 | @Override 23 | public void initialize() { 24 | localHandler.initialize(); 25 | nativeHandler.initialize(); 26 | } 27 | 28 | @Override 29 | public int run(IoHandlerContext context) { 30 | contextWrapper.base = context; 31 | localHandler.run(contextWrapper); 32 | return nativeHandler.run(context); 33 | } 34 | 35 | private static class IoHandlerContextWrapper implements IoHandlerContext { 36 | private IoHandlerContext base; 37 | 38 | @Override 39 | public boolean canBlock() { 40 | return false; 41 | } 42 | 43 | @Override 44 | public long delayNanos(long currentTimeNanos) { 45 | return base.delayNanos(currentTimeNanos); 46 | } 47 | 48 | @Override 49 | public long deadlineNanos() { 50 | return base.deadlineNanos(); 51 | } 52 | } 53 | 54 | @Override 55 | public void prepareToDestroy() { 56 | localHandler.prepareToDestroy(); 57 | nativeHandler.prepareToDestroy(); 58 | } 59 | 60 | @Override 61 | public void destroy() { 62 | localHandler.destroy(); 63 | nativeHandler.destroy(); 64 | } 65 | 66 | private static final Class LOCAL_HANDLER_CLASS; 67 | 68 | static { 69 | try { 70 | @SuppressWarnings("unchecked") 71 | Class clazz = (Class) Class.forName("io.netty.channel.local.LocalIoHandle"); 72 | LOCAL_HANDLER_CLASS = clazz; 73 | } catch (ClassNotFoundException e) { 74 | throw new RuntimeException(e); 75 | } 76 | } 77 | 78 | @Override 79 | public IoRegistration register(IoHandle handle) throws Exception { 80 | if (LOCAL_HANDLER_CLASS.isAssignableFrom(handle.getClass())) { 81 | return this.localHandler.register(handle); 82 | } 83 | return this.nativeHandler.register(handle); 84 | } 85 | 86 | @Override 87 | public void wakeup() { 88 | localHandler.wakeup(); 89 | nativeHandler.wakeup(); 90 | } 91 | 92 | @Override 93 | public boolean isCompatible(Class handleType) { 94 | return localHandler.isCompatible(handleType) || nativeHandler.isCompatible(handleType); 95 | } 96 | } 97 | 98 | 99 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/inject/PlatformInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api.inject; 27 | 28 | import java.net.SocketAddress; 29 | 30 | /** 31 | * The global interface of all the Platform Injectors. The injector can be used for various things. 32 | * It is used internally for intercepting handshake/login packets and for debug mode, but there is 33 | * also an option to add your own addons. Note that every platform that supports netty should 34 | * implement this, but the platform implementation isn't required to implement this. 35 | */ 36 | public interface PlatformInjector { 37 | 38 | /** 39 | * @return the server socket address 40 | */ 41 | SocketAddress getServerSocketAddress(); 42 | 43 | /** 44 | * Injects the server connection. 45 | * 46 | * @throws Exception if something went wrong while injecting the server connection 47 | */ 48 | boolean inject() throws Exception; 49 | 50 | /** 51 | * If the server connection is currently injected. 52 | * 53 | * @return true if the server connection is currently injected, returns false otherwise 54 | */ 55 | boolean isInjected(); 56 | 57 | /** 58 | * Adds an addon to the addon list of the Injector (the addon is called when Connect injects a 59 | * channel). See {@link InjectorAddon} for more info. 60 | * 61 | * @param addon the addon to add to the addon list 62 | * @return true if the addon has been added, false if the addon is already present 63 | */ 64 | boolean addAddon(InjectorAddon addon); 65 | 66 | /** 67 | * Removes an addon from the addon list of the Injector (the addon is called when Connect 68 | * injects a channel). See {@link InjectorAddon} for more info. 69 | * 70 | * @param addon the class of the addon to remove from the addon list 71 | * @param the addon type 72 | * @return the removed addon instance 73 | */ 74 | T removeAddon(Class addon); 75 | } 76 | -------------------------------------------------------------------------------- /api/src/main/java/com/minekube/connect/api/util/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.api.util; 27 | 28 | import java.util.Objects; 29 | import java.util.function.Function; 30 | 31 | /** 32 | * Represents a function that accepts three arguments and produces a result. This is the three-arity 33 | * specialization of {@link Function}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #apply(Object, Object, Object)}. 37 | * 38 | * @param the type of the first argument to the function 39 | * @param the type of the second argument to the function 40 | * @param the type of the third argument of the function 41 | * @param the type of the result of the function 42 | * @see Function 43 | * @since 1.8 44 | */ 45 | @FunctionalInterface 46 | public interface TriFunction { 47 | /** 48 | * Performs this operation on the given arguments. 49 | * 50 | * @param t the first input argument 51 | * @param u the second input argument 52 | * @param v the third input argument 53 | */ 54 | R apply(T t, U u, V v); 55 | 56 | /** 57 | * Returns a composed function that first applies this function to its input, and then applies 58 | * the {@code after} function to the result. If evaluation of either function throws an 59 | * exception, it is relayed to the caller of the composed function. 60 | * 61 | * @param the type of output of the {@code after} function, and of the composed function 62 | * @param after the function to apply after this function is applied 63 | * @return a composed function that first applies this function and then applies the {@code 64 | * after} function 65 | * @throws NullPointerException if after is null 66 | */ 67 | default TriFunction andThen(Function after) { 68 | Objects.requireNonNull(after); 69 | return (T t, U u, V v) -> after.apply(apply(t, u, v)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/config/ConnectConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.config; 27 | 28 | import com.minekube.connect.util.Utils; 29 | import java.util.List; 30 | import lombok.Getter; 31 | 32 | /** 33 | * The global configuration file used in every platform. Some platforms have their own addition to 34 | * the global configuration like {@link ProxyConnectConfig} for the proxies. 35 | */ 36 | @Getter 37 | public class ConnectConfig { 38 | private String defaultLocale; 39 | 40 | private MetricsConfig metrics; 41 | 42 | private boolean debug; 43 | private int configVersion; 44 | 45 | /** 46 | * The endpoint name of this instance that is registered when calling the watch service for 47 | * listening for sessions for this endpoint. 48 | */ 49 | private final String endpoint = Utils.randomString(5); // default to random name 50 | 51 | /** 52 | * Whether cracked players should be allowed to join. 53 | * If not set, Connect will automatically detect if the server allows cracked players. 54 | */ 55 | private Boolean allowOfflineModePlayers; 56 | 57 | /** 58 | * Super endpoints are authorized to control this endpoint via Connect API. 59 | * e.g. disconnect players from this endpoint, send messages to players, etc. 60 | */ 61 | private List superEndpoints; 62 | 63 | private static final String ENDPOINT_ENV = System.getenv("CONNECT_ENDPOINT"); 64 | 65 | public String getEndpoint() { 66 | if (ENDPOINT_ENV != null && !ENDPOINT_ENV.isEmpty()) { 67 | return ENDPOINT_ENV; 68 | } 69 | return endpoint; 70 | } 71 | 72 | public boolean isProxy() { 73 | return this instanceof ProxyConnectConfig; 74 | } 75 | 76 | @Getter 77 | public static class MetricsConfig { 78 | /** 79 | * If metrics should be disabled. 80 | */ 81 | private boolean disabled; 82 | /** 83 | * The unique id that should be consistent for a server/proxy. 84 | */ 85 | private String uuid; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | branches: [ connect ] 6 | tags: [ "*.*.*" ] 7 | 8 | jobs: 9 | 10 | build: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | env: 15 | RELEASE_DIR: release 16 | LATEST_RELEASE_DIR: latest/release 17 | LATEST_PRERELEASE_DIR: latest/prerelease 18 | steps: 19 | - uses: actions/checkout@v3 20 | 21 | - name: Set up JDK 17 22 | uses: actions/setup-java@v3 23 | with: 24 | distribution: 'temurin' 25 | java-version: '17' 26 | 27 | - name: Setup Gradle 28 | uses: gradle/gradle-build-action@v2 29 | 30 | - name: Build with Maven 31 | run: ./gradlew build 32 | 33 | - name: Rename JARs for Latest Pre-Release 34 | if: ${{ !startsWith(github.ref, 'refs/tags/') }} 35 | run: | 36 | mkdir -p ${LATEST_PRERELEASE_DIR} 37 | cp spigot/build/libs/connect-spigot.jar ${LATEST_PRERELEASE_DIR}/connect-spigot-prerelease.jar 38 | cp velocity/build/libs/connect-velocity.jar ${LATEST_PRERELEASE_DIR}/connect-velocity-prerelease.jar 39 | cp bungee/build/libs/connect-bungee.jar ${LATEST_PRERELEASE_DIR}/connect-bungee-prerelease.jar 40 | 41 | - name: Rename JARs for Latest Release 42 | if: startsWith(github.ref, 'refs/tags/') 43 | run: | 44 | mkdir -p ${LATEST_RELEASE_DIR} 45 | cp spigot/build/libs/connect-spigot.jar ${LATEST_RELEASE_DIR}/connect-spigot.jar 46 | cp velocity/build/libs/connect-velocity.jar ${LATEST_RELEASE_DIR}/connect-velocity.jar 47 | cp bungee/build/libs/connect-bungee.jar ${LATEST_RELEASE_DIR}/connect-bungee.jar 48 | 49 | - name: Rename JARs for Release 50 | if: startsWith(github.ref, 'refs/tags/') 51 | run: | 52 | mkdir -p ${RELEASE_DIR} 53 | REF=${GITHUB_REF##*/} 54 | cp spigot/build/libs/connect-spigot.jar ${RELEASE_DIR}/connect-spigot-${REF}.jar 55 | cp velocity/build/libs/connect-velocity.jar ${RELEASE_DIR}/connect-velocity-${REF}.jar 56 | cp bungee/build/libs/connect-bungee.jar ${RELEASE_DIR}/connect-bungee-${REF}.jar 57 | 58 | - name: Latest Pre Release 59 | uses: marvinpinto/action-automatic-releases@latest 60 | if: ${{ !startsWith(github.ref, 'refs/tags/') }} 61 | with: 62 | repo_token: ${{ secrets.GH_TOKEN }} 63 | automatic_release_tag: latest-prerelease 64 | prerelease: true 65 | title: Latest Pre-Release 66 | files: | 67 | latest/prerelease/*.jar 68 | LICENSE 69 | 70 | - name: Latest Release 71 | uses: marvinpinto/action-automatic-releases@latest 72 | if: startsWith(github.ref, 'refs/tags/') 73 | with: 74 | repo_token: ${{ secrets.GH_TOKEN }} 75 | automatic_release_tag: latest 76 | prerelease: false 77 | title: Latest Release 78 | files: | 79 | latest/release/*.jar 80 | LICENSE 81 | 82 | - name: Release version 83 | uses: marvinpinto/action-automatic-releases@latest 84 | if: startsWith(github.ref, 'refs/tags/') 85 | with: 86 | repo_token: ${{ secrets.GH_TOKEN }} 87 | prerelease: false 88 | files: | 89 | release/*.jar 90 | LICENSE -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/addon/DebugAddon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.addon; 27 | 28 | import com.google.inject.Inject; 29 | import com.google.inject.name.Named; 30 | import com.minekube.connect.addon.debug.ChannelInDebugHandler; 31 | import com.minekube.connect.addon.debug.ChannelOutDebugHandler; 32 | import com.minekube.connect.api.inject.InjectorAddon; 33 | import com.minekube.connect.api.logger.ConnectLogger; 34 | import com.minekube.connect.config.ConnectConfig; 35 | import com.minekube.connect.util.Utils; 36 | import io.netty.channel.Channel; 37 | import io.netty.channel.ChannelPipeline; 38 | import java.util.concurrent.atomic.AtomicInteger; 39 | 40 | public final class DebugAddon implements InjectorAddon { 41 | @Inject private ConnectConfig config; 42 | @Inject private ConnectLogger logger; 43 | 44 | @Inject 45 | @Named("platformName") 46 | private String platformName; 47 | 48 | @Inject 49 | @Named("packetEncoder") 50 | private String packetEncoder; 51 | 52 | @Inject 53 | @Named("packetDecoder") 54 | private String packetDecoder; 55 | 56 | @Override 57 | public void onInject(Channel channel, boolean toServer) { 58 | logger.info("Successfully called onInject. To server? " + toServer); 59 | 60 | AtomicInteger packetCount = new AtomicInteger(); 61 | 62 | channel.pipeline().addBefore( 63 | packetEncoder, "connect_debug_out", 64 | new ChannelOutDebugHandler(platformName, toServer, packetCount, logger) 65 | ).addBefore( 66 | packetDecoder, "connect_debug_in", 67 | new ChannelInDebugHandler(platformName, toServer, packetCount, logger) 68 | ); 69 | } 70 | 71 | @Override 72 | public void onRemoveInject(Channel channel) { 73 | ChannelPipeline pipeline = channel.pipeline(); 74 | 75 | Utils.removeHandler(pipeline, "connect_debug_out"); 76 | Utils.removeHandler(pipeline, "connect_debug_in"); 77 | } 78 | 79 | @Override 80 | public boolean shouldInject() { 81 | return config.isDebug(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /core/src/main/java/com/minekube/connect/logger/JavaUtilConnectLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.logger; 27 | 28 | import static com.minekube.connect.util.MessageFormatter.format; 29 | 30 | import com.minekube.connect.api.logger.ConnectLogger; 31 | import com.minekube.connect.util.LanguageManager; 32 | import java.util.logging.Level; 33 | import java.util.logging.Logger; 34 | import lombok.RequiredArgsConstructor; 35 | 36 | @RequiredArgsConstructor 37 | public final class JavaUtilConnectLogger implements ConnectLogger { 38 | private final Logger logger; 39 | private final LanguageManager languageManager; 40 | private Level originLevel; 41 | 42 | @Override 43 | public void error(String message, Object... args) { 44 | logger.severe(format(message, args)); 45 | } 46 | 47 | @Override 48 | public void error(String message, Throwable throwable, Object... args) { 49 | logger.log(Level.SEVERE, format(message, args), throwable); 50 | } 51 | 52 | @Override 53 | public void warn(String message, Object... args) { 54 | logger.warning(format(message, args)); 55 | } 56 | 57 | @Override 58 | public void info(String message, Object... args) { 59 | logger.info(format(message, args)); 60 | } 61 | 62 | @Override 63 | public void translatedInfo(String message, Object... args) { 64 | logger.info(languageManager.getLogString(message, args)); 65 | } 66 | 67 | @Override 68 | public void debug(String message, Object... args) { 69 | logger.fine(format(message, args)); 70 | } 71 | 72 | @Override 73 | public void trace(String message, Object... args) { 74 | logger.finer(format(message, args)); 75 | } 76 | 77 | @Override 78 | public void enableDebug() { 79 | originLevel = logger.getLevel(); 80 | logger.setLevel(Level.ALL); 81 | } 82 | 83 | @Override 84 | public void disableDebug() { 85 | if (originLevel != null) { 86 | logger.setLevel(originLevel); 87 | } 88 | } 89 | 90 | @Override 91 | public boolean isDebug() { 92 | return logger.getLevel() == Level.ALL; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /spigot/src/main/java/com/minekube/connect/util/SpigotVersionSpecificMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.util; 27 | 28 | import com.minekube.connect.SpigotPlugin; 29 | import java.lang.reflect.Method; 30 | import org.bukkit.entity.Player; 31 | import org.bukkit.plugin.Plugin; 32 | 33 | public final class SpigotVersionSpecificMethods { 34 | private static final Method GET_SPIGOT; 35 | private static final Method OLD_GET_LOCALE; 36 | private static final boolean NEW_VISIBILITY; 37 | 38 | static { 39 | GET_SPIGOT = ReflectionUtils.getMethod(Player.class, "spigot"); 40 | OLD_GET_LOCALE = ReflectionUtils.getMethod(Player.Spigot.class, "getLocale"); 41 | 42 | NEW_VISIBILITY = null != ReflectionUtils.getMethod( 43 | Player.class, "hidePlayer", 44 | Plugin.class, Player.class 45 | ); 46 | } 47 | 48 | private final SpigotPlugin plugin; 49 | 50 | public SpigotVersionSpecificMethods(SpigotPlugin plugin) { 51 | this.plugin = plugin; 52 | } 53 | 54 | public String getLocale(Player player) { 55 | if (OLD_GET_LOCALE == null) { 56 | return player.getLocale(); 57 | } 58 | Object spigot = ReflectionUtils.invoke(player, GET_SPIGOT); 59 | return ReflectionUtils.castedInvoke(spigot, OLD_GET_LOCALE); 60 | } 61 | 62 | public void hideAndShowPlayer(Player on, Player target) { 63 | // In Folia we don't have to schedule this as there is no concept of a single main thread. 64 | // Instead, we have to schedule the task per player. 65 | if (ClassNames.IS_FOLIA) { 66 | on.getScheduler().execute(plugin, () -> hideAndShowPlayer0(on, target), null, 0); 67 | return; 68 | } 69 | hideAndShowPlayer0(on, target); 70 | } 71 | 72 | @SuppressWarnings("deprecation") 73 | private void hideAndShowPlayer0(Player source, Player target) { 74 | if (NEW_VISIBILITY) { 75 | source.hidePlayer(plugin, target); 76 | source.showPlayer(plugin, target); 77 | return; 78 | } 79 | source.hidePlayer(target); 80 | source.showPlayer(target); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /velocity/src/main/java/com/minekube/connect/logger/Slf4JConnectLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | * @author GeyserMC 23 | * @link https://github.com/GeyserMC/Floodgate 24 | */ 25 | 26 | package com.minekube.connect.logger; 27 | 28 | import static com.minekube.connect.util.MessageFormatter.format; 29 | 30 | import com.minekube.connect.api.logger.ConnectLogger; 31 | import com.minekube.connect.util.LanguageManager; 32 | import lombok.RequiredArgsConstructor; 33 | import org.apache.logging.log4j.Level; 34 | import org.apache.logging.log4j.core.config.Configurator; 35 | import org.slf4j.Logger; 36 | 37 | @RequiredArgsConstructor 38 | public final class Slf4JConnectLogger implements ConnectLogger { 39 | private final Logger logger; 40 | private final LanguageManager languageManager; 41 | 42 | @Override 43 | public void error(String message, Object... args) { 44 | logger.error(message, args); 45 | } 46 | 47 | @Override 48 | public void error(String message, Throwable throwable, Object... args) { 49 | logger.error(format(message, args), throwable); 50 | } 51 | 52 | @Override 53 | public void warn(String message, Object... args) { 54 | logger.warn(message, args); 55 | } 56 | 57 | @Override 58 | public void info(String message, Object... args) { 59 | logger.info(message, args); 60 | } 61 | 62 | @Override 63 | public void translatedInfo(String message, Object... args) { 64 | logger.info(languageManager.getLogString(message, args)); 65 | } 66 | 67 | @Override 68 | public void debug(String message, Object... args) { 69 | logger.debug(message, args); 70 | } 71 | 72 | @Override 73 | public void trace(String message, Object... args) { 74 | logger.trace(message, args); 75 | } 76 | 77 | @Override 78 | public void enableDebug() { 79 | if (!logger.isDebugEnabled()) { 80 | Configurator.setLevel(logger.getName(), Level.DEBUG); 81 | } 82 | } 83 | 84 | @Override 85 | public void disableDebug() { 86 | if (logger.isDebugEnabled()) { 87 | Configurator.setLevel(logger.getName(), Level.INFO); 88 | } 89 | } 90 | 91 | @Override 92 | public boolean isDebug() { 93 | return logger.isDebugEnabled(); 94 | } 95 | } 96 | --------------------------------------------------------------------------------