Java Code Examples for cn.nukkit.Player#getWindowId()

The following examples show how to use cn.nukkit.Player#getWindowId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);
    ContainerOpenPacket pk = new ContainerOpenPacket();
    pk.windowId = who.getWindowId(this);
    pk.type = this.getType().getNetworkType();
    InventoryHolder holder = this.getHolder();
    if (holder instanceof Vector3) {
        pk.x = (int) ((Vector3) holder).getX();
        pk.y = (int) ((Vector3) holder).getY();
        pk.z = (int) ((Vector3) holder).getZ();
    } else {
        pk.x = pk.y = pk.z = 0;
    }

    who.dataPacket(pk);

    this.sendContents(who);
}
 
Example 2
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player... players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk);
    }
}
 
Example 3
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player[] players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    /*//Because PE is stupid and shows 9 less slots than you send it, give it 9 dummy slots so it shows all the REAL slots.
    for(int i = this.getSize(); i < this.getSize() + this.getHotbarSize(); ++i){
        pk.slots[i] = new ItemBlock(Block.get(BlockID.AIR));
    }
        pk.slots[i] = new ItemBlock(Block.get(BlockID.AIR));
    }*/

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            if (this.getHolder() != player) this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk.clone());

    }
}
 
Example 4
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSlot(int index, Player... players) {
    InventorySlotPacket pk = new InventorySlotPacket();
    pk.slot = index;
    pk.item = this.getItem(index).clone();

    for (Player player : players) {
        if (player.equals(this.getHolder())) {
            pk.inventoryId = ContainerIds.INVENTORY;
            player.dataPacket(pk);
        } else {
            int id = player.getWindowId(this);
            if (id == -1) {
                this.close(player);
                continue;
            }
            pk.inventoryId = id;
            player.dataPacket(pk.clone());
        }
    }
}
 
Example 5
Source File: PlayerCursorInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void sendSlot(int index, Player... target) {
    InventorySlotPacket pk = new InventorySlotPacket();
    pk.slot = index;
    pk.item = this.getItem(index);

    for (Player p : target) {
        if (p == this.getHolder()) {
            pk.inventoryId = ContainerIds.CURSOR;
            p.dataPacket(pk);
        } else {
            int id;

            if ((id = p.getWindowId(this)) == ContainerIds.NONE) {
                this.close(p);
                continue;
            }
            pk.inventoryId = id;
            p.dataPacket(pk);
        }
    }
}
 
Example 6
Source File: TradingInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    CompoundTag nbt = this.getHolder().getOffers();
    if (nbt != null) {
        super.onOpen(who);

        UpdateTradePacket pk1 = new UpdateTradePacket();
        pk1.windowId = (byte) who.getWindowId(this);
        pk1.windowType = 15;
        pk1.unknownVarInt1 = 0;
        pk1.unknownVarInt2 = 0;
        pk1.isWilling = false;
        pk1.trader = this.getHolder().getId();
        pk1.player = who.getId();
        pk1.displayName = this.getHolder().getName();
        try {
            pk1.offers = NBTIO.write(nbt, ByteOrder.LITTLE_ENDIAN, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        who.dataPacket(pk1);
    } else {
        super.onClose(who);
    }
}
 
Example 7
Source File: PlayerOffhandInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSlot(int index, Player... players) {
	InventorySlotPacket pk = new InventorySlotPacket();
	pk.slot = index;
	pk.item = this.getItem(index).clone();

	for (Player player : players) {
		if (player.equals(this.getHolder())) {
			pk.inventoryId = ContainerIds.OFFHAND;
			player.dataPacket(pk);
		} else {
			int id = player.getWindowId(this);
			if (id == -1) {
				this.close(player);
				continue;
			}
			pk.inventoryId = id;
			player.dataPacket(pk.clone());
		}
	}
}
 
Example 8
Source File: ContainerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);
    ContainerOpenPacket pk = new ContainerOpenPacket();
    pk.windowId = who.getWindowId(this);
    pk.type = this.getType().getNetworkType();
    InventoryHolder holder = this.getHolder();
    if (holder instanceof Vector3) {
        pk.x = (int) ((Vector3) holder).getX();
        pk.y = (int) ((Vector3) holder).getY();
        pk.z = (int) ((Vector3) holder).getZ();
    } else {
        pk.x = pk.y = pk.z = 0;
    }
    if (holder instanceof Entity) {
        pk.entityId = ((Entity) holder).getId();
    }

    who.dataPacket(pk);

    this.sendContents(who);
}
 
Example 9
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSlot(int index, Player... players) {
    InventorySlotPacket pk = new InventorySlotPacket();
    pk.slot = index;
    pk.item = this.getItem(index).clone();

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk);
    }
}
 
Example 10
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player... players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk);
    }
}
 
Example 11
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSlot(int index, Player... players) {
    InventorySlotPacket pk = new InventorySlotPacket();
    pk.slot = index;
    pk.item = this.getItem(index).clone();

    for (Player player : players) {
        if (player.equals(this.getHolder())) {
            pk.inventoryId = ContainerIds.INVENTORY;
            player.dataPacket(pk);
        } else {
            int id = player.getWindowId(this);
            if (id == -1) {
                this.close(player);
                continue;
            }
            pk.inventoryId = id;
            player.dataPacket(pk.clone());
        }
    }
}
 
Example 12
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player[] players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    /*//Because PE is stupid and shows 9 less slots than you send it, give it 9 dummy slots so it shows all the REAL slots.
    for(int i = this.getSize(); i < this.getSize() + this.getHotbarSize(); ++i){
        pk.slots[i] = new ItemBlock(new BlockAir());
    }
        pk.slots[i] = new ItemBlock(new BlockAir());
    }*/

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk.clone());

    }
}
 
Example 13
Source File: FakeBlockUIComponent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket pk = new ContainerClosePacket();
    pk.windowId = who.getWindowId(this);
    who.dataPacket(pk);
    super.onClose(who);
}
 
Example 14
Source File: BlockEntityBrewingStand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void sendBrewTime() {
    ContainerSetDataPacket pk = new ContainerSetDataPacket();
    pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_BREW_TIME;
    pk.value = this.brewTime;

    for (Player p : this.inventory.getViewers()) {
        int windowId = p.getWindowId(this.inventory);
        if (windowId > 0) {
            pk.windowId = windowId;

            p.dataPacket(pk);
        }
    }
}
 
Example 15
Source File: ContainerInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket pk = new ContainerClosePacket();
    pk.windowId = who.getWindowId(this);
    who.dataPacket(pk);
    super.onClose(who);
}
 
Example 16
Source File: BlockEntityBrewingStand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
protected void sendBrewTime() {
    ContainerSetDataPacket pk = new ContainerSetDataPacket();
    pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_BREW_TIME;
    pk.value = this.brewTime;

    for (Player p : this.inventory.getViewers()) {
        int windowId = p.getWindowId(this.inventory);
        if (windowId > 0) {
            pk.windowId = windowId;

            p.dataPacket(pk);
        }
    }
}
 
Example 17
Source File: ContainerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket pk = new ContainerClosePacket();
    pk.windowId = who.getWindowId(this);
    who.dataPacket(pk);
    super.onClose(who);
}
 
Example 18
Source File: DoubleChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendSlot(Inventory inv, int index, Player... players) {
    InventorySlotPacket pk = new InventorySlotPacket();
    pk.slot = inv == this.right ? this.left.getSize() + index : index;
    pk.item = inv.getItem(index).clone();

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk);
    }
}
 
Example 19
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket containerClosePacket = new ContainerClosePacket();
    containerClosePacket.windowId = who.getWindowId(this);
    who.dataPacket(containerClosePacket);
    super.onClose(who);

    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addSound(this.getHolder().add(0.5, 0.5, 0.5), Sound.RANDOM_CHESTCLOSED);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }

        who.setViewingEnderChest(null);
    }

    super.onClose(who);
}
 
Example 20
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onOpen(Player who) {
    if (who != this.getHolder()) {
        return;
    }
    super.onOpen(who);
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.windowId = who.getWindowId(this);
    containerOpenPacket.type = this.getType().getNetworkType();
    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null) {
        containerOpenPacket.x = (int) chest.getX();
        containerOpenPacket.y = (int) chest.getY();
        containerOpenPacket.z = (int) chest.getZ();
    } else {
        containerOpenPacket.x = containerOpenPacket.y = containerOpenPacket.z = 0;
    }

    who.dataPacket(containerOpenPacket);

    this.sendContents(who);

    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addSound(this.getHolder().add(0.5, 0.5, 0.5), Sound.RANDOM_CHESTOPEN);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }
    }
}