|
|
|
@@ -24,7 +24,6 @@ import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.event.DataComponentValue;
|
|
|
|
import net.kyori.adventure.text.event.DataComponentValue;
|
|
|
|
import net.kyori.adventure.text.event.HoverEvent;
|
|
|
|
import net.kyori.adventure.text.event.HoverEvent;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
|
|
|
|
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
|
|
|
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
|
|
|
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
|
|
|
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
|
|
|
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
|
|
|
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
|
|
|
@@ -135,12 +134,12 @@ import java.nio.charset.StandardCharsets;
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
|
|
|
|
|
|
public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
private static BukkitNetworkManager instance;
|
|
|
|
private static BukkitNetworkManager instance;
|
|
|
|
private static Tristate enforceSecureProfile = Tristate.UNDEFINED;
|
|
|
|
|
|
|
|
private final BukkitCraftEngine plugin;
|
|
|
|
private final BukkitCraftEngine plugin;
|
|
|
|
private final Map<Class<?>, NMSPacketListener> nmsPacketListeners = new IdentityHashMap<>(128);
|
|
|
|
private final Map<Class<?>, NMSPacketListener> nmsPacketListeners = new IdentityHashMap<>(128);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -175,6 +174,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean hasModelEngine;
|
|
|
|
private final boolean hasModelEngine;
|
|
|
|
private final boolean hasViaVersion;
|
|
|
|
private final boolean hasViaVersion;
|
|
|
|
|
|
|
|
private final boolean hasAntiPopup;
|
|
|
|
|
|
|
|
|
|
|
|
private int[] blockStateRemapper;
|
|
|
|
private int[] blockStateRemapper;
|
|
|
|
private int[] modBlockStateRemapper;
|
|
|
|
private int[] modBlockStateRemapper;
|
|
|
|
@@ -184,6 +184,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
Plugin modelEngine = Bukkit.getPluginManager().getPlugin("ModelEngine");
|
|
|
|
Plugin modelEngine = Bukkit.getPluginManager().getPlugin("ModelEngine");
|
|
|
|
this.hasModelEngine = modelEngine != null && modelEngine.getPluginMeta().getVersion().startsWith("R4");
|
|
|
|
this.hasModelEngine = modelEngine != null && modelEngine.getPluginMeta().getVersion().startsWith("R4");
|
|
|
|
this.hasViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
|
|
|
this.hasViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
|
|
|
|
|
|
|
this.hasAntiPopup = Bukkit.getPluginManager().getPlugin("AntiPopup") != null;
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.plugin = plugin;
|
|
|
|
// set up packet id
|
|
|
|
// set up packet id
|
|
|
|
this.packetIds = VersionHelper.isOrAbove1_20_5() ? new PacketIds1_20_5() : new PacketIds1_20();
|
|
|
|
this.packetIds = VersionHelper.isOrAbove1_20_5() ? new PacketIds1_20_5() : new PacketIds1_20();
|
|
|
|
@@ -230,6 +231,20 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
if (VersionHelper.isLeaves()) {
|
|
|
|
if (VersionHelper.isLeaves()) {
|
|
|
|
this.injectLeavesBotList();
|
|
|
|
this.injectLeavesBotList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 对安装了 FreedomChat 的用户告警
|
|
|
|
|
|
|
|
if (Bukkit.getPluginManager().getPlugin("FreedomChat") != null) {
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
|
|
|
|
plugin.logger().severe("");
|
|
|
|
|
|
|
|
if (Locale.getDefault() == Locale.SIMPLIFIED_CHINESE) {
|
|
|
|
|
|
|
|
plugin.logger().severe("CraftEngine 与 FreedomChat 不兼容,请立刻卸载 FreedomChat");
|
|
|
|
|
|
|
|
plugin.logger().severe("同时使用可能会导致物品显示异常或无法正确翻译数据包等情况");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
plugin.logger().severe("CraftEngine is incompatible with FreedomChat. Please uninstall FreedomChat immediately.");
|
|
|
|
|
|
|
|
plugin.logger().severe("Simultaneous use may result in item display anomalies or failure to correctly translate network packets.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin.logger().severe("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static BukkitNetworkManager instance() {
|
|
|
|
public static BukkitNetworkManager instance() {
|
|
|
|
@@ -504,8 +519,25 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
() -> {}, 1, 1);
|
|
|
|
() -> {}, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.sendPacket(TotemAnimationCommand.FIX_TOTEM_SOUND_PACKET, false);
|
|
|
|
user.sendPacket(TotemAnimationCommand.FIX_TOTEM_SOUND_PACKET, false);
|
|
|
|
|
|
|
|
Channel channel = user.nettyChannel();
|
|
|
|
|
|
|
|
if (this.hasAntiPopup && Config.disableChatReport() && channel != null) {
|
|
|
|
|
|
|
|
removeAntiPopupHandler(channel, 0); // 功能冲突直接移除
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void removeAntiPopupHandler(Channel channel, int times) {
|
|
|
|
|
|
|
|
if (times > 5) {
|
|
|
|
|
|
|
|
Debugger.COMMON.debug(() -> "antipopup_handler Removed Failed");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel.pipeline().get("antipopup_handler") == null) {
|
|
|
|
|
|
|
|
plugin.scheduler().asyncLater(() -> removeAntiPopupHandler(channel, times + 1), 1, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.pipeline().remove("antipopup_handler");
|
|
|
|
|
|
|
|
Debugger.COMMON.debug(() -> "antipopup_handler Handler Removed (" + times + ")");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
|
|
@@ -543,13 +575,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Object settings = CoreReflections.field$DedicatedServer$settings.get(FastNMS.INSTANCE.method$MinecraftServer$getServer());
|
|
|
|
Object settings = CoreReflections.field$DedicatedServer$settings.get(FastNMS.INSTANCE.method$MinecraftServer$getServer());
|
|
|
|
Object properties = CoreReflections.field$DedicatedServerSettings$properties.get(settings);
|
|
|
|
Object properties = CoreReflections.field$DedicatedServerSettings$properties.get(settings);
|
|
|
|
boolean enforceSecureProfile = (boolean) CoreReflections.methodHandle$DedicatedServerProperties$enforceSecureProfileGetter.invoke(properties);
|
|
|
|
CoreReflections.methodHandle$DedicatedServerProperties$enforceSecureProfileSetter.invoke(properties, false);
|
|
|
|
if (BukkitNetworkManager.enforceSecureProfile == Tristate.UNDEFINED) {
|
|
|
|
|
|
|
|
BukkitNetworkManager.enforceSecureProfile = Tristate.of(enforceSecureProfile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BukkitNetworkManager.enforceSecureProfile.asBoolean()) { // 如果启用才修改
|
|
|
|
|
|
|
|
CoreReflections.methodHandle$DedicatedServerProperties$enforceSecureProfileSetter.invoke(properties, !Config.disableChatReport());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new InjectionException("Error injecting secure profile", e);
|
|
|
|
throw new InjectionException("Error injecting secure profile", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -558,12 +584,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
Bukkit.getPluginManager().registerEvents(this, this.plugin.javaPlugin());
|
|
|
|
Bukkit.getPluginManager().registerEvents(this, this.plugin.javaPlugin());
|
|
|
|
|
|
|
|
if (Config.disableChatReport()) {
|
|
|
|
updateEnforceSecureProfile();
|
|
|
|
updateEnforceSecureProfile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void load() {
|
|
|
|
|
|
|
|
updateEnforceSecureProfile();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@@ -1574,6 +1597,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object chatType = FastNMS.INSTANCE.field$ClientboundPlayerChatPacket$chatType(packet);
|
|
|
|
Object chatType = FastNMS.INSTANCE.field$ClientboundPlayerChatPacket$chatType(packet);
|
|
|
|
|
|
|
|
if (!VersionHelper.isOrAbove1_20_5()) {
|
|
|
|
|
|
|
|
chatType = FastNMS.INSTANCE.method$ChatType$BoundNetwork$resolve(chatType);
|
|
|
|
|
|
|
|
}
|
|
|
|
Object decorate = FastNMS.INSTANCE.method$ChatType$Bound$decorate(chatType, content);
|
|
|
|
Object decorate = FastNMS.INSTANCE.method$ChatType$Bound$decorate(chatType, content);
|
|
|
|
if (Config.allowEmojiChat()) {
|
|
|
|
if (Config.allowEmojiChat()) {
|
|
|
|
String rawJsonMessage = ComponentUtils.minecraftToJson(decorate);
|
|
|
|
String rawJsonMessage = ComponentUtils.minecraftToJson(decorate);
|
|
|
|
@@ -2011,7 +2037,11 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onPacketSend(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
|
|
|
public void onPacketSend(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
|
|
|
user.setEncoderState(VersionHelper.isOrAbove1_20_2() ? ConnectionState.CONFIGURATION : ConnectionState.PLAY);
|
|
|
|
if (VersionHelper.isOrAbove1_20_2()) {
|
|
|
|
|
|
|
|
user.setEncoderState(ConnectionState.CONFIGURATION);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
user.setConnectionState(ConnectionState.PLAY);
|
|
|
|
|
|
|
|
}
|
|
|
|
GameProfile gameProfile = FastNMS.INSTANCE.field$ClientboundLoginFinishedPacket$gameProfile(packet);
|
|
|
|
GameProfile gameProfile = FastNMS.INSTANCE.field$ClientboundLoginFinishedPacket$gameProfile(packet);
|
|
|
|
if (VersionHelper.isOrAbove1_21_9()) {
|
|
|
|
if (VersionHelper.isOrAbove1_21_9()) {
|
|
|
|
user.setVerifiedName(gameProfile.name());
|
|
|
|
user.setVerifiedName(gameProfile.name());
|
|
|
|
@@ -2107,8 +2137,11 @@ public class BukkitNetworkManager implements NetworkManager, Listener {
|
|
|
|
case 2, 3 -> ConnectionState.LOGIN;
|
|
|
|
case 2, 3 -> ConnectionState.LOGIN;
|
|
|
|
default -> null;
|
|
|
|
default -> null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (nextState == null) {
|
|
|
|
if (nextState == null) { // 如果乱发包直接强行断开连接
|
|
|
|
user.kick(Component.text("Illegal packet", NamedTextColor.RED));
|
|
|
|
Channel channel = user.nettyChannel();
|
|
|
|
|
|
|
|
if (channel != null) {
|
|
|
|
|
|
|
|
channel.pipeline().disconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (BukkitNetworkManager.instance.hasViaVersion) {
|
|
|
|
if (BukkitNetworkManager.instance.hasViaVersion) {
|
|
|
|
|