php pocketmine-Player类(方法)实例源码

下面列出了php pocketmine-Player 类(方法)源码代码实例,从而了解它的用法。

作者:EmreTr    项目:TNTRu   
public function removeSpectator(Player $player)
 {
     if (isset($this->spectators[strtolower($player->getName())])) {
         unset($this->spectators[strtolower($player->getName())]);
     }
     $this->update();
 }

作者:TexusDar    项目:ImagicalMin   
public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player && !$player->isSneaking() || $player === null) {
         $this->getLevel()->scheduleUpdate($this, 500);
         $this->togglePowered();
     }
 }

作者:Edwardthedog    项目:Steadfast   
public function onActivate(Item $item, Player $player = \null)
 {
     $faces = [0 => 3, 1 => 0, 2 => 1, 3 => 2];
     $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x3 | ~$this->meta & 0x4;
     $this->getLevel()->setBlock($this, $this, \true);
     return \true;
 }

作者:barnseyminesu    项目:Small-ZC-Plugin   
/**
  * @param Player $player
  * @return mixed
  */
 public function getAttachment(Player $player)
 {
     if (!isset($this->attachments[$player->getName()])) {
         $this->attachments[$player->getName()] = $player->addAttachment($this);
     }
     return $this->attachments[$player->getName()];
 }

作者:ClearSkyTea    项目:ClearSk   
public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         $nbt = new CompoundTag("", [new StringTag("id", Tile::ITEM_FRAME), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new ByteTag("ItemRotation", 0), new FloatTag("ItemDropChance", 1.0)]);
         Tile::createTile(Tile::ITEM_FRAME, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     }
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         return false;
     }
     if ($tile->getItem()->getId() === 0) {
         $tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
         if ($player instanceof Player) {
             if ($player->isSurvival()) {
                 $count = $item->getCount();
                 if (--$count <= 0) {
                     $player->getInventory()->setItemInHand(Item::get(Item::AIR));
                     return true;
                 }
                 $item->setCount($count);
                 $player->getInventory()->setItemInHand($item);
             }
         }
     } else {
         $itemRot = $tile->getItemRotation();
         if ($itemRot === 7) {
             $itemRot = 0;
         } else {
             $itemRot++;
         }
         $tile->setItemRotation($itemRot);
     }
     return true;
 }

作者:EmreTr    项目:rt   
public function burstArrow(Player $player)
 {
     if ($player->getInventory()->getItemInHand()->getId() === Item::BOW) {
         $bow = $player->getInventory()->getItemInHand();
         $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x), new Double("", $player->y + $player->getEyeHeight()), new Double("", $player->z)]), "Motion" => new Enum("Motion", [new Double("", -\sin($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI)), new Double("", -\sin($player->pitch / 180 * M_PI)), new Double("", \cos($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $player->yaw), new Float("", $player->pitch)])]);
         $ev = new EntityShootBowEvent($player, $bow, Entity::createEntity("Arrow", $player->chunk, $nbt, $player), 1.5);
         $this->getServer()->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             $ev->getProjectile()->kill();
         } else {
             $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
             if ($ev->getProjectile() instanceof Projectile) {
                 $this->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
                 if ($projectileEv->isCancelled()) {
                     $ev->getProjectile()->kill();
                 } else {
                     $this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
                     $ev->getProjectile()->spawnToAll();
                 }
             } else {
                 $this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
                 $ev->getProjectile()->spawnToAll();
             }
         }
     }
 }

作者:MCPEGamerJPatGitHu    项目:xEco   
public function onRun(PlayerEnt $entity, Player $player, array $args)
 {
     if (!isset($args[1])) {
         return false;
     }
     $bank = isset($args[2]) and strtolower($args[2]) === "-bank";
     if ($bank and !$player->hasPermission("xecon.cmd.pay.bank")) {
         return "You don't have permission to pay bank money to other players.";
     } elseif (!$bank and !$player->hasPermission("xecon.cmd.pay.cash")) {
         return "You don't have permission to pay cash to other players.";
     }
     $toEnt = $this->getPlugin()->getPlayerEnt($args[0]);
     if (!$toEnt instanceof PlayerEnt) {
         return "Player {$args['0']} is not registered in the database!";
     }
     $to = $toEnt->getAccount($name = $bank ? PlayerEnt::ACCOUNT_BANK : PlayerEnt::ACCOUNT_CASH);
     $from = $entity->getAccount($name);
     $amount = floatval($args[1]);
     if ($amount <= 0) {
         return "Amount must be larger than zero!";
     }
     if (!$from->canPay($amount)) {
         return "You cannot pay \${$amount} from your {$from} account.";
     }
     if (!$to->canReceive($amount)) {
         return "{$args['0']}'s {$to} account cannot receive \${$amount}.";
     }
     $from->pay($to, $amount, implode(" ", array_slice($args, 2 + ($bank ? 1 : 0))));
     return "Transaction completed: \${$amount} has been paid to {$args['1']}'s {$to} account from your {$from} account.";
 }

作者:ClearSkyTea    项目:ClearSk   
public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === Dye::BONEMEAL) {
         $grow = false;
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK && $this->getSide(0, 2)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 2; $y++) {
                 $b = $this->getSide(1, $y);
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         $grow = true;
                     }
                     break;
                 } else {
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if ($grow && $player->isSurvival()) {
             $item->count--;
         }
         return true;
     }
     return false;
 }

作者:GoneTon    项目:WorldEditAr   
private function internal_onQuit(Player $player)
 {
     if (isset($this->sessions[$player->getId()])) {
         $this->sessions[$player->getId()]->close();
         unset($this->sessions[$player->getId()]);
     }
 }

作者:PrimusL    项目:EssentialsP   
/**
  * @param int $currentTick
  */
 public function onRun($currentTick)
 {
     if ($this->requester instanceof Player && $this->requester->isOnline()) {
         $this->getAPI()->getServer()->getLogger()->debug(TextFormat::YELLOW . "Running EssentialsPE's TPRequestTask");
         $this->getAPI()->removeTPRequest($this->requester);
     }
 }

作者:TBNRFrags246    项目:Econom   
public function __construct(SimpleWarp $plugin, Warp $warp, Player $player)
 {
     parent::__construct($plugin);
     $this->warp = $warp;
     $this->player = $player;
     $this->position = $player->getPosition();
 }

作者:ClearSkyTea    项目:ClearSk   
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $direction = ($player !== null ? $player->getDirection() : 0) & 0x3;
     $this->meta = $this->meta & 0xc | $direction;
     $this->getLevel()->setBlock($block, $this, true, true);
     $this->getLevel()->addSound(new AnvilFallSound($this));
 }

作者:haruajsur    项目:BattleKit   
public function setBal($amt, Player $player)
 {
     if (!$this->checkReady()) {
         return false;
     }
     return !isset($this->getAPI()->setMoney($player->getName(), $amt)->description);
 }

作者:ClearSkyTea    项目:ClearSk   
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($face !== 0) {
         $nbt = new CompoundTag("", ["id" => new StringTag("id", Tile::SIGN), "x" => new IntTag("x", $block->x), "y" => new IntTag("y", $block->y), "z" => new IntTag("z", $block->z), "Text1" => new StringTag("Text1", ""), "Text2" => new StringTag("Text2", ""), "Text3" => new StringTag("Text3", ""), "Text4" => new StringTag("Text4", "")]);
         if ($player !== null) {
             $nbt->Creator = new StringTag("Creator", $player->getRawUniqueId());
         }
         if ($item->hasCustomBlockData()) {
             foreach ($item->getCustomBlockData() as $key => $v) {
                 $nbt->{$key} = $v;
             }
         }
         if ($face === 1) {
             $this->meta = floor(($player->yaw + 180) * 16 / 360 + 0.5) & 0xf;
             $this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true);
             Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
             return true;
         } else {
             $this->meta = $face;
             $this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true);
             Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
             return true;
         }
     }
     return false;
 }

作者:haruajsur    项目:BattleKit   
public function applyTo(Player $p)
 {
     $inventory = $p->getInventory()->getContents();
     $size = $p->getInventory()->getSize();
     foreach ($this->items as $id => $item) {
         if (!is_numeric($id)) {
             switch ($id) {
                 case 'helmet':
                     $id = $size;
                     break;
                 case 'chestplate':
                     $id = $size + 1;
                     break;
                 case 'leggings':
                     $id = $size + 2;
                     break;
                 case 'boots':
                     $id = $size + 3;
                     break;
             }
         }
         $inventory[$id] = $item;
     }
     $p->getInventory()->setContents($inventory);
     $p->getInventory()->sendArmorContents([$p]);
     foreach ($this->commands as $command) {
         $command = str_replace("{player}", $p->getName(), $command);
         $this->getPlugin()->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
     }
     if ($this->onGiveMessage !== false) {
         $p->sendMessage($this->onGiveMessage);
     }
 }

作者:ChiefArt    项目:SurvivalGame   
public function joinToArena(Player $p)
 {
     if ($this->game >= 1) {
         $p->sendMessage($this->msg->getMsg("already_running"));
     }
     $ev = new PlayerJoinArenaEvent($p, $this, "");
     if ($this->isArenaFull() && !$p->hasPermission("sg.arena.join.full")) {
         $ev->setMessage($this->msg->getMsg("game_full"));
         $ev->setCancelled();
     } else {
         if (!$p->hasPermission("sg.arena.join")) {
             $ev->setMessage(Messages::getMsg("no_permission_join", ["%NAME", $this->name]));
             $ev->setCancelled();
         } else {
             $ev->setMessage(Messages::getMsg("join_to_arena", ["%NAME" => $this->name]));
         }
     }
     $this->plugin->getServer()->getPluginManager()->callEvent($ev);
     if ($ev->isCancelled()) {
         return;
     }
     $this->messageArenaPlayers(str_replace(["%PLAYER", "%COUNT", "%MAXCOUNT"], [$p->getName(), count($this->getPlayers()), $this->getMaxPlayers()], $this->msg->getMsg("game_connect")));
     $this->players[strtolower($p->getName())]["ins"] = $p;
     $this->saveInventory($p);
     $p->teleport($this->getNextJoinPos($p));
 }

作者:abc1230987    项目:Genisy   
public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($tile instanceof FlowerPotTile) {
         if ($tile->getFlowerPotItem() === Item::AIR) {
             switch ($item->getId()) {
                 case Item::TALL_GRASS:
                     if ($item->getDamage() === 1) {
                         break;
                     }
                 case Item::SAPLING:
                 case Item::DEAD_BUSH:
                 case Item::DANDELION:
                 case Item::RED_FLOWER:
                 case Item::BROWN_MUSHROOM:
                 case Item::RED_MUSHROOM:
                 case Item::CACTUS:
                     $tile->setFlowerPotData($item->getId(), $item->getDamage());
                     $this->setDamage($item->getId());
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }

作者:Cecil10    项目:PocketMine-0.13.   
public function onClose(Player $who)
 {
     $pk = new ContainerClosePacket();
     $pk->windowid = $who->getWindowId($this);
     $who->dataPacket($pk);
     parent::onClose($who);
 }

作者:xpyctu    项目:Genisy   
public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anviletEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $tile = $this->getLevel()->getTile($this);
         $enchantTable = null;
         if ($tile instanceof EnchantTable) {
             $enchantTable = $tile;
         }
     } else {
         $this->getLevel()->setBlock($this, $this, true, true);
         $nbt = new CompoundTag("", [new StringTag("id", Tile::ENCHANT_TABLE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
         if ($item->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
         }
         if ($item->hasCustomBlockData()) {
             foreach ($item->getCustomBlockData() as $key => $v) {
                 $nbt->{$key} = $v;
             }
         }
         $enchantTable = Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     }
     $player->addWindow($enchantTable->getInventory());
     return true;
 }

作者:DWW    项目:pocketmine-plugin   
/**
  * This will transfer a player and also add the workaround for players
  * lingering connections...
  * @param Player $player
  * @param str $address
  * @param int $port
  * @param str $message
  * @return bool
  */
 public static function transferPlayer(Player $player, $address, $port, $message = null)
 {
     $ft = $player->getServer()->getPluginManager()->getPlugin("FastTransfer");
     if ($ft === null) {
         return false;
     }
     if ($message === null) {
         $message = mc::_("You are being transferred");
     }
     $res = $ft->transferPlayer($player, $address, $port, $message);
     // find out the RakLib interface, which is the network interface that MCPE players connect with
     foreach ($player->getServer()->getNetwork()->getInterfaces() as $interface) {
         if ($interface instanceof RakLibInterface) {
             $raklib = $interface;
             break;
         }
     }
     if (!isset($rakLib)) {
         return $res;
     }
     // calculate the identifier for the player used by RakLib
     $identifier = $player->getAddress() . ":" . $player->getPort();
     // this method call is the most important one -
     // it sends some signal to RakLib that makes it think that the client
     // has clicked the "Quit to Title" button (or timed out). Some RakLib
     // internal stuff will then tell PocketMine that the player has quitted.
     $rakLib->closeSession($identifier, "transfer");
 }


问题


面经


文章

微信
公众号

扫码关注公众号