条件允许 进行更新预适配

This commit is contained in:
SerendipityR 2022-08-19 23:17:39 +08:00 committed by GitHub
parent 554ad4fa5b
commit 1f7c366a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 302 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../libs/MCP-1.15.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -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<String> 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;
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../libs/MCP-1.16.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="adventure" level="project" />
</component>
</module>

View File

@ -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<String> clickVerifiesHandle(ServerChatPacket packet, Session session, List<String> ClickVerifiesDetect, Component Message) {
List<String> 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;
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../libs/MCP-1.18.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="adventure" level="project" />
</component>
</module>

View File

@ -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<String> clickVerifiesHandle(ClientboundChatPacket packet, Session session, List<String> ClickVerifiesDetect, Component Message) {
List<String> 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) {}
}
}