Обновляем пакеты
This commit is contained in:
@@ -7,8 +7,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
||||
import mc.core.text.Text;
|
||||
|
||||
@@ -19,9 +19,7 @@ public class DisconnectPacket implements SCPacket {
|
||||
private Text reason;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeString(TextSerializer.serialize(reason).toString());
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
@@ -21,16 +21,12 @@ public class EncryptionRequestPacket implements SCPacket {
|
||||
private byte[] verifyToken;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeString(serverId);
|
||||
byte[] bytes = publicKey.getEncoded();
|
||||
netStream.writeVarInt(bytes.length);
|
||||
netStream.writeBytes(bytes);
|
||||
netStream.writeVarInt(verifyToken.length);
|
||||
netStream.writeBytes(verifyToken);
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
import mc.core.player.PlayerMode;
|
||||
|
||||
@NoArgsConstructor
|
||||
@@ -20,9 +20,7 @@ public class JoinGamePacket implements SCPacket {
|
||||
private String levelType;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeInt(entityId);
|
||||
netStream.writeUnsignedByte(mode.getId());
|
||||
netStream.writeInt(dimension);
|
||||
@@ -30,7 +28,5 @@ public class JoinGamePacket implements SCPacket {
|
||||
netStream.writeUnsignedByte(0); // Max Players, unused
|
||||
netStream.writeString(levelType);
|
||||
netStream.writeBoolean(false); // Reduced Debug Info
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -20,12 +20,8 @@ public class LoginSuccessPacket implements SCPacket {
|
||||
private String playerName;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeString(uuid.toString());
|
||||
netStream.writeString(playerName);
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import lombok.ToString;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
@ToString
|
||||
public class PingPacket implements CSPacket, SCPacket {
|
||||
@@ -20,9 +19,7 @@ public class PingPacket implements CSPacket, SCPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeLong(payload);
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Setter
|
||||
@@ -20,9 +20,7 @@ public class PlayerAbilitiesPacket implements SCPacket {
|
||||
private float fieldOfView = flyingSpeed;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
byte flag = 0;
|
||||
if (godMode) flag = (byte)(flag | 0x01);
|
||||
if (flying) flag = (byte)(flag | 0x02);
|
||||
@@ -32,7 +30,5 @@ public class PlayerAbilitiesPacket implements SCPacket {
|
||||
netStream.writeByte(flag);
|
||||
netStream.writeFloat(flyingSpeed);
|
||||
netStream.writeFloat(fieldOfView);
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
import mc.core.player.Look;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -21,9 +21,7 @@ public class PlayerPositionAndLookPacket implements SCPacket {
|
||||
private Look look;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeDouble(location.getX());
|
||||
netStream.writeDouble(location.getY());
|
||||
netStream.writeDouble(location.getZ());
|
||||
@@ -37,7 +35,5 @@ public class PlayerPositionAndLookPacket implements SCPacket {
|
||||
* X_ROT - 0x10
|
||||
*/
|
||||
netStream.writeVarInt(RANDOM.nextInt()); // Client should confirm this packet with Teleport Confirm containing the same Teleport ID
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import lombok.*;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -27,12 +26,8 @@ public class PluginMessagePacket implements SCPacket, CSPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeString(channelName);
|
||||
netStream.writeBytes(data);
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.serializers.LocationSerializer;
|
||||
|
||||
@AllArgsConstructor
|
||||
@@ -19,9 +19,7 @@ public class SpawnPositionPacket implements SCPacket {
|
||||
private Location location;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeLong(LocationSerializer.serialize(location));
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
|
||||
@Setter
|
||||
@ToString
|
||||
@@ -27,9 +27,7 @@ public class StatusResponsePacket implements SCPacket {
|
||||
private byte[] faviconBase64;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
public void writeSelf(NetStream netStream) {
|
||||
JsonObject playersObj = new JsonObject();
|
||||
playersObj.addProperty("max", maxOnline);
|
||||
playersObj.addProperty("online", online);
|
||||
@@ -49,6 +47,5 @@ public class StatusResponsePacket implements SCPacket {
|
||||
}
|
||||
|
||||
netStream.writeString(rootObj.toString());
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.State;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetStream;
|
||||
|
||||
@@ -38,8 +39,10 @@ public class PacketEncoder extends MessageToByteEncoder<SCPacket> {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = packet.toByteArray();
|
||||
NetStream netStream = new WrapperNetStream(out);
|
||||
NetStream netStream = new ByteArrayOutputNetStream();
|
||||
packet.writeSelf(netStream);
|
||||
byte[] bytes = ((ByteArrayOutputNetStream) netStream).toByteArray();
|
||||
netStream = new WrapperNetStream(out);
|
||||
|
||||
netStream.writeVarInt(bytes.length + sizeVarInt(id));
|
||||
netStream.writeVarInt(id);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-10
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2;
|
||||
package mc.core.network.proto_1_12_2.netty.wrappers;
|
||||
|
||||
import mc.core.network.proto_1_12_2.NetStream_p340;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
Reference in New Issue
Block a user