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:
@@ -33,7 +33,7 @@ allprojects {
|
|||||||
maven("https://repo.nexomc.com/snapshots/")
|
maven("https://repo.nexomc.com/snapshots/")
|
||||||
maven("https://repo.nexomc.com/releases/")
|
maven("https://repo.nexomc.com/releases/")
|
||||||
|
|
||||||
// Geary & Backup ProtocolLib repo
|
// Geary repo
|
||||||
maven("https://repo.mineinabyss.com/releases/")
|
maven("https://repo.mineinabyss.com/releases/")
|
||||||
maven("https://repo.mineinabyss.com/snapshots/")
|
maven("https://repo.mineinabyss.com/snapshots/")
|
||||||
|
|
||||||
@@ -55,9 +55,6 @@ allprojects {
|
|||||||
// PlaceholderAPI
|
// PlaceholderAPI
|
||||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||||
|
|
||||||
// ProtocolLib
|
|
||||||
maven("https://repo.dmulloy2.net/repository/public/")
|
|
||||||
|
|
||||||
// Oraxen
|
// Oraxen
|
||||||
maven("https://repo.oraxen.com/releases")
|
maven("https://repo.oraxen.com/releases")
|
||||||
|
|
||||||
@@ -83,7 +80,7 @@ allprojects {
|
|||||||
compileOnly("com.mojang:authlib:3.13.56")
|
compileOnly("com.mojang:authlib:3.13.56")
|
||||||
compileOnly("org.jetbrains:annotations:26.0.1")
|
compileOnly("org.jetbrains:annotations:26.0.1")
|
||||||
compileOnly("io.th0rgal:oraxen:1.182.0")
|
compileOnly("io.th0rgal:oraxen:1.182.0")
|
||||||
compileOnly("com.nexomc:nexo:1.0.0")
|
compileOnly("com.nexomc:nexo:1.4.0")
|
||||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14")
|
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14")
|
||||||
compileOnly("com.mineinabyss:geary-papermc:0.31.0-dev.4")
|
compileOnly("com.mineinabyss:geary-papermc:0.31.0-dev.4")
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.15")
|
compileOnly("it.unimi.dsi:fastutil:8.5.15")
|
||||||
@@ -98,7 +95,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
compileOnly("com.github.Xiao-MoMi:Custom-Fishing:2.3.3")
|
compileOnly("com.github.Xiao-MoMi:Custom-Fishing:2.3.3")
|
||||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
||||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
|
|
||||||
compileOnly("org.joml:joml:1.10.8")
|
compileOnly("org.joml:joml:1.10.8")
|
||||||
compileOnly("com.google.guava:guava:33.4.0-jre") // Sometimes just not included in compile time???
|
compileOnly("com.google.guava:guava:33.4.0-jre") // Sometimes just not included in compile time???
|
||||||
compileOnly("com.github.Gecolay.GSit:core:2.0.0")
|
compileOnly("com.github.Gecolay.GSit:core:2.0.0")
|
||||||
@@ -151,7 +147,6 @@ tasks {
|
|||||||
|
|
||||||
downloadPlugins {
|
downloadPlugins {
|
||||||
hangar("PlaceholderAPI", "2.11.6")
|
hangar("PlaceholderAPI", "2.11.6")
|
||||||
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
|
||||||
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar")
|
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +198,6 @@ bukkit {
|
|||||||
main = "me.lojosho.hibiscuscommons.HibiscusCommonsPlugin"
|
main = "me.lojosho.hibiscuscommons.HibiscusCommonsPlugin"
|
||||||
apiVersion = "1.20"
|
apiVersion = "1.20"
|
||||||
authors = listOf("LoJoSho")
|
authors = listOf("LoJoSho")
|
||||||
depend = listOf("ProtocolLib")
|
|
||||||
softDepend = listOf(
|
softDepend = listOf(
|
||||||
"ModelEngine",
|
"ModelEngine",
|
||||||
"Oraxen",
|
"Oraxen",
|
||||||
@@ -250,12 +244,6 @@ hangarPublish {
|
|||||||
|
|
||||||
val versions: List<String> = listOf("1.18.2-1.20.4")
|
val versions: List<String> = listOf("1.18.2-1.20.4")
|
||||||
platformVersions.set(versions)
|
platformVersions.set(versions)
|
||||||
|
|
||||||
dependencies {
|
|
||||||
hangar("ProtocolLib") {
|
|
||||||
required.set(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package me.lojosho.hibiscuscommons.nms;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Display;
|
import org.bukkit.entity.Display;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -20,10 +21,13 @@ public interface NMSPackets {
|
|||||||
|
|
||||||
static int POSITION_INTERPOLATION_DURATION = 2;
|
static int POSITION_INTERPOLATION_DURATION = 2;
|
||||||
|
|
||||||
void sendSlotUpdate(
|
void sendGamemodeChange(Player player, GameMode gameMode);
|
||||||
Player player,
|
|
||||||
int slot
|
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(
|
void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -58,8 +62,6 @@ public interface NMSPackets {
|
|||||||
List<Player> sendTo
|
List<Player> sendTo
|
||||||
);
|
);
|
||||||
|
|
||||||
void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo);
|
|
||||||
|
|
||||||
void sendCameraPacket(int entityId, List<Player> sendTo);
|
void sendCameraPacket(int entityId, List<Player> sendTo);
|
||||||
|
|
||||||
void sendSpawnEntityPacket(int entityId, UUID uuid, EntityType entityType, Location location, List<Player> sendTo);
|
void sendSpawnEntityPacket(int entityId, UUID uuid, EntityType entityType, Location location, List<Player> sendTo);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package me.lojosho.hibiscuscommons.nms;
|
|||||||
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package me.lojosho.hibiscuscommons.util;
|
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.HibiscusCommonsPlugin;
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.profile.PlayerProfile;
|
||||||
|
import org.bukkit.profile.PlayerTextures;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -21,14 +21,8 @@ public class ServerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static WrappedSignedProperty getSkin(Player player) {
|
public static PlayerTextures getSkin(Player player) {
|
||||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
return player.getPlayerProfile().getTextures();
|
||||||
.get("textures").stream().findAny().orElse(null);
|
|
||||||
|
|
||||||
if (skinData == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package me.lojosho.hibiscuscommons.util.packets;
|
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.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||||
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -34,14 +32,9 @@ public class PacketManager {
|
|||||||
|
|
||||||
public static void gamemodeChangePacket(
|
public static void gamemodeChangePacket(
|
||||||
Player player,
|
Player player,
|
||||||
int gamemode
|
GameMode gamemode
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
|
NMSHandlers.getHandler().getPacketHandler().sendGamemodeChange(player, gamemode);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ridingMountPacket(
|
public static void ridingMountPacket(
|
||||||
@@ -52,15 +45,12 @@ public class PacketManager {
|
|||||||
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, new int[]{passengerId}, sendTo);
|
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, new int[]{passengerId}, sendTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendLookPacket(
|
public static void sendRotateHeadPacket(
|
||||||
int entityId,
|
int entityId,
|
||||||
@NotNull Location location,
|
@NotNull Location location,
|
||||||
@NotNull List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
NMSHandlers.getHandler().getPacketHandler().sendRotateHeadPacket(entityId, location, sendTo);
|
||||||
packet.getIntegers().write(0, entityId);
|
|
||||||
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendRotationPacket(
|
public static void sendRotationPacket(
|
||||||
@@ -69,29 +59,7 @@ public class PacketManager {
|
|||||||
boolean onGround,
|
boolean onGround,
|
||||||
@NotNull List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, location, onGround, sendTo);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendRidingPacket(
|
public static void sendRidingPacket(
|
||||||
@@ -213,9 +181,4 @@ public class PacketManager {
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPacket(Player player, PacketContainer packet) {
|
|
||||||
if (player == null) return;
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,14 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R3;
|
package me.lojosho.hibiscuscommons.nms.v1_20_R3;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.serialization.JsonOps;
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
||||||
import net.minecraft.advancements.Advancement;
|
|
||||||
import net.minecraft.advancements.AdvancementHolder;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
@@ -25,6 +16,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
import net.minecraft.world.scores.PlayerTeam;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.v1_20_R3.CraftEquipmentSlot;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntityType;
|
||||||
@@ -36,12 +28,10 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.ItemDisplay;
|
import org.bukkit.entity.ItemDisplay;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||||
@@ -50,7 +40,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
@@ -77,13 +67,45 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -229,20 +251,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
import net.minecraft.world.scores.PlayerTeam;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
@@ -49,7 +51,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
@@ -76,13 +78,45 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -227,20 +261,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
import net.minecraft.world.scores.PlayerTeam;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
@@ -49,7 +51,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
static Constructor<ClientboundRotateHeadPacket> rotationConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotationConstructor;
|
||||||
static Constructor<ClientboundAddEntityPacket> spawnConstructor;
|
static Constructor<ClientboundAddEntityPacket> spawnConstructor;
|
||||||
|
|
||||||
@@ -79,8 +81,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -92,6 +94,37 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
@@ -237,20 +270,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
import net.minecraft.world.scores.PlayerTeam;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
@@ -51,7 +53,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
@@ -72,13 +74,45 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -215,20 +249,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
@@ -28,8 +28,10 @@ import net.minecraft.world.scores.PlayerTeam;
|
|||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
@@ -54,7 +56,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@@ -76,13 +78,45 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -219,20 +253,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.serialization.JsonOps;
|
import com.mojang.serialization.JsonOps;
|
||||||
|
import io.lumine.mythic.bukkit.utils.redis.jedis.Client;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||||
@@ -11,6 +12,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||||
import net.minecraft.advancements.*;
|
import net.minecraft.advancements.*;
|
||||||
|
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
@@ -19,8 +21,10 @@ import net.minecraft.network.syncher.SynchedEntityData;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.portal.TeleportTransition;
|
import net.minecraft.world.level.portal.TeleportTransition;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
@@ -28,8 +32,10 @@ import net.minecraft.world.scores.PlayerTeam;
|
|||||||
import net.minecraft.world.scores.Team;
|
import net.minecraft.world.scores.Team;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
@@ -53,7 +59,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
static Constructor<ClientboundRotateHeadPacket> rotateHeadConstructor;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@@ -75,13 +81,45 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
rotateHeadConstructor = ClientboundRotateHeadPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
||||||
lookAtConstructor.setAccessible(true);
|
rotateHeadConstructor.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendGamemodeChange(Player player, GameMode gameMode) {
|
||||||
|
ClientboundGameEventPacket.Type type = ClientboundGameEventPacket.CHANGE_GAME_MODE;
|
||||||
|
float param = gameMode.ordinal();
|
||||||
|
|
||||||
|
ClientboundGameEventPacket packet = new ClientboundGameEventPacket(type, param);
|
||||||
|
sendPacket(player, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotateHeadPacket(int entityId, Location location, List<Player> sendTo) {
|
||||||
|
byte headRot = (byte) (location.getYaw() * 256.0F / 360.0F);
|
||||||
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
byteBuf.writeVarInt(entityId);
|
||||||
|
byteBuf.writeByte(headRot);
|
||||||
|
try {
|
||||||
|
ClientboundRotateHeadPacket packet = rotateHeadConstructor.newInstance(byteBuf);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRotationPacket(int entityId, Location location, boolean onGround, List<Player> sendTo) {
|
||||||
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
|
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
||||||
|
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
||||||
|
ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, yaw, pitch, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEquipmentSlotUpdate(
|
public void sendEquipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
@@ -218,20 +256,6 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
|||||||
Reference in New Issue
Block a user