mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Add some inline packet initialization
This commit is contained in:
parent
e635e29a16
commit
1f2dc0cd9f
@ -1379,9 +1379,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
* @param entity the entity to spectate
|
* @param entity the entity to spectate
|
||||||
*/
|
*/
|
||||||
public void spectate(@NotNull Entity entity) {
|
public void spectate(@NotNull Entity entity) {
|
||||||
CameraPacket cameraPacket = new CameraPacket();
|
playerConnection.sendPacket(new CameraPacket(entity));
|
||||||
cameraPacket.cameraId = entity.getEntityId();
|
|
||||||
playerConnection.sendPacket(cameraPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -750,10 +750,7 @@ public class InstanceContainer extends Instance {
|
|||||||
* @param blockStateId the new state of the block
|
* @param blockStateId the new state of the block
|
||||||
*/
|
*/
|
||||||
private void sendBlockChange(@NotNull Chunk chunk, @NotNull BlockPosition blockPosition, short blockStateId) {
|
private void sendBlockChange(@NotNull Chunk chunk, @NotNull BlockPosition blockPosition, short blockStateId) {
|
||||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
chunk.sendPacketToViewers(new BlockChangePacket(blockPosition, blockStateId));
|
||||||
blockChangePacket.blockPosition = blockPosition;
|
|
||||||
blockChangePacket.blockStateId = blockStateId;
|
|
||||||
chunk.sendPacketToViewers(blockChangePacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,10 +104,7 @@ public class BlockPlacementListener {
|
|||||||
//Send a block change with AIR as block to keep the client in sync,
|
//Send a block change with AIR as block to keep the client in sync,
|
||||||
//using refreshChunk results in the client not being in sync
|
//using refreshChunk results in the client not being in sync
|
||||||
//after rapid invalid block placements
|
//after rapid invalid block placements
|
||||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
player.getPlayerConnection().sendPacket(new BlockChangePacket(blockPosition, Block.AIR.getBlockId()));
|
||||||
blockChangePacket.blockPosition = blockPosition;
|
|
||||||
blockChangePacket.blockStateId = Block.AIR.getBlockId();
|
|
||||||
player.getPlayerConnection().sendPacket(blockChangePacket);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -263,13 +263,6 @@ public class PlayerDiggingListener {
|
|||||||
*/
|
*/
|
||||||
private static void sendAcknowledgePacket(@NotNull Player player, @NotNull BlockPosition blockPosition, int blockStateId,
|
private static void sendAcknowledgePacket(@NotNull Player player, @NotNull BlockPosition blockPosition, int blockStateId,
|
||||||
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
||||||
AcknowledgePlayerDiggingPacket acknowledgePlayerDiggingPacket = new AcknowledgePlayerDiggingPacket();
|
player.getPlayerConnection().sendPacket(new AcknowledgePlayerDiggingPacket(blockPosition, blockStateId, status, success));
|
||||||
acknowledgePlayerDiggingPacket.blockPosition = blockPosition;
|
|
||||||
acknowledgePlayerDiggingPacket.blockStateId = blockStateId;
|
|
||||||
acknowledgePlayerDiggingPacket.status = status;
|
|
||||||
acknowledgePlayerDiggingPacket.successful = success;
|
|
||||||
|
|
||||||
player.getPlayerConnection().sendPacket(acknowledgePlayerDiggingPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,22 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class AcknowledgePlayerDiggingPacket implements ServerPacket {
|
public class AcknowledgePlayerDiggingPacket implements ServerPacket {
|
||||||
|
|
||||||
public BlockPosition blockPosition = new BlockPosition(0,0,0);
|
public BlockPosition blockPosition;
|
||||||
public int blockStateId;
|
public int blockStateId;
|
||||||
public ClientPlayerDiggingPacket.Status status = ClientPlayerDiggingPacket.Status.STARTED_DIGGING;
|
public ClientPlayerDiggingPacket.Status status;
|
||||||
public boolean successful;
|
public boolean successful;
|
||||||
|
|
||||||
public AcknowledgePlayerDiggingPacket() {}
|
public AcknowledgePlayerDiggingPacket(@NotNull BlockPosition blockPosition, int blockStateId,
|
||||||
|
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
||||||
|
this.blockPosition = blockPosition;
|
||||||
|
this.blockStateId = blockStateId;
|
||||||
|
this.status = status;
|
||||||
|
this.successful = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcknowledgePlayerDiggingPacket() {
|
||||||
|
this(new BlockPosition(0, 0, 0), 0, ClientPlayerDiggingPacket.Status.STARTED_DIGGING, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
@ -9,13 +9,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class ActionBarPacket implements ServerPacket {
|
public class ActionBarPacket implements ServerPacket {
|
||||||
|
|
||||||
public Component actionBarText = Component.empty();
|
public Component actionBarText;
|
||||||
|
|
||||||
public ActionBarPacket() {
|
public ActionBarPacket(@NotNull Component actionBarText) {
|
||||||
|
this.actionBarText = actionBarText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionBarPacket(Component actionBarText) {
|
public ActionBarPacket() {
|
||||||
this.actionBarText = actionBarText;
|
this(Component.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,17 +1,30 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class AttachEntityPacket implements ServerPacket {
|
public class AttachEntityPacket implements ServerPacket {
|
||||||
|
|
||||||
public int attachedEntityId;
|
public int attachedEntityId;
|
||||||
public int holdingEntityId; // Or -1 to detach
|
public int holdingEntityId; // Or -1 to detach
|
||||||
|
|
||||||
public AttachEntityPacket() {}
|
public AttachEntityPacket(int attachedEntityId, int holdingEntityId) {
|
||||||
|
this.attachedEntityId = attachedEntityId;
|
||||||
|
this.holdingEntityId = holdingEntityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttachEntityPacket(@NotNull Entity attachedEntity, @Nullable Entity holdingEntity) {
|
||||||
|
this(attachedEntity.getEntityId(), holdingEntity != null ? holdingEntity.getEntityId() : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttachEntityPacket() {
|
||||||
|
this(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
@ -12,8 +12,13 @@ public class BlockChangePacket implements ServerPacket {
|
|||||||
public BlockPosition blockPosition;
|
public BlockPosition blockPosition;
|
||||||
public int blockStateId;
|
public int blockStateId;
|
||||||
|
|
||||||
|
public BlockChangePacket(BlockPosition blockPosition, int blockStateId) {
|
||||||
|
this.blockPosition = blockPosition;
|
||||||
|
this.blockStateId = blockStateId;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockChangePacket() {
|
public BlockChangePacket() {
|
||||||
blockPosition = new BlockPosition(0,0,0);
|
this(new BlockPosition(0, 0, 0), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
@ -10,7 +11,17 @@ public class CameraPacket implements ServerPacket {
|
|||||||
|
|
||||||
public int cameraId;
|
public int cameraId;
|
||||||
|
|
||||||
public CameraPacket() {}
|
public CameraPacket(int cameraId) {
|
||||||
|
this.cameraId = cameraId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraPacket(@NotNull Entity camera) {
|
||||||
|
this(camera.getEntityId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraPacket() {
|
||||||
|
this(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
@ -26,18 +26,16 @@ public class ChatMessagePacket implements ComponentHoldingServerPacket {
|
|||||||
public ChatPosition position;
|
public ChatPosition position;
|
||||||
public UUID uuid;
|
public UUID uuid;
|
||||||
|
|
||||||
public ChatMessagePacket() {
|
|
||||||
this.message = Component.empty();
|
|
||||||
this.position = ChatPosition.SYSTEM_MESSAGE;
|
|
||||||
this.uuid = NULL_UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessagePacket(@NotNull Component message, @NotNull ChatPosition position, @Nullable UUID uuid) {
|
public ChatMessagePacket(@NotNull Component message, @NotNull ChatPosition position, @Nullable UUID uuid) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.uuid = Objects.requireNonNullElse(uuid, NULL_UUID);
|
this.uuid = Objects.requireNonNullElse(uuid, NULL_UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChatMessagePacket() {
|
||||||
|
this(Component.empty(), ChatPosition.SYSTEM_MESSAGE, NULL_UUID);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
writer.writeComponent(message);
|
writer.writeComponent(message);
|
||||||
|
Loading…
Reference in New Issue
Block a user