Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Implement new protocol version registry
Dieser Commit ist enthalten in:
Ursprung
c48922eb3e
Commit
09f484f956
@ -82,11 +82,11 @@ public class ProtocolPipeline extends Protocol {
|
||||
String packet = "UNKNOWN";
|
||||
|
||||
// For 1.8/1.9 server version, eventually we'll probably get an API for this...
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.V1_8 &&
|
||||
ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.V1_9_2) {
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_8.getId() &&
|
||||
ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.v1_9_2.getId()) {
|
||||
|
||||
PacketType type;
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL == ProtocolVersion.V1_8) {
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL == ProtocolVersion.v1_8.getId()) {
|
||||
if (direction == Direction.INCOMING) {
|
||||
type = PacketType.findNewPacket(state, direction, originalID);
|
||||
} else {
|
||||
|
@ -14,8 +14,8 @@ public class ProtocolRegistry {
|
||||
|
||||
static {
|
||||
// Register built in protocols
|
||||
registerProtocol(new Protocol1_9TO1_8(), Collections.singletonList(ProtocolVersion.V1_9), ProtocolVersion.V1_8);
|
||||
registerProtocol(new Protocol1_9_1TO1_9(), Arrays.asList(ProtocolVersion.V1_9_1, ProtocolVersion.V1_9_2), ProtocolVersion.V1_9);
|
||||
registerProtocol(new Protocol1_9TO1_8(), Collections.singletonList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_8.getId());
|
||||
registerProtocol(new Protocol1_9_1TO1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,13 +1,46 @@
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class ProtocolVersion {
|
||||
/* Defined protocol constants */
|
||||
public static final int V1_7_1 = 4;
|
||||
public static final int V1_7_6 = 5;
|
||||
private static final Map<Integer, ProtocolVersion> versions = new HashMap<>();
|
||||
|
||||
public static final int V1_8 = 47;
|
||||
public static final ProtocolVersion v1_7_1;
|
||||
public static final ProtocolVersion v1_7_6;
|
||||
public static final ProtocolVersion v1_8;
|
||||
public static final ProtocolVersion v1_9;
|
||||
public static final ProtocolVersion v1_9_1;
|
||||
public static final ProtocolVersion v1_9_2;
|
||||
|
||||
public static final int V1_9 = 107;
|
||||
public static final int V1_9_1 = 108; // used for 1.9.1
|
||||
public static final int V1_9_2 = 109;
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
static {
|
||||
register(v1_7_1 = new ProtocolVersion(4, "1.7-1.7.5"));
|
||||
register(v1_7_6 = new ProtocolVersion(5, "1.7.6-1.7.10"));
|
||||
register(v1_8 = new ProtocolVersion(4, "1.8.x"));
|
||||
register(v1_9 = new ProtocolVersion(107, "1.9"));
|
||||
register(v1_9_1 = new ProtocolVersion(108, "1.9.1"));
|
||||
register(v1_9_2 = new ProtocolVersion(109, "1.9.2"));
|
||||
}
|
||||
|
||||
public static void register(@NonNull ProtocolVersion protocol) {
|
||||
versions.put(protocol.getId(), protocol);
|
||||
}
|
||||
|
||||
public static boolean isRegistered(int id) {
|
||||
return versions.containsKey(id);
|
||||
}
|
||||
|
||||
public static ProtocolVersion getProtocol(int id) {
|
||||
return versions.get(id);
|
||||
}
|
||||
|
||||
public static List<ProtocolVersion> getProtocols() {
|
||||
return Collections.unmodifiableList(new ArrayList<ProtocolVersion>(versions.values()));
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class ViaBossBar implements BossBar {
|
||||
}
|
||||
|
||||
private void sendPacket(UUID uuid, ByteBuf buf) {
|
||||
if (!ViaVersion.getInstance().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.V1_9)) {
|
||||
if (!ViaVersion.getInstance().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
players.remove(uuid);
|
||||
return;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -38,7 +39,7 @@ public class ListSubCmd extends ViaSubCommand {
|
||||
Map<Integer, Set<String>> sorted = new TreeMap<>(playerVersions);
|
||||
|
||||
for (Map.Entry<Integer, Set<String>> entry : sorted.entrySet())
|
||||
sender.sendMessage(String.format(color("&8[&6%s&8]: &b%s"), entry.getKey(), entry.getValue())); //TODO: Make versions like [1.8,1.9,1.9.1,1.9.2,etc] instead of protocol id
|
||||
sender.sendMessage(String.format(color("&8[&6%s&8]: &b%s"), ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue()));
|
||||
|
||||
sorted.clear();
|
||||
return true;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren