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