3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Don't use ItemStack.empty()

This is a fairly new method
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-06-13 23:22:18 +02:00
Ursprung cc6f789334
Commit 794683ef75
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F

Datei anzeigen

@ -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());