9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-06 15:52:03 +00:00

Merge pull request #137 from jhqwqmc/dev

feat(network): 添加检测客户端版本
This commit is contained in:
XiaoMoMi
2025-04-25 18:56:33 +08:00
committed by GitHub
11 changed files with 243 additions and 17 deletions

View File

@@ -51,4 +51,12 @@ public interface NetWorkUser {
void setClientModState(boolean enable);
void addResourcePackUUID(UUID uuid);
ProtocolVersion protocolVersion();
void setProtocolVersion(int protocolVersion);
boolean sentResourcePack();
void setSentResourcePack(boolean sentResourcePack);
}

View File

@@ -9,6 +9,7 @@ import java.util.List;
public interface NetworkManager extends Manageable {
String MOD_CHANNEL = "craftengine:payload";
String VIA_CHANNEL = "vv:proxy_details";
void setUser(Channel channel, NetWorkUser user);

View File

@@ -0,0 +1,52 @@
package net.momirealms.craftengine.core.plugin.network;
public enum ProtocolVersion {
UNKNOWN(-1, "Unknown"),
V1_20(763, "1.20"),
V1_20_1(763, "1.20.1"),
V1_20_2(764, "1.20.2"),
V1_20_3(765, "1.20.3"),
V1_20_4(765, "1.20.4"),
V1_20_5(766, "1.20.5"),
V1_20_6(766, "1.20.6"),
V1_21(767, "1.21"),
V1_21_1(767, "1.21.1"),
V1_21_2(768, "1.21.2"),
V1_21_3(768, "1.21.3"),
V1_21_4(769, "1.21.4"),
V1_21_5(770, "1.21.5");
private final int id;
private final String name;
ProtocolVersion(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public static ProtocolVersion getByName(String name) {
for (ProtocolVersion version : values()) {
if (version.getName().equals(name)) {
return version;
}
}
return UNKNOWN;
}
public static ProtocolVersion getById(int id) {
for (ProtocolVersion version : values()) {
if (version.getId() == id) {
return version;
}
}
return UNKNOWN;
}
}

View File

@@ -0,0 +1,10 @@
package net.momirealms.craftengine.core.util;
import net.momirealms.craftengine.core.plugin.network.ProtocolVersion;
public class ProtocolVersionUtils {
public static boolean isVersionNewerThan(ProtocolVersion version, ProtocolVersion targetVersion) {
return version.getId() >= targetVersion.getId();
}
}