2020-08-11 14:00:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector.network;
|
|
|
|
|
|
|
|
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
|
2020-11-17 17:03:12 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v419.Bedrock_v419;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
2020-08-29 00:11:32 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains information about the supported Bedrock protocols in Geyser.
|
|
|
|
*/
|
|
|
|
public class BedrockProtocol {
|
|
|
|
/**
|
2020-08-29 00:11:32 +00:00
|
|
|
* Default Bedrock codec that should act as a fallback. Should represent the latest available
|
|
|
|
* release of the game that Geyser supports.
|
2020-08-11 14:00:14 +00:00
|
|
|
*/
|
2020-11-17 17:03:12 +00:00
|
|
|
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v419.V419_CODEC;
|
2020-08-11 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* A list of all supported Bedrock versions that can join Geyser
|
|
|
|
*/
|
2020-08-29 00:11:32 +00:00
|
|
|
public static final List<BedrockPacketCodec> SUPPORTED_BEDROCK_CODECS = new ArrayList<>();
|
2020-08-11 14:00:14 +00:00
|
|
|
|
|
|
|
static {
|
2020-08-29 00:11:32 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
|
2020-08-11 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the {@link BedrockPacketCodec} of the given protocol version.
|
|
|
|
* @param protocolVersion The protocol version to attempt to find
|
|
|
|
* @return The packet codec, or null if the client's protocol is unsupported
|
|
|
|
*/
|
|
|
|
public static BedrockPacketCodec getBedrockCodec(int protocolVersion) {
|
|
|
|
for (BedrockPacketCodec packetCodec : SUPPORTED_BEDROCK_CODECS) {
|
|
|
|
if (packetCodec.getProtocolVersion() == protocolVersion) {
|
|
|
|
return packetCodec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|