本文整理汇总了PHP中pocketmine\Player::getServer方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::getServer方法的具体用法?PHP Player::getServer怎么用?PHP Player::getServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Player
的用法示例。
在下文中一共展示了Player::getServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player) {
$t = $this->getLevel()->getTile($this);
if ($t instanceof FurnaceTile) {
$furnace = $t;
} else {
$nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::FURNACE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
if (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof StringTag) {
if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) {
return true;
}
}
if ($player->isCreative() and $player->getServer()->limitedCreative) {
return true;
}
$player->addWindow($furnace->getInventory());
}
return true;
}
示例2: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player) {
$t = $this->getLevel()->getTile($this);
$dispenser = null;
if ($t instanceof TileDispenser) {
$dispenser = $t;
} else {
$nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::DISPENSER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$dispenser = Tile::createTile(Tile::DISPENSER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
if ($player->isCreative() and $player->getServer()->limitedCreative) {
return true;
}
$player->addWindow($dispenser->getInventory());
}
return true;
}
示例3: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player) {
$top = $this->getSide(1);
if ($top->isTransparent() !== true) {
return true;
}
$t = $this->getLevel()->getTile($this);
$chest = null;
if ($t instanceof TileChest) {
$chest = $t;
} else {
$nbt = new CompoundTag("", [new EnumTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag) {
if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) {
return true;
}
}
if ($player->isCreative() and $player->getServer()->limitedCreative) {
return true;
}
$player->addWindow($chest->getInventory());
}
return true;
}
示例4: getMaskLocation
public function getMaskLocation(Player $player)
{
// always return player current location if there is an error
if (!$this->maskLoc) {
return $player->getLocation();
}
if (!preg_match('#^((\\?spawn\\?)|((\\-)?[0-9]+,(\\-)?[0-9]+,(\\-)?[0-9]+))@([^/\\\\]+)$#', $this->maskLocPos, $match)) {
return $player->getLocation();
}
$pos = $match[1];
$world = $match[7];
$level = $player->getLevel();
if ($world === "?default?") {
$level = $player->getServer()->getDefaultLevel();
} elseif ($world !== "?current?") {
$level = $player->getServer()->getLevelByName($world);
if (!$level instanceof Level) {
$level = $player->getLevel();
}
}
if ($pos === "?spawn?") {
$position = $level->getSpawnLocation();
} else {
list($x, $y, $z) = explode(",", $pos);
$position = new Position((int) $x, (int) $y, (int) $z, $level);
}
return $position;
}
示例5: transferPlayer
/**
* 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");
}
示例6: onActivate
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;
}
示例7: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($player === null or $player->isSurvival() !== true) {
return false;
}
if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) {
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this));
if ($ev->isCancelled()) {
return false;
} else {
if ($this->count <= 1) {
$player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1));
return true;
} else {
$this->count--;
$player->getInventory()->setItemInHand($this);
}
if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) {
$player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1));
} else {
$motion = $player->getDirectionVector()->multiply(0.4);
$position = clone $player->getPosition();
$player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40);
}
return true;
}
}
return false;
}
示例8: teleport
public function teleport(Player $player)
{
if ($this->message !== null) {
$player->sendMessage($this->message);
}
if ($this->position instanceof Position) {
if ($this->position->isValid()) {
if ($this->position instanceof WeakPosition) {
$this->position->updateProperties();
}
//Server::getInstance()->getLogger()->info($this->position->x . " : " . $this->position->y . " : " . $this->position->z);
$player->teleport($this->position);
} else {
$player->sendMessage($this->getApi()->executeTranslationItem("level-not-loaded-warp"));
}
} else {
$plugin = $player->getServer()->getPluginManager()->getPlugin("FastTransfer");
if ($plugin instanceof PluginBase && $plugin->isEnabled() && $plugin instanceof FastTransfer) {
$plugin->transferPlayer($player, $this->address, $this->port);
} else {
$player->getServer()->getPluginManager()->getPlugin("SimpleWarp")->getLogger()->warning("In order to use warps tp other servers, you must install " . TextFormat::AQUA . "FastTransfer" . TextFormat::RESET . ".");
$player->sendPopup(TextFormat::RED . "Warp failed!" . TextFormat::RESET);
}
}
}
示例9: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player) {
if ($player->getServer()->limitedCreative and $player->isCreative()) {
return true;
}
$player->craftingType = Player::CRAFTING_BIG;
}
return true;
}
示例10: execute
public function execute(Player $source) : bool
{
$droppedItem = $this->getTargetItem();
if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
if (!$source->getFloatingInventory()->contains($droppedItem)) {
return false;
}
$source->getFloatingInventory()->removeItem($droppedItem);
}
$source->dropItem($droppedItem);
return true;
}
示例11: place
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
if ($player instanceof Player) {
$this->meta = ((int) $player->getDirection() + 5) % 4;
}
$this->getLevel()->setBlock($block, $this, true, true);
if ($player != null) {
// interesting for snow golem AND iron golem (this can be the body)
$firstBlock = $this->getLevel()->getBlock($block->add(0, -1, 0));
$secondBlock = $this->getLevel()->getBlock($block->add(0, -2, 0));
// interesting for iron golem (checking arms and air beyond the feet)
$armBlock1 = $this->getLevel()->getBlock($block->add(0, -1, -1));
// arm 1
$armBlock2 = $this->getLevel()->getBlock($block->add(0, -1, 1));
// arm2
$airBlock1 = $this->getLevel()->getBlock($block->add(0, -2, -1));
// beneath arms
$airBlock2 = $this->getLevel()->getBlock($block->add(0, -2, 1));
// beneath arms
// we've to test in all 3d!
$armBlock3 = $this->getLevel()->getBlock($block->add(-1, -1, 0));
// arm 1
$armBlock4 = $this->getLevel()->getBlock($block->add(1, -1, 0));
// arm2
$airBlock3 = $this->getLevel()->getBlock($block->add(-1, -2, 0));
// beneath arms
$airBlock4 = $this->getLevel()->getBlock($block->add(1, -2, 0));
// beneath arms
if ($firstBlock->getId() === Item::SNOW_BLOCK && $secondBlock->getId() === Item::SNOW_BLOCK and $player->getServer()->getProperty("golem.snow-golem-enabled") === true) {
//Block match snowgolem
$this->getLevel()->setBlock($block, new Air());
$this->getLevel()->setBlock($firstBlock, new Air());
$this->getLevel()->setBlock($secondBlock, new Air());
$snowGolem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
$snowGolem->spawnToAll();
} elseif ($firstBlock->getId() === Item::IRON_BLOCK && $secondBlock->getId() === Item::IRON_BLOCK and $player->getServer()->getProperty("golem.iron-golem-enabled") === true) {
// possible iron golem
if ($armBlock1->getId() === Item::IRON_BLOCK && $armBlock2->getId() === Item::IRON_BLOCK && $airBlock1->getId() === Item::AIR && $airBlock2->getId() === Item::AIR || $armBlock3->getId() === Item::IRON_BLOCK && $armBlock4->getId() === Item::IRON_BLOCK && $airBlock3->getId() === Item::AIR && $airBlock4->getId() === Item::AIR) {
$this->getLevel()->setBlock($block, new Air());
$this->getLevel()->setBlock($firstBlock, new Air());
$this->getLevel()->setBlock($secondBlock, new Air());
$this->getLevel()->setBlock($armBlock1, new Air());
$this->getLevel()->setBlock($armBlock2, new Air());
$this->getLevel()->setBlock($armBlock3, new Air());
$this->getLevel()->setBlock($armBlock4, new Air());
$ironGolem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
$ironGolem->spawnToAll();
}
}
}
return true;
}
示例12: onActivate
public function onActivate(Item $item, Player $player = null)
{
if (!$this->getLevel()->getServer()->anvilEnabled) {
return true;
}
if ($player instanceof Player) {
if ($player->isCreative() and $player->getServer()->limitedCreative) {
return true;
}
$player->addWindow(new AnvilInventory($this));
}
return true;
}
示例13: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$bucketContents = Block::get($this->meta);
if ($bucketContents instanceof Air) {
// Bucket Empty so pick up block
if ($target instanceof Liquid and $target->getDamage() === 0) {
$result = clone $this;
if ($target instanceof StillWater) {
$toStore = Block::WATER;
} elseif ($target instanceof StillLava) {
$toStore = Block::LAVA;
} else {
return false;
}
$result->setDamage($toStore);
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
$player->getLevel()->setBlock($target, new Air(), true, true);
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem(), $player);
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
} elseif ($bucketContents instanceof Liquid) {
// Bucket Full, so empty
$result = clone $this;
$result->setDamage(0);
if ($bucketContents instanceof Water) {
$toCreate = Block::STILL_WATER;
} elseif ($bucketContents instanceof Lava) {
$toCreate = Block::STILL_LAVA;
} else {
return false;
}
$bucketContents = Block::get($toCreate);
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
$player->getLevel()->setBlock($block, $bucketContents, true, true);
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem(), $player);
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
return false;
}
示例14: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($player instanceof Player) {
$t = $this->getLevel()->getTile($this);
if ($t instanceof TileHopper) {
if ($t->hasLock() and !$t->checkLock($item->getCustomName())) {
$player->getServer()->getLogger()->debug($player->getName() . " attempted to open a locked hopper");
return true;
}
$player->addWindow($t->getInventory());
}
}
return true;
}
示例15: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$targetBlock = Block::get($this->meta);
if ($targetBlock instanceof Air) {
if ($target instanceof Liquid and $target->getDamage() === 0) {
$result = clone $this;
$id = $target->getId();
if ($id == self::STILL_WATER) {
$id = self::WATER;
}
if ($id == self::STILL_LAVA) {
$id = self::LAVA;
}
$result->setDamage($id);
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
$player->getLevel()->setBlock($target, new Air(), true, true);
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem());
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
} elseif ($targetBlock instanceof Liquid) {
$result = clone $this;
$result->setDamage(0);
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
//Only disallow water placement in the Nether, allow other liquids to be placed
//In vanilla, water buckets are emptied when used in the Nether, but no water placed.
if (!($player->getLevel()->getDimension() === Level::DIMENSION_NETHER and $targetBlock->getID() === self::WATER)) {
$player->getLevel()->setBlock($block, $targetBlock, true, true);
}
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem());
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
return false;
}