use isViewer and sendPacket shortcut

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-28 21:44:19 +02:00
parent 72461ade73
commit 107388a37b

View File

@ -12,7 +12,6 @@ import net.minestom.server.network.packet.server.play.OpenWindowPacket;
import net.minestom.server.network.packet.server.play.SetSlotPacket; import net.minestom.server.network.packet.server.play.SetSlotPacket;
import net.minestom.server.network.packet.server.play.WindowItemsPacket; import net.minestom.server.network.packet.server.play.WindowItemsPacket;
import net.minestom.server.network.packet.server.play.WindowPropertyPacket; import net.minestom.server.network.packet.server.play.WindowPropertyPacket;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.inventory.PlayerInventoryUtils; import net.minestom.server.utils.inventory.PlayerInventoryUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -130,8 +129,8 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable
*/ */
@Override @Override
public void update() { public void update() {
for(Player player : viewers) { for (Player player : viewers) {
player.getPlayerConnection().sendPacket(createNewWindowItemsPacket(player)); player.sendPacket(createNewWindowItemsPacket(player));
} }
} }
@ -143,11 +142,8 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable
* @param player the player to update the inventory * @param player the player to update the inventory
*/ */
public void update(@NotNull Player player) { public void update(@NotNull Player player) {
if (!getViewers().contains(player)) if (!isViewer(player)) return;
return; player.sendPacket(createNewWindowItemsPacket(player));
final PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(createNewWindowItemsPacket(player));
} }
@NotNull @NotNull
@ -204,7 +200,7 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable
public void setCursorItem(@NotNull Player player, @NotNull ItemStack cursorItem) { public void setCursorItem(@NotNull Player player, @NotNull ItemStack cursorItem) {
final ItemStack currentCursorItem = cursorPlayersItem.getOrDefault(player, ItemStack.AIR); final ItemStack currentCursorItem = cursorPlayersItem.getOrDefault(player, ItemStack.AIR);
if (!currentCursorItem.isSimilar(cursorItem)) { if (!currentCursorItem.isSimilar(cursorItem)) {
player.getPlayerConnection().sendPacket(SetSlotPacket.createCursorPacket(cursorItem)); player.sendPacket(SetSlotPacket.createCursorPacket(cursorItem));
} }
if (!cursorItem.isAir()) { if (!cursorItem.isAir()) {
this.cursorPlayersItem.put(player, cursorItem); this.cursorPlayersItem.put(player, cursorItem);