13
0
geforkt von Mirrors/Velocity

Fix formatting in ProtocolVersion

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-07 17:24:56 -05:00
Ursprung ce6b061b79
Commit 853fd2226d

Datei anzeigen

@ -1,138 +1,137 @@
package com.velocitypowered.api.network; package com.velocitypowered.api.network;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.velocitypowered.api.proxy.server.ServerInfo;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Represents each Minecraft protocol version * Represents each Minecraft protocol version.
*/ */
public enum ProtocolVersion { public enum ProtocolVersion {
UNKNOWN(-1, "Unknown"), UNKNOWN(-1, "Unknown"),
LEGACY(-1, "Legacy"), LEGACY(-2, "Legacy"),
MINECRAFT_1_8(47, "1.8"), MINECRAFT_1_8(47, "1.8"),
MINECRAFT_1_9(107, "1.9"), MINECRAFT_1_9(107, "1.9"),
MINECRAFT_1_9_1(108, "1.9.1"), MINECRAFT_1_9_1(108, "1.9.1"),
MINECRAFT_1_9_2(109, "1.9.2"), MINECRAFT_1_9_2(109, "1.9.2"),
MINECRAFT_1_9_4(110, "1.9.4"), MINECRAFT_1_9_4(110, "1.9.4"),
MINECRAFT_1_10(210, "1.10"), MINECRAFT_1_10(210, "1.10"),
MINECRAFT_1_11(315, "1.11"), MINECRAFT_1_11(315, "1.11"),
MINECRAFT_1_11_1(316, "1.11.1"), MINECRAFT_1_11_1(316, "1.11.1"),
MINECRAFT_1_12(335, "1.12"), MINECRAFT_1_12(335, "1.12"),
MINECRAFT_1_12_1(338, "1.12.1"), MINECRAFT_1_12_1(338, "1.12.1"),
MINECRAFT_1_12_2(340, "1.12.2"), MINECRAFT_1_12_2(340, "1.12.2"),
MINECRAFT_1_13(393, "1.13"), MINECRAFT_1_13(393, "1.13"),
MINECRAFT_1_13_1(401, "1.13.1"), MINECRAFT_1_13_1(401, "1.13.1"),
MINECRAFT_1_13_2(404, "1.13.2"); MINECRAFT_1_13_2(404, "1.13.2");
private final int protocol; private final int protocol;
private final String name; private final String name;
/** /**
* Represents the lowest supported version * Represents the lowest supported version.
*/ */
public static final ProtocolVersion MINIMUM_VERSION = MINECRAFT_1_8; public static final ProtocolVersion MINIMUM_VERSION = MINECRAFT_1_8;
/** /**
* Represents the highest supported version * Represents the highest supported version.
*/ */
public static final ProtocolVersion MAXIMUM_VERSION = MINECRAFT_1_13_2; public static final ProtocolVersion MAXIMUM_VERSION = MINECRAFT_1_13_2;
/** /**
* The user-friendly representation of the lowest and highest supported versions * The user-friendly representation of the lowest and highest supported versions.
*/ */
public static final String SUPPORTED_VERSION_STRING = String.format("%s-%s", MINIMUM_VERSION, MAXIMUM_VERSION); public static final String SUPPORTED_VERSION_STRING = String
.format("%s-%s", MINIMUM_VERSION, MAXIMUM_VERSION);
/** /**
* A map linking the protocol version number to its {@link ProtocolVersion} representation * A map linking the protocol version number to its {@link ProtocolVersion} representation.
*/ */
public static final ImmutableMap<Integer, ProtocolVersion> ID_TO_PROTOCOL_CONSTANT; public static final ImmutableMap<Integer, ProtocolVersion> ID_TO_PROTOCOL_CONSTANT;
static { static {
Map<Integer, ProtocolVersion> versions = new HashMap<>(); Map<Integer, ProtocolVersion> versions = new HashMap<>();
for (ProtocolVersion version : values()) { for (ProtocolVersion version : values()) {
versions.put(version.protocol, version); versions.put(version.protocol, version);
}
ID_TO_PROTOCOL_CONSTANT = ImmutableMap.copyOf(versions);
} }
ProtocolVersion(int protocol, String name) { ID_TO_PROTOCOL_CONSTANT = ImmutableMap.copyOf(versions);
this.protocol = protocol; }
this.name = name;
}
/** ProtocolVersion(int protocol, String name) {
* Returns the protocol as an int this.protocol = protocol;
* this.name = name;
* @return the protocol version }
*/
public int getProtocol() {
return protocol;
}
/** /**
* Returns the user-friendly name for this protocol * Returns the protocol as an int.
* *
* @return the protocol name * @return the protocol version
*/ */
public String getName() { public int getProtocol() {
return name; return protocol;
} }
/** /**
* Gets the {@link ProtocolVersion} for the given protocol * Returns the user-friendly name for this protocol.
* *
* @param protocol the protocol as an int * @return the protocol name
* @return the protocol version */
*/ public String getName() {
public static ProtocolVersion getProtocolVersion(int protocol) { return name;
return ID_TO_PROTOCOL_CONSTANT.getOrDefault(protocol, UNKNOWN); }
}
/** /**
* Returns whether the protocol is supported * Gets the {@link ProtocolVersion} for the given protocol.
* *
* @param protocol the protocol as an int * @param protocol the protocol as an int
* @return if the protocol supported * @return the protocol version
*/ */
public static boolean isSupported(int protocol) { public static ProtocolVersion getProtocolVersion(int protocol) {
ProtocolVersion version = ID_TO_PROTOCOL_CONSTANT.get(protocol); return ID_TO_PROTOCOL_CONSTANT.getOrDefault(protocol, UNKNOWN);
}
return version != null && !version.isUnknown(); /**
} * 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 * Returns whether the {@link ProtocolVersion} is supported.
* *
* @return if the protocol is unknown * @param version the protocol version
*/ * @return if the protocol supported
public boolean isUnknown() { */
return this == UNKNOWN; public static boolean isSupported(ProtocolVersion version) {
} return version != null && !version.isUnknown();
}
/** /**
* Returns whether this {@link ProtocolVersion} is a legacy protocol * Returns whether this {@link ProtocolVersion} is unknown to the proxy.
* *
* @return if the protocol is legacy * @return if the protocol is unknown
*/ */
public boolean isLegacy() { public boolean isUnknown() {
return this == LEGACY; return this == UNKNOWN;
} }
@Override /**
public String toString() { * Returns whether this {@link ProtocolVersion} is a legacy protocol.
return name; *
} * @return if the protocol is legacy
*/
public boolean isLegacy() {
return this == LEGACY;
}
@Override
public String toString() {
return name;
}
} }