public function removeSpectator(Player $player) { if (isset($this->spectators[strtolower($player->getName())])) { unset($this->spectators[strtolower($player->getName())]); } $this->update(); }
/** * @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()]; }
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(); } } } }
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."; }
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; }
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; }
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; }
private function internal_onQuit(Player $player) { if (isset($this->sessions[$player->getId()])) { $this->sessions[$player->getId()]->close(); unset($this->sessions[$player->getId()]); } }
/** * @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); } }
public function __construct(SimpleWarp $plugin, Warp $warp, Player $player) { parent::__construct($plugin); $this->warp = $warp; $this->player = $player; $this->position = $player->getPosition(); }
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)); }
public function setBal($amt, Player $player) { if (!$this->checkReady()) { return false; } return !isset($this->getAPI()->setMoney($player->getName(), $amt)->description); }
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; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player && !$player->isSneaking() || $player === null) { $this->getLevel()->scheduleUpdate($this, 500); $this->togglePowered(); } }
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)); }
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; }
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; }
public function sendWeather(Player $p) { $pk1 = new LevelEventPacket(); $pk1->evid = LevelEventPacket::EVENT_STOP_RAIN; $pk1->data = $this->strength1; $pk2 = new LevelEventPacket(); $pk2->evid = LevelEventPacket::EVENT_STOP_THUNDER; $pk2->data = $this->strength2; if ($p->weatherData[0] != $this->weatherNow) { $p->dataPacket($pk1); $p->dataPacket($pk2); if ($this->weatherNow == 1) { $pk = new LevelEventPacket(); $pk->evid = LevelEventPacket::EVENT_START_RAIN; $pk->data = $this->strength1; $p->dataPacket($pk); } elseif ($this->weatherNow == 2) { $pk = new LevelEventPacket(); $pk->evid = LevelEventPacket::EVENT_START_RAIN; $pk->data = $this->strength1; $p->dataPacket($pk); $pk = new LevelEventPacket(); $pk->evid = LevelEventPacket::EVENT_START_THUNDER; $pk->data = $this->strength2; $p->dataPacket($pk); } elseif ($this->weatherNow == 3) { $pk = new LevelEventPacket(); $pk->evid = LevelEventPacket::EVENT_START_THUNDER; $pk->data = $this->strength2; $p->dataPacket($pk); } $p->weatherData = [$this->weatherNow, $this->strength1, $this->strength2]; } }
public function onClose(Player $who) { $pk = new ContainerClosePacket(); $pk->windowid = $who->getWindowId($this); $who->dataPacket($pk); parent::onClose($who); }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $faces = [0 => 0, 1 => 1, 2 => 2, 3 => 3]; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; $this->getLevel()->setBlock($block, $this, true); return true; }
public function __construct(HereAuth $main, Player $player, AccountInfo $info) { $this->main = $main; $this->player = $player; $this->accountInfo = $info; if ($info->passwordHash === null) { if (!$main->getConfig()->getNested("ForceRegister.Enabled", true)) { // no registration involved $this->onAuth(); $reminder = $main->getConfig()->getNested("ForceRegister.Reminder", ""); if (strlen($reminder) > 0) { $player->sendMessage($reminder); } return; } $this->startRegistration(); return; } if ($info->opts->autoSecret and $player->getClientSecret() === $info->lastSecret) { $this->onAuth(); return; } if ($info->opts->autoIp and $player->getAddress() === $info->lastIp) { $this->onAuth(); return; } if ($info->opts->autoUuid and $player->getUniqueId()->toBinary() === $info->lastUuid) { $this->onAuth(); return; } $this->state = self::STATE_PENDING_LOGIN; $this->player->sendMessage($main->getConfig()->getNested("Messages.Login.Query", "Please login")); }
/** * 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"); }
public function onRun(array $args, Player $player) { $mode = 0; $target = $player->getPosition(); while (isset($args[0])) { $arg = array_shift($args); switch ($arg) { case "c": case "crosshair": $target = WorldEditArt::getCrosshairTarget($player); if (!$target instanceof Block) { return "The block is too far/in the void/sky!"; } break; case "v": case "view": $mode = 1; break; } } switch ($mode) { case 0: $this->getMain()->setAnchor($player, $target); return "Your anchor has been set to " . WorldEditArt::posToStr($target) . "."; case 1: $anchor = $this->getMain()->getAnchor($player); if (!$anchor instanceof Position) { return "You don't have an anchor selected!"; } return "Your anchor is at " . WorldEditArt::posToStr($anchor) . "."; default: return null; } }
private function private_onLogin(Player $player) { /** @var string|LoginDataQuery $LoginQuery */ $LoginQuery = $this->main->getLoginQueryImpl(); /** @noinspection PhpDeprecationInspection */ new $LoginQuery($this->main, $player->getId(), $player->getName(), $player->getAddress(), $player->getClientId()); }
public function addPlacedBlock(Block $block, Player $player) { $name = $player->getName(); $block = $block->getName() . " ID: " . $block->getId() . " "; $end = "[" . time() . "] " . $name . " placed - " . $block; $this->blocks[] = $end; }
public function executeRankUp(Player $player, $response, $gotreward = false) { $message = null; switch ($response) { case "0": $message = str_replace("##voteurl##", $this->config->getVoteUrl(), $this->config->getMessage("vote-open")); break; case "1": if ($gotreward == false) { $this->requestApiTaks($player->getName(), "action=post&", true); $this->rankUp->rankUp($this, $player); $command = "say " . $this->config->getMessage("vote-success"); $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("##player##", $player->getName(), $command)); } break; case "2": $message = $this->config->getMessage("vote-nextday"); break; default: $message = $this->config->getMessage("error-fetching-vote"); $this->getLogger()->warning(TextFormat::RED . $message); break; } if ($message) { $this->getLogger()->info(TextFormat::GREEN . $message); $player->sendMessage($message); } }
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; $result->setDamage($target->getId()); $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 ($targetBlock instanceof Liquid) { $result = clone $this; $result->setDamage(0); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($block, $targetBlock, true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }
public function loadInventory(Player $player, Inventory $inv) { $n = trim(strtolower($player->getName())); if ($n === "") { return false; } $d = substr($n, 0, 1); $path = $this->getDataFolder() . $d . "/" . $n . ".yml"; if (!is_file($path)) { return false; } $cfg = new Config($path, Config::YAML); $yaml = $cfg->getAll(); if ($this->isGlobal) { $ln = "*"; } else { $ln = trim(strtolower($player->getLevel()->getName())); } if (!isset($yaml[$ln])) { return false; } $inv->clearAll(); foreach ($yaml[$ln] as $slot => $t) { list($id, $dam, $cnt) = explode(":", $t); $item = Item::get($id, $dam, $cnt); $inv->setItem($slot, $item); } return true; }
/** * * @param Player $player */ public function giveEffects(Player $player) { $effects = $this->getEffects(); foreach ($effects as $effect) { $player->addEffect($effect); } }
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); } }