Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 13:52:50 +02:00
Use new method for finding cause, might need updating with disconnect. Can't replicate disconnect spam on any version on my machine. Also move to JSON for all because older versions don't have GSON :( in main package
Dieser Commit ist enthalten in:
Ursprung
fee986d215
Commit
1a90f0eb28
@ -44,13 +44,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
if (!(cause.getCause().getCause() instanceof CancelException)) {
|
||||
if (!(cause.getCause() instanceof CancelException)) {
|
||||
if (!(cause instanceof CancelException)) {
|
||||
if (PacketUtil.containsCause(cause, CancelException.class)) return;
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,12 +72,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
if (!(cause.getCause().getCause() instanceof CancelException)) {
|
||||
if (!(cause.getCause() instanceof CancelException)) {
|
||||
if (!(cause instanceof CancelException)) {
|
||||
if (PacketUtil.containsCause(cause, CancelException.class)) return;
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package us.myles.ViaVersion.transformers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||
import org.spacehq.mc.protocol.util.NetUtil;
|
||||
|
||||
import us.myles.ViaVersion.CancelException;
|
||||
import us.myles.ViaVersion.ConnectionInfo;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
@ -28,7 +25,8 @@ import java.util.*;
|
||||
import static us.myles.ViaVersion.util.PacketUtil.*;
|
||||
|
||||
public class OutgoingTransformer {
|
||||
private static Gson gson = new Gson();
|
||||
private static JSONParser parser = new JSONParser();
|
||||
|
||||
private final ConnectionInfo info;
|
||||
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||
private boolean cancel = false;
|
||||
@ -193,9 +191,14 @@ public class OutgoingTransformer {
|
||||
|
||||
if (packet == PacketType.STATUS_RESPONSE) {
|
||||
String original = PacketUtil.readString(input);
|
||||
JsonObject object = gson.fromJson(original, JsonObject.class);
|
||||
object.get("version").getAsJsonObject().addProperty("protocol", info.getProtocol());
|
||||
PacketUtil.writeString(gson.toJson(object), output);
|
||||
try {
|
||||
JSONObject json = (JSONObject) parser.parse(original);
|
||||
JSONObject version = (JSONObject) json.get("version");
|
||||
version.put("protocol", info.getProtocol());
|
||||
PacketUtil.writeString(json.toJSONString(), output);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (packet == PacketType.LOGIN_SUCCESS) {
|
||||
@ -522,9 +525,8 @@ public class OutgoingTransformer {
|
||||
line = "{\"text\":" + line + "}";
|
||||
}
|
||||
try {
|
||||
new JSONParser().parse(line);
|
||||
}
|
||||
catch (org.json.simple.parser.ParseException e) {
|
||||
parser.parse(line);
|
||||
} catch (org.json.simple.parser.ParseException e) {
|
||||
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github!");
|
||||
return "{\"text\":\"\"}";
|
||||
}
|
||||
|
@ -414,4 +414,12 @@ public class PacketUtil {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
|
||||
while (t != null) {
|
||||
t = t.getCause();
|
||||
if (c.isAssignableFrom(t.getClass())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren