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

The following examples show how to use cn.nukkit.Player#dataPacket() . 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: EntitySquid.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 2
Source File: EntityBoat.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.type = EntityBoat.NETWORK_ID;
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = 0;
    pk.speedY = 0;
    pk.speedZ = 0;
    pk.yaw = (float) this.yaw;
    pk.pitch = (float) this.pitch;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 3
Source File: EntityStray.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    MobEquipmentPacket pk1 = new MobEquipmentPacket();
    pk1.eid = this.getId();
    pk1.item = new ItemBow();
    pk1.hotbarSlot = 10;
    player.dataPacket(pk1);

    super.spawnTo(player);
}
 
Example 4
Source File: EntityPotion.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = EntityPotion.NETWORK_ID;
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 5
Source File: EntityEgg.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = EntityEgg.NETWORK_ID;
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 6
Source File: EntityRabbit.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 7
Source File: EntityStray.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 8
Source File: EntityPolarBear.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
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: EntityArmorStand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
	AddEntityPacket pk = new AddEntityPacket();
	pk.entityRuntimeId = this.getId();
	pk.entityUniqueId = this.getId();
	pk.type = this.getNetworkId();
	pk.x = (float) this.x;
	pk.y = (float) this.y;
	pk.z = (float) this.z;
	pk.speedX = (float) this.motionX;
	pk.speedY = (float) this.motionY;
	pk.speedZ = (float) this.motionZ;
	pk.yaw = (float) this.yaw;
	pk.pitch = (float) this.pitch;
	player.dataPacket(pk);

	sendArmor(player);
	sendHand(player);

	super.spawnTo(player);
}
 
Example 11
Source File: EntitySheep.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 12
Source File: EntityPotion.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = EntityPotion.NETWORK_ID;
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 13
Source File: EntityVex.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 14
Source File: EntityCow.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 15
Source File: EntityZombiePigman.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket pk = new AddEntityPacket();
    pk.type = this.getNetworkId();
    pk.entityUniqueId = this.getId();
    pk.entityRuntimeId = this.getId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = (float) this.motionX;
    pk.speedY = (float) this.motionY;
    pk.speedZ = (float) this.motionZ;
    pk.metadata = this.dataProperties;
    player.dataPacket(pk);

    super.spawnTo(player);
}
 
Example 16
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 17
Source File: EntityHuman.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void despawnFrom(Player player) {
    if (this.hasSpawned.containsKey(player.getLoaderId())) {

        RemoveEntityPacket pk = new RemoveEntityPacket();
        pk.eid = this.getId();
        player.dataPacket(pk);
        this.hasSpawned.remove(player.getLoaderId());
    }
}
 
Example 18
Source File: EntityPrimedTNT.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void spawnTo(Player player) {
    AddEntityPacket packet = new AddEntityPacket();
    packet.type = EntityPrimedTNT.NETWORK_ID;
    packet.entityUniqueId = this.getId();
    packet.entityRuntimeId = getId();
    packet.x = (float) x;
    packet.y = (float) y;
    packet.z = (float) z;
    packet.speedX = (float) motionX;
    packet.speedY = (float) motionY;
    packet.speedZ = (float) motionZ;
    packet.metadata = dataProperties;
    player.dataPacket(packet);
    super.spawnTo(player);
}
 
Example 19
Source File: EntityArmorStand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void sendHand(Player player) {
	MobEquipmentPacket pk = new MobEquipmentPacket();
	pk.entityRuntimeId = this.getId();
	pk.inventorySlot = 0;
	pk.hotbarSlot = 0;
	pk.item = this.getHand();
	player.dataPacket(pk);
}
 
Example 20
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendData(Player[] players, EntityMetadata data) {
    SetEntityDataPacket pk = new SetEntityDataPacket();
    pk.eid = this.getId();
    pk.metadata = data == null ? this.dataProperties : data;

    for (Player player : players) {
        if (player == this) {
            continue;
        }
        player.dataPacket(pk.clone());
    }
    if (this instanceof Player) {
        ((Player) this).dataPacket(pk);
    }
}