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

refactor: drop protocollib, swap remaining packets to nms

This commit is contained in:
Boy
2025-05-01 11:15:26 +02:00
committed by Boy0000
parent 0f0baaf474
commit eaa1228708
11 changed files with 244 additions and 187 deletions

View File

@@ -2,6 +2,7 @@ package me.lojosho.hibiscuscommons.nms;
import it.unimi.dsi.fastutil.ints.IntList;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Display;
import org.bukkit.entity.EntityType;
@@ -20,10 +21,13 @@ public interface NMSPackets {
static int POSITION_INTERPOLATION_DURATION = 2;
void sendSlotUpdate(
Player player,
int slot
);
void sendGamemodeChange(Player player, GameMode gameMode);
void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo);
void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo);
void sendSlotUpdate(Player player, int slot);
void sendEquipmentSlotUpdate(
int entityId,
@@ -58,8 +62,6 @@ public interface NMSPackets {
List<Player> sendTo
);
void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo);
void sendCameraPacket(int entityId, List<Player> sendTo);
void sendSpawnEntityPacket(int entityId, UUID uuid, EntityType entityType, Location location, List<Player> sendTo);

View File

@@ -2,7 +2,6 @@ package me.lojosho.hibiscuscommons.nms;
import org.bukkit.Color;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,12 +1,12 @@
package me.lojosho.hibiscuscommons.util;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import org.bukkit.Color;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -21,14 +21,8 @@ public class ServerUtils {
}
@Nullable
public static WrappedSignedProperty getSkin(Player player) {
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
.get("textures").stream().findAny().orElse(null);
if (skinData == null) {
return null;
}
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
public static PlayerTextures getSkin(Player player) {
return player.getPlayerProfile().getTextures();
}
/**

View File

@@ -1,12 +1,10 @@
package me.lojosho.hibiscuscommons.util.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.MessagesUtil;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -34,14 +32,9 @@ public class PacketManager {
public static void gamemodeChangePacket(
Player player,
int gamemode
GameMode gamemode
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
packet.getGameStateIDs().write(0, 3);
// Tells what event this is. This is a change gamemode event.
packet.getFloat().write(0, (float) gamemode);
sendPacket(player, packet);
MessagesUtil.sendDebugMessages("Gamemode Change sent to " + player + " to be " + gamemode);
NMSHandlers.getHandler().getPacketHandler().sendGamemodeChange(player, gamemode);
}
public static void ridingMountPacket(
@@ -52,15 +45,12 @@ public class PacketManager {
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, new int[]{passengerId}, sendTo);
}
public static void sendLookPacket(
public static void sendRotateHeadPacket(
int entityId,
@NotNull Location location,
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
for (Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendRotateHeadPacket(entityId, location, sendTo);
}
public static void sendRotationPacket(
@@ -69,29 +59,7 @@ public class PacketManager {
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw = location.getYaw() * ROTATION_FACTOR;
float pitch = location.getPitch() * ROTATION_FACTOR;
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) yaw);
packet.getBytes().write(1, (byte) pitch);
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
packet.getBooleans().write(0, onGround);
for (Player p : sendTo) sendPacket(p, packet);
}
public static void sendRotationPacket(
int entityId,
int yaw,
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw2 = yaw * ROTATION_FACTOR;
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, yaw2, onGround, sendTo);
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, location, onGround, sendTo);
}
public static void sendRidingPacket(
@@ -213,9 +181,4 @@ public class PacketManager {
return players;
}
public static void sendPacket(Player player, PacketContainer packet) {
if (player == null) return;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
}
}