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

The following examples show how to use cn.nukkit.Player#getId() . 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: 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 2
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void sendHeldItem(Player... players) {
    Item item = this.getItemInHand();

    MobEquipmentPacket pk = new MobEquipmentPacket();
    pk.item = item;
    pk.inventorySlot = pk.hotbarSlot = this.getHeldItemIndex();

    for (Player player : players) {
        pk.entityRuntimeId = this.getHolder().getId();
        if (player.equals(this.getHolder())) {
            pk.entityRuntimeId = player.getId();
            this.sendSlot(this.getHeldItemIndex(), player);
        }

        player.dataPacket(pk);
    }
}
 
Example 3
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void sendHeldItem(Player... players) {
    Item item = this.getItemInHand();

    MobEquipmentPacket pk = new MobEquipmentPacket();
    pk.item = item;
    pk.inventorySlot = pk.hotbarSlot = this.getHeldItemIndex();

    for (Player player : players) {
        pk.eid = this.getHolder().getId();
        if (player.equals(this.getHolder())) {
            pk.eid = player.getId();
            this.sendSlot(this.getHeldItemIndex(), player);
        }

        player.dataPacket(pk);
    }
}
 
Example 4
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void sendHeldItem(Player... players) {
    Item item = this.getItemInHand();

    MobEquipmentPacket pk = new MobEquipmentPacket();
    pk.item = item;
    pk.inventorySlot = pk.hotbarSlot = this.getHeldItemIndex();

    for (Player player : players) {
        pk.eid = this.getHolder().getId();
        if (player.equals(this.getHolder())) {
            pk.eid = player.getId();
            this.sendSlot(this.getHeldItemIndex(), player);
        }

        player.dataPacket(pk);
    }
}
 
Example 5
Source File: EntityItem.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCollideWithPlayer(Player player) {
    if(this.getPickupDelay() > 0) {
        return;
    }

    Item item = this.getItem();
    PlayerInventory playerInventory = player.getInventory();

    if(!(item instanceof Item) || (player.isSurvival() && !playerInventory.canAddItem(item))) {
        return;
    }

    InventoryPickupItemEvent ev;
    this.server.getPluginManager().callEvent(ev = new InventoryPickupItemEvent(playerInventory, this));
    if(ev.isCancelled()) {
        return;
    }

    TakeItemEntityPacket pk = new TakeItemEntityPacket();
    pk.entityRuntimeId = player.getId();
    pk.target = this.getId();
    Server.broadcastPacket(this.getViewers().values(), pk);

    playerInventory.addItem(item);
    this.kill();
}
 
Example 6
Source File: EntityArrow.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCollideWithPlayer(Player player) {
    if(!this.hadCollision) {
        return;
    }

    Item item = new Item(Item.ARROW, 0, 1);
    PlayerInventory playerInventory = player.getInventory();

    if(player.isSurvival() && playerInventory.canAddItem(item)) {
        return;
    }

    InventoryPickupArrowEvent ev;
    this.server.getPluginManager().callEvent(ev = new InventoryPickupArrowEvent(playerInventory, this));
    if(ev.isCancelled()) {
        return;
    }

    TakeItemEntityPacket pk = new TakeItemEntityPacket();
    pk.entityRuntimeId = player.getId();
    pk.target = this.getId();
    Server.broadcastPacket(this.getViewers().values(), pk);

    playerInventory.addItem(item);
    this.kill();
}