diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java index c7c6e01..a476db9 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java @@ -97,12 +97,5 @@ public interface NMSPackets { void sendToastPacket(Player player, ItemStack icon, Component title, Component description); - void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo); - - // The mask here is for is the armorstand is on fire or not. - void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo); - - void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo); - Object createMountPacket(int entityId, int[] passengerIds); } diff --git a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSCommon.java b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSCommon.java index 5d876d7..0fa2d1e 100644 --- a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSCommon.java +++ b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSCommon.java @@ -1,33 +1,17 @@ package me.lojosho.hibiscuscommons.nms.v1_20_R4; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); - } } diff --git a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java index bc540a1..0ff338a 100644 --- a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java +++ b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java @@ -57,17 +57,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -80,7 +73,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -473,59 +467,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } } diff --git a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSCommon.java b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSCommon.java index f56884e..d612c94 100644 --- a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSCommon.java +++ b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSCommon.java @@ -1,33 +1,17 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R1; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); - } } diff --git a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java index 1fd482a..2c1076e 100644 --- a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java +++ b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java @@ -1,6 +1,7 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R1; import com.google.common.collect.ImmutableList; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -9,6 +10,7 @@ import com.mojang.serialization.JsonOps; import io.papermc.paper.adventure.PaperAdventure; import it.unimi.dsi.fastutil.ints.IntList; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; +import me.lojosho.hibiscuscommons.nms.v1_21_R1.NMSCommon; import me.lojosho.hibiscuscommons.util.AdventureUtils; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.kyori.adventure.text.Component; @@ -57,17 +59,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -80,7 +75,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -473,59 +469,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } } diff --git a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSCommon.java b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSCommon.java index e5c6251..6fedb0e 100644 --- a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSCommon.java +++ b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSCommon.java @@ -1,33 +1,17 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R2; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); - } } diff --git a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java index de40c33..5a0bf0b 100644 --- a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java +++ b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java @@ -1,6 +1,7 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R2; import com.google.common.collect.ImmutableList; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -9,6 +10,7 @@ import com.mojang.serialization.JsonOps; import io.papermc.paper.adventure.PaperAdventure; import it.unimi.dsi.fastutil.ints.IntList; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; +import me.lojosho.hibiscuscommons.nms.v1_21_R2.NMSCommon; import me.lojosho.hibiscuscommons.util.AdventureUtils; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.kyori.adventure.text.Component; @@ -58,17 +60,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -81,7 +76,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -471,59 +467,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } } diff --git a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSCommon.java b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSCommon.java index 6243a8a..8796861 100644 --- a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSCommon.java +++ b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSCommon.java @@ -1,33 +1,17 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R3; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); - } } diff --git a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java index f492de9..5548c47 100644 --- a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java +++ b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java @@ -60,17 +60,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -83,7 +76,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -508,60 +502,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } } diff --git a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSCommon.java b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSCommon.java index db885dd..1f2fdba 100644 --- a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSCommon.java +++ b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSCommon.java @@ -1,33 +1,17 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R4; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); - } } diff --git a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java index c1bcd86..cd4fa45 100644 --- a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java +++ b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java @@ -60,17 +60,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -83,7 +76,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -509,59 +503,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } } diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSCommon.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSCommon.java index de8bf0e..124c5a5 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSCommon.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSCommon.java @@ -1,33 +1,16 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R5; -import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; public class NMSCommon { - public void sendPacket(@NotNull Player player, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - }); - } - - public void sendPacket(@NotNull List players, @NotNull Packet packet) { - Bukkit.getAsyncScheduler().runNow(HibiscusCommonsPlugin.getInstance(), (task) -> { - for (Player p : players) { - ServerPlayer serverPlayer = ((CraftPlayer) p).getHandle(); - ServerPlayerConnection connection = serverPlayer.connection; - connection.send(packet); - } - }); + public void sendPacket(Player player, Packet packet) { + ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); + ServerPlayerConnection connection = serverPlayer.connection; + connection.send(packet); } } diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java index 8bb01ef..61be102 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java @@ -57,17 +57,10 @@ import java.util.stream.Collectors; public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets { private static ServerLevel level = MinecraftServer.getServer().overworld(); - private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects - private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") public void sendSharedEntityData(int entityId, Map dataValues, List sendTo) { - ClientboundSetEntityDataPacket packet = getSharedEntityPacket(entityId, dataValues); - for (Player player : sendTo) sendPacket(player, packet); - } - - private ClientboundSetEntityDataPacket getSharedEntityPacket(int entityId, Map dataValues) { List> nmsDataValues = dataValues.entrySet().stream().map(entry -> { int index = entry.getKey(); Number value = entry.getValue(); @@ -80,7 +73,8 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. }; }).collect(Collectors.toList()); - return new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entityId, nmsDataValues); + for (Player player : sendTo) sendPacket(player, packet); } @Override @@ -506,60 +500,4 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. fakeNmsEntity.passengers = ImmutableList.of(); return packet; } - - @Override - public void sendInvisibleParticleCloud(int entityId, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, CLOUD_EFFECT_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = net.minecraft.world.entity.EntityType.ARMOR_STAND; - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - - final Map dataValues = Map.of(0, mask, 15, (byte) 0x10); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, dataValues); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } - - @Override - public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { - net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - Vec3 velocity = Vec3.ZERO; - float headYaw = 0f; - - final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); - final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); - - ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); - sendPacket(sendTo, bundlePacket); - } }