本文整理匯總了PHP中pocketmine\entity\Effect::setDuration方法的典型用法代碼示例。如果您正苦於以下問題:PHP Effect::setDuration方法的具體用法?PHP Effect::setDuration怎麽用?PHP Effect::setDuration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\entity\Effect
的用法示例。
在下文中一共展示了Effect::setDuration方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setVanish
/**
* Set the Vanish mode on or off
*
* @param Player $player
* @param bool $state
* @param bool $noPacket
* @return bool
*/
public function setVanish(Player $player, $state, $noPacket = false)
{
if (!is_bool($state)) {
return false;
}
if ($this->invisibilityEffect === null) {
$effect = new Effect(Effect::INVISIBILITY, "Vanish", 127, 131, 146);
$effect->setDuration(1728000);
// 24 hours... Well... No one will play more than this, so I think its OK xD
$this->invisibilityEffect = $effect;
}
$this->getServer()->getPluginManager()->callEvent($ev = new PlayerVanishEvent($this, $player, $state, $noPacket));
if ($ev->isCancelled()) {
return false;
}
$state = $ev->willVanish();
$player->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, $state);
$player->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, $state ? 0 : 1);
/** @var Player[] $pl */
$pl = [];
foreach ($player->getLevel()->getPlayers() as $p) {
if ($state || !$state && !in_array($p->getName(), $ev->getHiddenFor())) {
$pl[] = $p;
}
}
$noPacket = $ev->noPacket();
if ($this->isVanished($player) && $ev->noPacket() !== ($priority = $this->hasNoPacket($player))) {
$noPacket = $priority;
}
if (!$noPacket) {
if (!$state) {
$pk = new MobEffectPacket();
$pk->eid = $player->getId();
$pk->eventId = MobEffectPacket::EVENT_REMOVE;
$pk->effectId = $this->invisibilityEffect->getId();
} else {
$pk = new MobEffectPacket();
$pk->eid = $player->getId();
$pk->effectId = $this->invisibilityEffect->getId();
$pk->amplifier = $this->invisibilityEffect->getAmplifier();
$pk->particles = $this->invisibilityEffect->isVisible();
$pk->duration = $this->invisibilityEffect->getDuration();
$pk->eventId = MobEffectPacket::EVENT_ADD;
}
$this->getServer()->broadcastPacket($pl, $pk);
} else {
if (!$state) {
foreach ($pl as $p) {
$p->showPlayer($player);
}
} else {
foreach ($pl as $p) {
$p->hidePlayer($player);
}
}
}
$this->getSession($player)->setVanish($state, !$state ? $ev->noPacket() : $noPacket);
return true;
}