Overrided toString method for packets

This commit is contained in:
Nanit 2021-10-30 13:58:19 +03:00
parent 7df4db9e10
commit aded28cfef
10 changed files with 44 additions and 0 deletions

View File

@ -42,6 +42,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
try { try {
packet.encode(msg, version); packet.encode(msg, version);
Logger.debug("Sending %s packet", packet.toString());
} catch (Exception e) { } catch (Exception e) {
Logger.warning("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage()); Logger.warning("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
} }

View File

@ -40,6 +40,11 @@ public class PreEncodedPacket implements PacketOut {
} }
} }
@Override
public String toString() {
return packet.getClass().getSimpleName();
}
public static PreEncodedPacket of(PacketOut packet) { public static PreEncodedPacket of(PacketOut packet) {
return new PreEncodedPacket(packet).encodePacket(); return new PreEncodedPacket(packet).encodePacket();
} }

View File

@ -17,4 +17,9 @@ public class PacketDisconnect implements PacketOut {
msg.writeString(String.format("{\"text\": \"%s\"}", reason)); msg.writeString(String.format("{\"text\": \"%s\"}", reason));
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -30,4 +30,9 @@ public class PacketLoginPluginRequest implements PacketOut {
msg.writeBytes(data); msg.writeBytes(data);
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -33,4 +33,9 @@ public class PacketLoginPluginResponse implements PacketIn {
} }
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -16,4 +16,8 @@ public class PacketLoginStart implements PacketIn {
this.username = msg.readString(); this.username = msg.readString();
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -25,4 +25,9 @@ public class PacketLoginSuccess implements PacketOut {
msg.writeString(username); msg.writeString(username);
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -18,4 +18,9 @@ public class PacketStatusPing implements Packet {
this.randomId = msg.readLong(); this.randomId = msg.readLong();
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -10,4 +10,8 @@ public class PacketStatusRequest implements PacketIn {
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
} }

View File

@ -26,6 +26,11 @@ public class PacketStatusResponse implements PacketOut {
msg.writeString(json); msg.writeString(json);
} }
@Override
public String toString() {
return getClass().getSimpleName();
}
private String getResponseJson(String version, int protocol, int maxPlayers, int online, String description) { private String getResponseJson(String version, int protocol, int maxPlayers, int online, String description) {
return String.format(TEMPLATE, version, protocol, maxPlayers, online, description); return String.format(TEMPLATE, version, protocol, maxPlayers, online, description);
} }