Я переключаю слот на зелье или наоборот пишет Без эффектов хоть в loretext написано другое.
Код:
public function GetLevitationPotion() {
$displayText = ‘§r§fЗелье левитации’;
$loreText = [
"§r§7Левитация (0:45) "
];
$loreTags = [];
foreach ($loreText as $line) {
$loreTags[] = new StringTag("", $line);
}
$loreCompound = new ListTag("Lore", $loreTags);
$tag = new CompoundTag("", [
"levitationPotionTag" => new IntTag("levitationPotionTag"),
"display" => new CompoundTag("display", [
"Name" => new StringTag("Name", $displayText),
"Lore" => $loreCompound,
]),
]);
$item = Item::get(Item::POTION, 0, 1);
$item->setNamedTag($tag);
return $item;
}
public function isLevitationPotion($item) {
if (!$item->hasCompoundTag())
return false;
$tag = $item->getNamedTag();
return isset($tag->levitationPotionTag);
}
public function onConsumeLevitationPotion(PlayerItemConsumeEvent $event) {
$player = $event->getPlayer();
$item = $event->getItem();
if ($this->isLevitationPotion($item)) {
$levitationEffect = Effect::getEffect(Effect::LEVITATION)->setDuration(900)->setAmplifier(0)->setVisible(true);
$player->addEffect($levitationEffect);
}
}
public function GetLevitationPotionTimeUp() {
$displayText = '§r§fЗелье левитации';
$loreText = [
"§r§7Левитация (1:20) "
];
$loreTags = [];
foreach ($loreText as $line) {
$loreTags[] = new StringTag("", $line);
}
$loreCompound = new ListTag("Lore", $loreTags);
$tag = new CompoundTag("", [
"levitationPotionTimeUpTag" => new IntTag("levitationPotionTimeUpTag"),
"display" => new CompoundTag("display", [
"Name" => new StringTag("Name", $displayText),
"Lore" => $loreCompound,
]),
]);
$item = Item::get(Item::POTION, 0, 1);
$item->setNamedTag($tag);
return $item;
}
public function isLevitationPotionTimeUp($item) {
if (!$item->hasCompoundTag())
return false;
$tag = $item->getNamedTag();
return isset($tag->levitationPotionTimeUpTag);
}
public function onConsumeLevitationPotionTimeUp(PlayerItemConsumeEvent $event) {
$player = $event->getPlayer();
$item = $event->getItem();
if ($this->isLevitationPotionTimeUp($item)) {
$levitationEffect = Effect::getEffect(Effect::LEVITATION)->setDuration(1600)->setAmplifier(0)->setVisible(true);
$player->addEffect($levitationEffect);
}
}
public function GetLevitationPotionTwo() {
$displayText = '§r§fЗелье левитации';
$loreText = [
"§r§7Левитация II (0:22) "
];
$loreTags = [];
foreach ($loreText as $line) {
$loreTags[] = new StringTag("", $line);
}
$loreCompound = new ListTag("Lore", $loreTags);
$tag = new CompoundTag("", [
"levitationPotionTwoTag" => new IntTag("levitationPotionTwoTag"),
"display" => new CompoundTag("display", [
"Name" => new StringTag("Name", $displayText),
"Lore" => $loreCompound,
]),
]);
$item = Item::get(Item::POTION, 0, 1);
$item->setNamedTag($tag);
return $item;
}
public function isLevitationPotionTwo($item) {
if (!$item->hasCompoundTag())
return false;
$tag = $item->getNamedTag();
return isset($tag->levitationPotionTwoTag);
}
public function onConsumeLevitationPotionTwo(PlayerItemConsumeEvent $event) {
$player = $event->getPlayer();
$item = $event->getItem();
if ($this->isLevitationPotionTwo($item)) {
$levitationEffect = Effect::getEffect(Effect::LEVITATION)->setDuration(440)->setAmplifier(1)->setVisible(true);
$player->addEffect($levitationEffect);
}
}