本文整理汇总了PHP中pocketmine\event\server\DataPacketReceiveEvent类的典型用法代码示例。如果您正苦于以下问题:PHP DataPacketReceiveEvent类的具体用法?PHP DataPacketReceiveEvent怎么用?PHP DataPacketReceiveEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataPacketReceiveEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onReceivePacket
public function onReceivePacket(DataPacketReceiveEvent $event)
{
$player = $event->getPlayer();
$packet = $event->getPacket();
if ($packet->pid() == Info::LOGIN_PACKET) {
if ($packet->protocol1 < Info::CURRENT_PROTOCOL) {
//Check if outdated client message is custom
if (CustomAlerts::getAPI()->isOutdatedClientMessageCustom()) {
CustomAlerts::getAPI()->setOutdatedClientMessage(CustomAlerts::getAPI()->getDefaultOutdatedClientMessage($player));
}
//Outdated Client Kick Event
$this->plugin->getServer()->getPluginManager()->callEvent(new CustomAlertsOutdatedClientKickEvent($player));
//Check if Outdated Client message is not empty
if (CustomAlerts::getAPI()->getOutdatedClientMessage() != null) {
$player->close("", CustomAlerts::getAPI()->getOutdatedClientMessage());
$event->setCancelled(true);
}
} elseif ($packet->protocol1 > Info::CURRENT_PROTOCOL) {
//Check if outdated server message is custom
if (CustomAlerts::getAPI()->isOutdatedServerMessageCustom()) {
CustomAlerts::getAPI()->setOutdatedServerMessage(CustomAlerts::getAPI()->getDefaultOutdatedServerMessage($player));
}
//Outdated Server Kick Event
$this->plugin->getServer()->getPluginManager()->callEvent(new CustomAlertsOutdatedServerKickEvent($player));
//Check if Outdated Server message is not empty
if (CustomAlerts::getAPI()->getOutdatedServerMessage() != null) {
$player->close("", CustomAlerts::getAPI()->getOutdatedServerMessage());
$event->setCancelled(true);
}
}
}
}
示例2: onPotionUse
public function onPotionUse(DataPacketReceiveEvent $ev)
{
//TODO : Give a potion effect to player when he eats potion
$packet = $ev->getPacket();
if ($packet instanceof EntityEventPacket) {
}
}
示例3: onPkt
public function onPkt(DataPacketReceiveEvent $e)
{
if ($e->getPacket()->pid() !== 0x0) {
return;
}
$this->lastPing[strtolower($e->getPlayer()->getName())] = Binary::readLong($e->getPacket()->buffer) / 1000.0;
}
示例4: onDataPacketReceiveEvent
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof InteractPacket) {
if ($boat instanceof Boat) {
if ($packet->action === 1) {
$this->riding[$player->getName()] = $packet->target;
} elseif ($packet->action === 3) {
if (isset($this->riding[$player->getName()])) {
unset($this->riding[$player->getName()]);
$this->removeWaterField($player);
}
}
}
} elseif ($packet instanceof MovePlayerPacket) {
if (isset($this->riding[$player->getName()])) {
$boat = $player->getLevel()->getEntity($this->riding[$player->getName()]);
if ($boat instanceof Boat) {
$x = (int) floor($boat->x);
$y = (int) floor($boat->y) - 1;
$z = (int) floor($boat->z);
if (isset($this->waterField[$player->getName()]["pos"]) and $this->waterField[$player->getName()]["pos"] == "{$x}:{$y}:{$z}") {
return;
}
$this->setWaterField($player, $x, $y, $z, $player->getLevel());
}
}
}
//
}
示例5: onDataPacketReceive
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk instanceof LoginPacket) {
$pk->username = str_replace([" ", "!", "?", "-", ",", "."], "_", $pk->username);
}
}
示例6: onReceivePacket
/**
* @param DataPacketReceiveEvent $event
* @priority LOW
*/
public function onReceivePacket(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() === ProtocolInfo::LOGIN_PACKET) {
/** @var \pocketmine\network\protocol\LoginPacket $pk */
$pk->username = $this->correctName($pk->username);
// var_dump($pk->username);
}
}
示例7: onReceive
public function onReceive(DataPacketReceiveEvent $event)
{
$p = $event->getPlayer();
$pk = $event->getPacket();
if ($pk instanceof PlayerActionPacket) {
if ($pk->action === PlayerActionPacket::ACTION_START_BREAK) {
$this->positions[$p->getName()] = $p->getLocation();
}
}
}
示例8: onJump
public function onJump(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
if (!$packet instanceof PlayerActionPacket) {
return;
}
$player = $event->getPlayer();
if ($packet->action === PlayerActionPacket::ACTION_JUMP && isset($this->onChair[$player->getName()])) {
$removepk = new RemoveEntityPacket();
$removepk->eid = $this->onChair[$player->getName()];
$this->getServer()->broadcastPacket($this->getServer()->getOnlinePlayers(), $removepk);
unset($this->onChair[$player->getName()]);
}
}
示例9: onPacketReceived
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
$player = $event->getPlayer();
if ($pk instanceof UseItemPacket and $pk->face === 0xff) {
$item = $player->getInventory()->getItemInHand();
if ($item->getId() == 369) {
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $player->getLevel()->getChunk($player->x >> 4, $player->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x + 0.5), new Double("", $player->y), new Double("", $player->z + 0.5)]), "Motion" => new Enum("Motion", [new Double("", -sin($mot) * 0.02), new Double("", 0.2), new Double("", -cos($mot) * 0.02)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "Fuse" => new Byte("Fuse", 100)]));
$tnt->spawnToAll();
$player->getLevel()->addSound(new AnviluseSound($player), array($player));
return true;
}
}
}
示例10: onInteract
public function onInteract(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
if ($event->getPacket()->pid() === Info::INTERACT_PACKET) {
$packet = $event->getPacket();
$player = $event->getPlayer();
$target = $player->getLevel()->getEntity($packet->target);
if ($target instanceof Chair) {
$action = $packet->action;
if ($action === 2 or $action === 3) {
$target->standupSittingEntity();
$target->close();
}
}
}
}
示例11: onDataPacketReceive
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) {
return false;
}
$p = $event->getPlayer();
$inv = $p->getInventory();
$i = $inv->getItemInHand();
if (isset($this->armorTable[$id = $i->getID()])) {
$ai = $inv->getArmorItem($type = $this->armorTable[$id]);
$inv->setArmorItem($type, $i, $p);
$inv->setItem($inv->getHeldItemSlot(), $ai);
$inv->sendContents($p);
$inv->sendArmorContents($p);
}
}
示例12: onDataPacketReceiveEvent
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
if ($this->plugin->trackingOn) {
$packet = $event->getPacket();
// $pkId = $packet->pid();
$class_path_ar = explode('\\', get_class($packet));
$pkName = end($class_path_ar);
if (isset($this->plugin->receivedPackets[$pkName])) {
$this->plugin->receivedPackets[$pkName]++;
} else {
$this->plugin->receivedPackets[$pkName] = 1;
}
}
/*
if(isset($this->plugin->receivedPackets[$pkId])) {
$this->plugin->receivedPackets[$pkId]++;
} else {
$this->plugin->receivedPackets[$pkId] = 1;
}
*/
}
示例13: onDataPacketReceive
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) {
return false;
}
$p = $event->getPlayer();
$inv = $p->getInventory();
$i = $inv->getItemInHand();
if ($i->getID() == 262) {
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $p->x), new Double("", $p->y + $p->getEyeHeight()), new Double("", $p->z)]), "Motion" => new Enum("Motion", [new Double("", -sin($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI)), new Double("", -sin($p->getPitch() / 180 * M_PI)), new Double("", cos($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $p->getyaw()), new Float("", $p->getPitch())])]);
$arrow = new Arrow($p->chunk, $nbt, $p);
$ev = new EntityShootBowEvent($p, Item::get(264, 0, 0), $arrow, 1.5);
$this->getServer(0)->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$arrow->kill();
} else {
$i->setCount($i->getCount() - 1);
$inv->setItem($inv->getHeldItemSlot(), $i);
$arrow->spawnToAll();
}
}
}
示例14: onPacketReceived
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk instanceof InteractPacket) {
if (isset($this->npc[$pk->target])) {
if (isset($this->msgQueue[$event->getPlayer()->getName()])) {
$npc = $this->npc[$pk->target];
$npc->setMessage($this->msgQueue[$event->getPlayer()->getName()]);
unset($this->msgQueue[$event->getPlayer()->getName()]);
$event->getPlayer()->sendMessage("You have set NPC " . TextFormat::AQUA . $npc->getName() . TextFormat::WHITE . " to say " . TextFormat::GREEN . $npc->getMessage());
return;
} else {
$this->npc[$pk->target]->onInteract($event->getPlayer());
}
}
}
}
示例15: onPacketReceived
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof InteractPacket) {
$boat = $player->getLevel()->getEntity($packet->target);
if ($boat instanceof Boat) {
if ($packet->action === 1) {
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = $player->getId();
$pk->type = 2;
$this->getServer()->broadcastPacket($player->getLevel()->getPlayers(), $pk);
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = 0;
$pk->type = 2;
$player->dataPacket($pk);
$this->riding[$player->getName()] = $packet->target;
} elseif ($packet->action === 3) {
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = $player->getId();
$pk->type = 3;
$this->getServer()->broadcastPacket($player->getLevel()->getPlayers(), $pk);
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = 0;
$pk->type = 3;
$player->dataPacket($pk);
if (isset($this->riding[$event->getPlayer()->getName()])) {
unset($this->riding[$event->getPlayer()->getName()]);
}
}
}
} elseif ($packet instanceof MovePlayerPacket) {
if (isset($this->riding[$player->getName()])) {
$boat = $player->getLevel()->getEntity($this->riding[$player->getName()]);
if ($boat instanceof Boat) {
$boat->x = $packet->x;
$boat->y = $packet->y;
$boat->z = $packet->z;
}
}
}
}