From 794683ef751e93d121f9153f1c209d7ac9236928 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 13 Jun 2024 23:22:18 +0200 Subject: [PATCH] Don't use ItemStack.empty() This is a fairly new method --- .../listeners/v1_20_5to1_21/PlayerChangeItemListener.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/v1_20_5to1_21/PlayerChangeItemListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/v1_20_5to1_21/PlayerChangeItemListener.java index d2b52a8b2..deb56697f 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/v1_20_5to1_21/PlayerChangeItemListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/v1_20_5to1_21/PlayerChangeItemListener.java @@ -33,6 +33,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.ItemStack; +import org.checkerframework.checker.nullness.qual.Nullable; /** * For some reason, mining efficiency is not calculated by the client anymore, but by the server, @@ -60,16 +61,16 @@ public final class PlayerChangeItemListener extends ViaBukkitListener { public void onPlayerItemHeld(final PlayerItemHeldEvent event) { final Player player = event.getPlayer(); final ItemStack item = player.getInventory().getItem(event.getNewSlot()); - sendAttributeUpdate(player, item != null ? item : ItemStack.empty()); + sendAttributeUpdate(player, item); } - private void sendAttributeUpdate(final Player player, final ItemStack item) { + private void sendAttributeUpdate(final Player player, @Nullable final ItemStack item) { final UserConnection connection = Via.getAPI().getConnection(player.getUniqueId()); if (connection == null || !isOnPipe(player)) { return; } - final int efficiencyLevel = item.getEnchantmentLevel(efficiency); + final int efficiencyLevel = item != null ? item.getEnchantmentLevel(efficiency) : 0; final PacketWrapper attributesPacket = PacketWrapper.create(ClientboundPackets1_21.UPDATE_ATTRIBUTES, connection); attributesPacket.write(Types.VAR_INT, player.getEntityId());