本文整理汇总了PHP中pocketmine\Server::broadcastPacket方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::broadcastPacket方法的具体用法?PHP Server::broadcastPacket怎么用?PHP Server::broadcastPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Server
的用法示例。
在下文中一共展示了Server::broadcastPacket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attack
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC)
{
if ($this->attackTime > 0) {
$lastCause = $this->getLastDamageCause();
if ($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage) {
return;
}
}
$pk = new EntityEventPacket();
$pk->eid = $this->getID();
$pk->event = 2;
//Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->setLastDamageCause($source);
$motion = new Vector3(0, 0, 0);
if ($source instanceof EntityDamageByEntityEvent) {
$e = $source->getDamager();
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$yaw = atan2($deltaX, $deltaZ);
$motion->x = sin($yaw) * 0.5;
$motion->z = cos($yaw) * 0.5;
}
$this->setMotion($motion);
$this->setHealth($this->getHealth() - $damage);
$this->attackTime = 10;
//0.5 seconds cooldown
}
示例2: execute
public function execute(CommandSender $sender, $currentAlias, array $args)
{
if (!$this->testPermission($sender)) {
return true;
}
if (count($args) !== 1) {
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false;
}
$difficulty = Server::getDifficultyFromString($args[0]);
if ($sender->getServer()->isHardcore()) {
$difficulty = 3;
}
if ($difficulty !== -1) {
$sender->getServer()->setConfigInt("difficulty", $difficulty);
$pk = new SetDifficultyPacket();
$pk->difficulty = $sender->getServer()->getDifficulty();
Server::broadcastPacket($sender->getServer()->getOnlinePlayers(), $pk);
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
} else {
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false;
}
return true;
}
示例3: explode
public function explode(Position $pos)
{
$aabb = new AxisAlignedBB($pos->getX() - self::RANGE, $pos->getY() - self::RANGE, $pos->getZ() - self::RANGE, $pos->getX() + self::RANGE, $pos->getY() + self::RANGE, $pos->getZ() + self::RANGE);
$nearbyEntities = $this->getPlayer()->getLevel()->getNearbyEntities($aabb, null);
$pk = new ExplodePacket();
$pk->x = $pos->x;
$pk->y = $pos->y;
$pk->z = $pos->z;
$pk->radius = 10;
$pk->records = [new Vector3($pos->x, $pos->y, $pos->z)];
Server::broadcastPacket($this->getPlayer()->getLevel()->getChunkPlayers($pos->x >> 4, $pos->z >> 4), $pk->setChannel(Network::CHANNEL_BLOCKS));
foreach ($nearbyEntities as $entity) {
if (!$entity instanceof Player) {
continue;
}
if ($this->getPlugin()->isEnemy($this->getPlayer()->getName(), $entity->getName())) {
//cause : 15, damage : 15, knockback : 5
$event = new EntityDamageByEntityEvent($this->getPlayer(), $entity, 15, 15, 5);
$entity->attack($event->getFinalDamage(), $event);
}
}
for ($i = 0; $i < 100; $i++) {
$this->getPlayer()->getLevel()->addParticle(new SmokeParticle(new Vector3($pos->x + mt_rand(-self::RANGE, self::RANGE), $pos->y + mt_rand(-self::RANGE, self::RANGE), $pos->z + mt_rand(-self::RANGE, self::RANGE))));
}
}
示例4: onCancel
public function onCancel()
{
$flags = (int) $this->target->getDataProperty(Player::DATA_FLAGS);
$dataProperty = [Player::DATA_FLAGS => [Player::DATA_TYPE_BYTE, $flags]];
$pk = new SetEntityDataPacket();
$pk->eid = $this->target->getId();
$pk->metadata = $dataProperty;
Server::broadcastPacket($this->target->getLevel()->getPlayers(), $pk);
}
示例5: setFlaming
public function setFlaming(Player $target)
{
$flags = (int) $target->getDataProperty(Player::DATA_FLAGS);
$flags ^= 1 << Player::DATA_FLAG_ONFIRE;
$dataProperty = [Player::DATA_FLAGS => [Player::DATA_TYPE_BYTE, $flags]];
$pk = new SetEntityDataPacket();
$pk->eid = $target->getId();
$pk->metadata = $dataProperty;
Server::broadcastPacket($this->getPlayer()->getLevel()->getPlayers(), $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
示例6: onCancel
public function onCancel()
{
$flags = (int) $this->target->getDataProperty(Player::DATA_FLAGS);
$dataProperty = [Player::DATA_FLAGS => [Player::DATA_TYPE_BYTE, $flags]];
$pk = new SetEntityDataPacket();
$pk->eid = $this->target->getId();
$pk->metadata = $dataProperty;
Server::broadcastPacket($this->target->getLevel()->getPlayers(), $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
unset(FlameThrower::$tasks[$this->target->getName()]);
}
示例7: doorSound
public function doorSound(Vector3 $pos)
{
$pk = new LevelEventPacket();
$pk->x = $pos->x;
$pk->y = $pos->y;
$pk->z = $pos->z;
$pk->evid = 1003;
$pk->data = 0;
Server::broadcastPacket($this->getServer()->getOnlinePlayers(), $pk);
}
示例8: onShoot
public function onShoot()
{
$this->lastShoot = microtime(true);
$pk = new ExplodePacket();
$pk->x = $this->player->getX();
$pk->y = $this->player->getY();
$pk->z = $this->player->getZ();
$pk->radius = 10;
$pk->records = [new Vector3($this->player->getX(), $this->player->getY() + 1.62, $this->player->getZ())];
Server::broadcastPacket($this->getPlayer()->getLevel()->getChunkPlayers($this->player->getX() >> 4, $this->player->getZ() >> 4), $pk->setChannel(Network::CHANNEL_BLOCKS));
}
示例9: setHeldItemIndex
public function setHeldItemIndex($index)
{
if ($index >= 0 and $index < $this->getHotbarSize()) {
$this->itemInHandIndex = $index;
$item = $this->getItemInHand();
$pk = new PlayerEquipmentPacket();
$pk->eid = $this->getHolder()->getId();
$pk->item = $item->getId();
$pk->meta = $item->getDamage();
$pk->slot = $this->getHeldItemIndex();
Server::broadcastPacket($this->getHolder()->getViewers(), $pk);
}
}
示例10: onClose
public function onClose(Player $who)
{
if (count($this->getViewers()) === 1) {
$pk = new TileEventPacket();
$pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ();
$pk->case1 = 1;
$pk->case2 = 0;
Server::broadcastPacket($this->getHolder()->getLevel()->getPlayers(), $pk);
}
parent::onClose($who);
}
示例11: onClose
public function onClose(Player $who)
{
if (count($this->getViewers()) === 1) {
$pk = new TileEventPacket();
$pk->x = $this->main->getFakeTile()->x;
$pk->y = $this->main->getFakeTile()->y;
$pk->z = $this->main->getFakeTile()->z;
$pk->case1 = 1;
$pk->case2 = 0;
if (($level = $this->main->getFakeTile()->getLevel()) instanceof Level) {
Server::broadcastPacket($level->getChunkPlayers($this->main->getFakeTile()->x >> 4, $this->main->getFakeTile()->z >> 4), $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
}
parent::onClose($who);
}
示例12: Light
public function Light($x, $y, $z)
{
//雷
$pk = new AddEntityPacket();
$pk->type = 93;
$pk->eid = Entity::$entityCount++;
$pk->metadata = array();
$pk->x = $x;
$pk->y = $y;
$pk->z = $z;
$pk->speedX = 0;
$pk->speedY = 0;
$pk->speedZ = 0;
Server::broadcastPacket(Server::getInstance()->getOnlinePlayers(), $pk);
}
示例13: onClose
public function onClose(Player $who)
{
if (count($this->getViewers()) === 1) {
$pk = new TileEventPacket();
$pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ();
$pk->case1 = 1;
$pk->case2 = 0;
if (($level = $this->getHolder()->getLevel()) instanceof Level) {
Server::broadcastPacket($level->getUsingChunk($this->getHolder()->getX() >> 4, $this->getHolder()->getZ() >> 4), $pk);
}
}
parent::onClose($who);
}
示例14: attack
public function attack($damage, EntityDamageEvent $source)
{
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
}
if ($source instanceof EntityDamageByEntityEvent) {
$this->swimSpeed = mt_rand(150, 350) / 2000;
$e = $source->getDamager();
$this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize();
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::SQUID_INK_CLOUD;
Server::broadcastPacket($this->hasSpawned, $pk);
}
}
示例15: attack
public function attack($damage, EntityDamageEvent $source)
{
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
}
if ($source instanceof EntityDamageByEntityEvent) {
$this->swimSpeed = \mt_rand(150, 350) / 2000;
$e = $source->getDamager();
$this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize();
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = 15;
Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
}