Send trade packet for every new viewer

This commit is contained in:
TheMode 2021-05-30 16:39:09 +02:00
parent c080750a88
commit 52d0ef7f53

View File

@ -1,9 +1,11 @@
package net.minestom.server.inventory.type;
import net.minestom.server.entity.Player;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
import net.minestom.server.network.packet.server.play.TradeListPacket;
import net.minestom.server.utils.ArrayUtils;
import org.jetbrains.annotations.NotNull;
public class VillagerInventory extends Inventory {
@ -79,6 +81,15 @@ public class VillagerInventory extends Inventory {
sendPacketToViewers(tradeListPacket); // Refresh window
}
@Override
public boolean addViewer(@NotNull Player player) {
final boolean result = super.addViewer(player);
if (result) {
player.getPlayerConnection().sendPacket(tradeListPacket);
}
return result;
}
private void setupPacket() {
this.tradeListPacket = new TradeListPacket();
this.tradeListPacket.windowId = getWindowId();