cn.nukkit.network.protocol.types.ContainerIds Java Examples

The following examples show how to use cn.nukkit.network.protocol.types.ContainerIds. 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: PlayerCursorInventory.java    From Jupiter 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 #2
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 #3
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 #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: CraftingTransaction.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected void sendInventories() {
      super.sendInventories();

/*
       * TODO: HACK!
 * we can't resend the contents of the crafting window, so we force the client to close it instead.
 * So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting
 * transaction goes wrong.
 */
      ContainerClosePacket pk = new ContainerClosePacket();
      pk.windowId = ContainerIds.NONE;
      source.getServer().getScheduler().scheduleDelayedTask(new Task() {
          @Override
          public void onRun(int currentTick) {
              source.dataPacket(pk);
          }
      }, 20);

      this.source.resetCraftingGridType();
  }
 
Example #6
Source File: PlayerUIInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
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.UI;
            p.dataPacket(pk);
        } else {
            int id;

            if ((id = p.getWindowId(this)) == ContainerIds.NONE) {
                this.close(p);
                continue;
            }
            pk.inventoryId = id;
            p.dataPacket(pk);
        }
    }
}
 
Example #7
Source File: PlayerUIInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player... target) {
    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 p : target) {
        if (p == this.getHolder()) {
            pk.inventoryId = ContainerIds.UI;
            p.dataPacket(pk);
        } else {
            int id;

            if ((id = p.getWindowId(this)) == ContainerIds.NONE) {
                this.close(p);
                continue;
            }
            pk.inventoryId = id;
            p.dataPacket(pk);
        }
    }
}
 
Example #8
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 #9
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 #10
Source File: PlayerOffhandInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendContents(Player... players) {
    Item item = this.getItem(0);
    MobEquipmentPacket pk = this.createMobEquipmentPacket(item);

    for (Player player : players) {
        if (player == this.getHolder()) {
            InventoryContentPacket pk2 = new InventoryContentPacket();
            pk2.inventoryId = ContainerIds.OFFHAND;
            pk2.slots = new Item[]{item};
            player.dataPacket(pk2);
        } else {
            player.dataPacket(pk);
        }
    }
}
 
Example #11
Source File: PlayerOffhandInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSlot(int index, Player... players) {
    Item item = this.getItem(0);
    MobEquipmentPacket pk = this.createMobEquipmentPacket(item);

    for (Player player : players) {
        if (player == this.getHolder()) {
            InventorySlotPacket pk2 = new InventorySlotPacket();
            pk2.inventoryId = ContainerIds.OFFHAND;
            pk2.item = item;
            player.dataPacket(pk2);
        } else {
            player.dataPacket(pk);
        }
    }
}
 
Example #12
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendCreativeContents() {
    if (!(this.getHolder() instanceof Player)) {
        return;
    }
    Player p = (Player) this.getHolder();

    InventoryContentPacket pk = new InventoryContentPacket();
    pk.inventoryId = ContainerIds.CREATIVE;

    if (!p.isSpectator()) { //fill it for all gamemodes except spectator
        pk.slots = Item.getCreativeItems().toArray(new Item[0]);
    }

    p.dataPacket(pk);
}
 
Example #13
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendCreativeContents() {
    if (!(this.getHolder() instanceof Player)) {
        return;
    }
    Player p = (Player) this.getHolder();

    InventoryContentPacket pk = new InventoryContentPacket();
    pk.inventoryId = ContainerIds.CREATIVE;

    if (!p.isSpectator()) { //fill it for all gamemodes except spectator
        pk.slots = Item.getCreativeItems().stream().toArray(Item[]::new);
    }

    p.dataPacket(pk);
}
 
Example #14
Source File: CraftingTransaction.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void sendInventories() {
      super.sendInventories();

/*
       * TODO: HACK!
 * we can't resend the contents of the crafting window, so we force the client to close it instead.
 * So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting
 * transaction goes wrong.
 */
      ContainerClosePacket pk = new ContainerClosePacket();
      pk.windowId = ContainerIds.NONE;
      this.source.dataPacket(pk);

      this.source.resetCraftingGridType();
  }
 
Example #15
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void addDefaultWindows() {
    this.addWindow(this.getInventory(), ContainerIds.INVENTORY, true);

    this.playerUIInventory = new PlayerUIInventory(this);
    this.addWindow(this.playerUIInventory, ContainerIds.UI, true);
    this.addWindow(this.offhandInventory, ContainerIds.OFFHAND, true);

    this.craftingGrid = this.playerUIInventory.getCraftingGrid();
    this.addWindow(this.craftingGrid, ContainerIds.NONE);

    //TODO: more windows
}
 
Example #16
Source File: PlayerOffhandInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private MobEquipmentPacket createMobEquipmentPacket(Item item) {
    MobEquipmentPacket pk = new MobEquipmentPacket();
    pk.eid = this.getHolder().getId();
    pk.item = item;
    pk.inventorySlot = 1;
    pk.windowId = ContainerIds.OFFHAND;
    pk.encode();
    pk.isEncoded = true;
    return pk;
}
 
Example #17
Source File: PlayerOffhandInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void sendOffhandItem(Player[] players) {
Item item = this.getItem(0);

MobEquipmentPacket pk = new MobEquipmentPacket();
pk.item = item;
pk.inventorySlot = pk.hotbarSlot = 0;
pk.windowId = ContainerIds.OFFHAND;

for (Player player : players) {
	pk.entityRuntimeId = this.getHolder().getId();
	player.dataPacket(pk);
}
  }
 
Example #18
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void sendCreativeContents() {
    if (!(this.getHolder() instanceof Player)) {
        return;
    }
    Player p = (Player) this.getHolder();

    InventoryContentPacket pk = new InventoryContentPacket();
    pk.inventoryId = ContainerIds.CREATIVE;

    if (!p.isSpectator()) { //fill it for all gamemodes except spectator
        pk.slots = Item.getCreativeItems().stream().toArray(Item[]::new);
    }

    p.dataPacket(pk);
}
 
Example #19
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setCraftingGrid(CraftingGrid grid) {
    this.craftingGrid = grid;
    this.addWindow(grid, ContainerIds.NONE);
}
 
Example #20
Source File: CraftingTransaction.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void sendInventories() {
	ContainerClosePacket pk = new ContainerClosePacket();
	pk.windowId = ContainerIds.NONE;
	this.source.dataPacket(pk);
}
 
Example #21
Source File: Player.java    From Nukkit with GNU General Public License v3.0 3 votes vote down vote up
protected void addDefaultWindows() {
    this.addWindow(this.getInventory(), ContainerIds.INVENTORY, true);

    this.cursorInventory = new PlayerCursorInventory(this);
    this.addWindow(this.cursorInventory, ContainerIds.CURSOR, true);

    this.craftingGrid = new CraftingGrid(this);

    //TODO: more windows
}