geforkt von Mirrors/Velocity
Tiny rework of Protocol Version API (#1260)
Dieser Commit ist enthalten in:
Ursprung
af09677f60
Commit
82189a6a21
@ -21,8 +21,28 @@ import java.util.Set;
|
||||
* Represents each Minecraft protocol version.
|
||||
*/
|
||||
public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
UNKNOWN(-1, "Unknown"),
|
||||
LEGACY(-2, "Legacy"),
|
||||
UNKNOWN(-1, "Unknown") {
|
||||
@Override
|
||||
public boolean isUnknown() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
LEGACY(-2, "Legacy") {
|
||||
@Override
|
||||
public boolean isLegacy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
MINECRAFT_1_7_2(4,
|
||||
"1.7.2", "1.7.3", "1.7.4", "1.7.5"),
|
||||
MINECRAFT_1_7_6(5,
|
||||
@ -118,7 +138,7 @@ public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
static {
|
||||
Set<ProtocolVersion> versions = EnumSet.noneOf(ProtocolVersion.class);
|
||||
for (ProtocolVersion value : values()) {
|
||||
if (!value.isUnknown() && !value.isLegacy()) {
|
||||
if (value.isSupported()) {
|
||||
versions.add(value);
|
||||
}
|
||||
}
|
||||
@ -191,6 +211,35 @@ public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
return ImmutableList.copyOf(names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this {@link ProtocolVersion} is supported.
|
||||
*
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public boolean isSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the protocol is supported.
|
||||
*
|
||||
* @param protocol the protocol as an int
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(int protocol) {
|
||||
return getProtocolVersion(protocol).isSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ProtocolVersion} is supported.
|
||||
*
|
||||
* @param version the protocol version
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(ProtocolVersion version) {
|
||||
return version != null && version.isSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ProtocolVersion} for the given protocol.
|
||||
*
|
||||
@ -201,35 +250,13 @@ public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
return ID_TO_PROTOCOL_CONSTANT.getOrDefault(protocol, UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the protocol is supported.
|
||||
*
|
||||
* @param protocol the protocol as an int
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(int protocol) {
|
||||
ProtocolVersion version = ID_TO_PROTOCOL_CONSTANT.get(protocol);
|
||||
|
||||
return version != null && !version.isUnknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ProtocolVersion} is supported.
|
||||
*
|
||||
* @param version the protocol version
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(ProtocolVersion version) {
|
||||
return version != null && !version.isUnknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this {@link ProtocolVersion} is unknown to the proxy.
|
||||
*
|
||||
* @return if the protocol is unknown
|
||||
*/
|
||||
public boolean isUnknown() {
|
||||
return this == UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,7 +265,7 @@ public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
* @return if the protocol is legacy
|
||||
*/
|
||||
public boolean isLegacy() {
|
||||
return this == LEGACY;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,7 +117,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic) {
|
||||
if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) {
|
||||
if (!handshake.getProtocolVersion().isSupported()) {
|
||||
// Bump connection into correct protocol state so that we can send the disconnect packet.
|
||||
connection.setState(StateRegistry.LOGIN);
|
||||
ic.disconnectQuietly(Component.translatable()
|
||||
|
@ -143,7 +143,7 @@ public class ServerListPingHandler {
|
||||
*/
|
||||
public CompletableFuture<ServerPing> getInitialPing(VelocityInboundConnection connection) {
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion())
|
||||
ProtocolVersion shownVersion = connection.getProtocolVersion().isSupported()
|
||||
? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
|
||||
PingPassthroughMode passthroughMode = configuration.getPingPassthrough();
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren