From 1f7c366a3abac2882d4438ed5444f00224977260 Mon Sep 17 00:00:00 2001 From: SerendipityR <48401197+SerendipityR-2022@users.noreply.github.com> Date: Fri, 19 Aug 2022 23:17:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=85=81=E8=AE=B8=20?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=9B=B4=E6=96=B0=E9=A2=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VersionSupport-578/VersionSupport-578.iml | 20 +++ .../VersionControl/VersionSupport578.java | 41 ++++++ VersionSupport-754/VersionSupport-754.iml | 21 +++ .../VersionControl/VersionSupport754.java | 61 ++++++++ VersionSupport-758/VersionSupport-758.iml | 21 +++ .../VersionControl/VersionSupport758.java | 138 ++++++++++++++++++ 6 files changed, 302 insertions(+) create mode 100644 VersionSupport-578/VersionSupport-578.iml create mode 100644 VersionSupport-578/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport578.java create mode 100644 VersionSupport-754/VersionSupport-754.iml create mode 100644 VersionSupport-754/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport754.java create mode 100644 VersionSupport-758/VersionSupport-758.iml create mode 100644 VersionSupport-758/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport758.java diff --git a/VersionSupport-578/VersionSupport-578.iml b/VersionSupport-578/VersionSupport-578.iml new file mode 100644 index 0000000..ece4b54 --- /dev/null +++ b/VersionSupport-578/VersionSupport-578.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VersionSupport-578/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport578.java b/VersionSupport-578/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport578.java new file mode 100644 index 0000000..ebe613d --- /dev/null +++ b/VersionSupport-578/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport578.java @@ -0,0 +1,41 @@ +package cn.serendipityr.EndMinecraftPlusV2.VersionControl; + +import com.github.steveice10.mc.protocol.data.message.Message; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.github.steveice10.packetlib.ProxyInfo; +import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.tcp.TcpSessionFactory; + +import java.util.List; + +public class VersionSupport578 { + public TcpSessionFactory createTcpSessionFactory(ProxyInfo proxyInfo) { + return new TcpSessionFactory(proxyInfo); + } + + public static boolean clickVerifiesHandle(Message message, Session session, List ClickVerifiesDetect) { + boolean needClick = false; + + if (message.getStyle().getClickEvent() != null) { + for (String clickVerifiesDetect:ClickVerifiesDetect) { + if (message.toString().contains(clickVerifiesDetect)) { + needClick = true; + break; + } + } + } + + if (needClick) { + session.send(new ClientChatPacket(message.getStyle().getClickEvent().getValue())); + return true; + } + + if (message.getExtra() != null && !message.getExtra().isEmpty()) { + for (Message extraMessage:message.getExtra()) { + clickVerifiesHandle(extraMessage, session, ClickVerifiesDetect); + } + } + + return false; + } +} diff --git a/VersionSupport-754/VersionSupport-754.iml b/VersionSupport-754/VersionSupport-754.iml new file mode 100644 index 0000000..d9fc988 --- /dev/null +++ b/VersionSupport-754/VersionSupport-754.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VersionSupport-754/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport754.java b/VersionSupport-754/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport754.java new file mode 100644 index 0000000..48ad5b3 --- /dev/null +++ b/VersionSupport-754/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport754.java @@ -0,0 +1,61 @@ +package cn.serendipityr.EndMinecraftPlusV2.VersionControl; + +import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; +import com.github.steveice10.packetlib.ProxyInfo; +import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.tcp.TcpClientSession; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class VersionSupport754 { + public static Session getSession(String ip, Integer port, String username, ProxyInfo proxyInfo) { + return new TcpClientSession(ip, port, new MinecraftProtocol(username), proxyInfo); + } + + public static List clickVerifiesHandle(ServerChatPacket packet, Session session, List ClickVerifiesDetect, Component Message) { + List result = new ArrayList<>(); + boolean needClick = false; + Component message; + + if (Message != null) { + message = Message; + } else { + message = packet.getMessage(); + } + + String simpleMsg = PlainTextComponentSerializer.plainText().serialize(message); + + if (message.style().clickEvent() != null) { + for (String clickVerifiesDetect:ClickVerifiesDetect) { + if (simpleMsg.contains(clickVerifiesDetect)) { + needClick = true; + break; + } + } + } + + if (needClick) { + session.send(new ClientChatPacket(Objects.requireNonNull(message.style().clickEvent()).value())); + result.add("1"); + result.add(simpleMsg); + result.add(Objects.requireNonNull(message.style().clickEvent()).value()); + return result; + } + + if (!message.children().isEmpty()) { + for (Component extraMessage:message.children()) { + clickVerifiesHandle(null, session, ClickVerifiesDetect, extraMessage); + } + } + + result.add("0"); + result.add(simpleMsg); + return result; + } +} diff --git a/VersionSupport-758/VersionSupport-758.iml b/VersionSupport-758/VersionSupport-758.iml new file mode 100644 index 0000000..4deac39 --- /dev/null +++ b/VersionSupport-758/VersionSupport-758.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VersionSupport-758/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport758.java b/VersionSupport-758/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport758.java new file mode 100644 index 0000000..51f9e3b --- /dev/null +++ b/VersionSupport-758/src/cn/serendipityr/EndMinecraftPlusV2/VersionControl/VersionSupport758.java @@ -0,0 +1,138 @@ +package cn.serendipityr.EndMinecraftPlusV2.VersionControl; + +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientInformationPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCommandSuggestionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket; +import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.packet.Packet; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class VersionSupport758 { + public static List clickVerifiesHandle(ClientboundChatPacket packet, Session session, List ClickVerifiesDetect, Component Message) { + List result = new ArrayList<>(); + boolean needClick = false; + Component message; + + if (Message != null) { + message = Message; + } else { + message = packet.getMessage(); + } + + String simpleMsg = PlainTextComponentSerializer.plainText().serialize(message); + + if (message.style().clickEvent() != null) { + for (String clickVerifiesDetect:ClickVerifiesDetect) { + if (simpleMsg.contains(clickVerifiesDetect)) { + needClick = true; + break; + } + } + } + + if (needClick) { + session.send(new ServerboundChatPacket(Objects.requireNonNull(message.style().clickEvent()).value())); + result.add("1"); + result.add(simpleMsg); + result.add(Objects.requireNonNull(message.style().clickEvent()).value()); + return result; + } + + if (!message.children().isEmpty()) { + for (Component extraMessage:message.children()) { + clickVerifiesHandle(null, session, ClickVerifiesDetect, extraMessage); + } + } + + result.add("0"); + result.add(simpleMsg); + return result; + } + + public static void sendClientSettingPacket(Session session, String locale) { + try { + Class cls = ServerboundClientInformationPacket.class; + Constructor constructor; + ServerboundClientInformationPacket packet; + try { + Class parm1Class = Class.forName("com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility"); + Class parm2Class = Class.forName("com.github.steveice10.mc.protocol.data.game.setting.SkinPart;"); + Class parm3Class = Class.forName("com.github.steveice10.mc.protocol.data.game.entity.player.Hand"); + + Class skinClass = Class.forName("com.github.steveice10.mc.protocol.data.game.setting.SkinPart"); + Object[] arrSkin = (Object[]) Array.newInstance(skinClass, 1); + Array.set(arrSkin, 0, skinClass.getEnumConstants()[0]); + + constructor = cls.getConstructor(String.class, int.class, parm1Class, boolean.class, parm2Class, parm3Class); + packet = (ServerboundClientInformationPacket) constructor.newInstance(locale, 10, parm1Class.getEnumConstants()[0], true, arrSkin, parm3Class.getEnumConstants()[0]); + } catch (NoSuchMethodException ex) { + Class parm1Class = Class.forName("com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientInformationPacket.chatVisibility"); + Class parm2Class = Class.forName("com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChangeDifficultyPacket.difficulty"); + + constructor = cls.getConstructor(String.class, int.class, parm1Class, boolean.class, parm2Class, boolean.class); + packet = (ServerboundClientInformationPacket) constructor.newInstance(locale, 10, parm1Class.getEnumConstants()[0], true, parm2Class.getEnumConstants()[0], true); + } + session.send(packet); + } catch (Exception ignored) {} + } + + public static void sendClientPlayerChangeHeldItemPacket(Session session, int slot) { + try { + Class cls = Class.forName("com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket"); + Constructor constructor = cls.getConstructor(int.class); + Packet packet = (Packet) constructor.newInstance(slot); + session.send(packet); + } catch (Exception ignored) {} + } + + public static void sendClientTeleportConfirmPacket(Session session, Packet packet) { + try { + Class cls = Class.forName("com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket"); + Constructor constructor = cls.getConstructor(int.class); + session.send(packet); + } catch (Exception ignored) {} + } + + public static void sendPosPacket(Session session, double x, double y, double z, float yaw, float pitch) { + try { + Class cls = ServerboundMovePlayerPosRotPacket.class; + Constructor constructor; + ServerboundMovePlayerPosRotPacket packet; + try { + constructor = cls.getConstructor(boolean.class, double.class, double.class, double.class, float.class, float.class); + packet = (ServerboundMovePlayerPosRotPacket) constructor.newInstance(true, x, y, z, yaw, pitch); + } catch (NoSuchMethodException ex) { + constructor = cls.getConstructor(boolean.class, double.class, double.class, double.class, double.class, float.class, float.class); + packet = (ServerboundMovePlayerPosRotPacket) constructor.newInstance(true, x, y - 1.62, y , z, yaw, pitch); + } + session.send(packet); + } catch (Exception ignored) {} + } + + public static void sendChatPacket(Session session, String msg) { + session.send(new ServerboundChatPacket(msg)); + } + + public static void sendTabPacket(Session session, String text) { + try { + Class cls = ServerboundCommandSuggestionPacket.class; + Constructor constructor = cls.getDeclaredConstructor(); + constructor.setAccessible(true); + ServerboundCommandSuggestionPacket packet = (ServerboundCommandSuggestionPacket) constructor.newInstance(); + Field field = cls.getDeclaredField("text"); + field.setAccessible(true); + field.set(packet, text); + session.send(packet); + } catch (Exception ignored) {} + } +}