9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

feat: add nms support for camera packet

This commit is contained in:
LoJoSho
2024-12-29 16:49:38 -06:00
parent 3c4b021706
commit 556729bada
9 changed files with 87 additions and 4 deletions

View File

@@ -49,4 +49,6 @@ public interface NMSPackets {
);
void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo);
void sendCameraPacket(int entityId, List<Player> sendTo);
}

View File

@@ -147,9 +147,7 @@ public class PacketManager {
* @param sendTo The players that will be sent this packet
*/
public static void sendCameraPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
packet.getIntegers().write(0, entityId);
for (final Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendCameraPacket(entityId, sendTo);
MessagesUtil.sendDebugMessages(sendTo + " | " + entityId + " has had a camera packet on them!");
}

View File

@@ -222,4 +222,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -222,4 +222,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -223,4 +223,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -222,4 +222,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -19,7 +19,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Constructor;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -232,4 +231,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -211,4 +211,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -211,4 +211,16 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
e.printStackTrace();
}
}
@Override
public void sendCameraPacket(int entityId, List<Player> sendTo) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeVarInt(entityId);
try {
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
for (Player p : sendTo) sendPacket(p, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}