本文整理汇总了PHP中pocketmine\Player类的典型用法代码示例。如果您正苦于以下问题:PHP Player类的具体用法?PHP Player怎么用?PHP Player使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Player类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeSpectator
public function removeSpectator(Player $player)
{
if (isset($this->spectators[strtolower($player->getName())])) {
unset($this->spectators[strtolower($player->getName())]);
}
$this->update();
}
示例2: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player && !$player->isSneaking() || $player === null) {
$this->getLevel()->scheduleUpdate($this, 500);
$this->togglePowered();
}
}
示例3: onActivate
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;
}
示例4: getAttachment
/**
* @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()];
}
示例5: onActivate
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;
}
示例6: burstArrow
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();
}
}
}
}
示例7: onRun
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.";
}
示例8: onActivate
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;
}
示例9: internal_onQuit
private function internal_onQuit(Player $player)
{
if (isset($this->sessions[$player->getId()])) {
$this->sessions[$player->getId()]->close();
unset($this->sessions[$player->getId()]);
}
}
示例10: onRun
/**
* @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);
}
}
示例11: __construct
public function __construct(SimpleWarp $plugin, Warp $warp, Player $player)
{
parent::__construct($plugin);
$this->warp = $warp;
$this->player = $player;
$this->position = $player->getPosition();
}
示例12: place
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));
}
示例13: setBal
public function setBal($amt, Player $player)
{
if (!$this->checkReady()) {
return false;
}
return !isset($this->getAPI()->setMoney($player->getName(), $amt)->description);
}
示例14: place
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;
}
示例15: applyTo
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);
}
}