Как сделать, чтобы предмет не работал на игрока, который его активировал, но работал на всех остальных, если установлен модификатор ALLNOTME.
<?php namespace CIS; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; use pocketmine\item\Item; use pocketmine\Server; use pocketmine\math\Vector3; class Main extends PluginBase implements Listener { private $itemsConfig = []; public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } if (!file_exists($this->getDataFolder() . 'items.yml')) { file_put_contents($this->getDataFolder() . 'items.yml', $this->getResource('items.yml')); } $this->itemsConfig = yaml_parse(file_get_contents($this->getDataFolder() . 'items.yml')); $this->getLogger()->info("Плагин CIS включен!"); } public function onDisable() { $this->getLogger()->info("Плагин CIS выключен!"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args): bool { if ($command->getName() === "cis") { if (empty($args)) { $sender->sendMessage("Используйте: /cis create <название> <название_на_предмете> <описание_на_предмете> или /cis give <игрок> <название>"); return true; } switch ($args[0]) { case "create": if (count($args) < 4) { $sender->sendMessage("Используйте: /cis create <название> <название_на_предмете> <описание_на_предмете>"); return true; } $itemName = $args[1]; $itemDisplayName = $args[2]; $itemDescription = implode(" ", array_slice($args, 3)); $activators = []; if ($sender instanceof Player) { $handItem = $sender->getInventory()->getItemInHand(); $itemId = $handItem->getId(); $item = $handItem; $item->setCustomName($itemDisplayName); $lore = explode("\n", $itemDescription); $item->setLore($lore); $this->saveItemConfig($itemName, $itemId, $itemDisplayName, $itemDescription, $activators, $sender); $sender->sendMessage("§aКастомный предмет успешно создан!"); } return true; case "give": if (count($args) < 3) { $sender->sendMessage("§6Используйте:§r /cis give <игрок> <название>"); return true; } $player = $this->getServer()->getPlayer($args[1]); if ($player instanceof Player) { $itemName = $args[2]; $itemInfo = $this->getItemConfig($itemName); if ($itemInfo !== null) { $item = Item::get($itemInfo["item"]); $item->setCustomName($itemInfo["display-name"]); $lore = explode("\n", $itemInfo["display-lore"]); $item->setLore($lore); $player->getInventory()->addItem($item); $sender->sendMessage("§aКастомный предмет успешно выдан игроку " . $player->getName()); } else { $sender->sendMessage("§cКастомный предмет с именем '$itemName' не найден."); } } else { $sender->sendMessage("§cИгрок с именем '$args[1]' не найден."); } return true; default: $sender->sendMessage("§6Используйте:§r /cis create <название> <название_на_предмете> <описание_на_предмете> или /cis give <игрок> <название>"); return true; } } return false; } public function onPlayerInteract(PlayerInteractEvent $event): void { $player = $event->getPlayer(); $item = $event->getItem(); $itemId = $item->getId(); $playerName = $player->getName(); foreach ($this->itemsConfig as $itemName => $itemConfig) { if ($itemConfig['item'] === $itemId) { if (isset($itemConfig['activators'])) { foreach ($itemConfig['activators'] as $activator) { $modifier = isset($activator['modifier']) ? $activator['modifier'] : ''; if (isset($activator[0]) && $activator[0] === 'ALLNOTME' && in_array($activator[1], ['MSG', 'POPUP', 'TELEPORT'])) { return; } if (isset($activator['action'])) { if (is_string($activator['action'])) { $this->processActionString($player, $activator['action']); } elseif (is_array($activator['action'])) { foreach ($activator['action'] as $action) { $this->processActionString($player, $action); } } else { $this->getLogger()->warning("Действие активатора имеет неверный формат."); } } else { $this->getLogger()->warning("Действие активатора не найдено."); } } } break; } } } private function processActionString(Player $player, string $actionString): void { $actions = explode(' ', $actionString); if (count($actions) >= 3 && in_array($actions[0], ['ME', 'ALL', 'ALLNOTME'])) { $this->ActionTypeModificator($player, $actions); } else { $this->getLogger()->warning("Неверный формат действия: $actionString"); $player->sendMessage("§cНеверный формат действия. Используйте: <модификатор> <тип_действия>"); } } private function Modificator(Player $player, string $modificator, string $subtype, string $actionType, ?Player $target = null, ?array $coordinates = null): void { switch ($modificator) { case 'ME': if ($actionType === 'MSG') { $player->sendMessage($subtype); } elseif ($actionType === 'POPUP') { $player->sendPopup($subtype); } elseif ($actionType === 'TELEPORT') { if ($target instanceof Player) { $player->teleport($target); } elseif ($coordinates !== null && count($coordinates) === 3) { $player->teleport(Server::getInstance()->getDefaultLevel()->getSafeSpawn()->add($coordinates)); } else { $player->sendMessage("§cНеверный формат телепортации."); } } break; case 'ALL': $onlinePlayers = $this->getServer()->getOnlinePlayers(); if ($actionType === 'MSG') { foreach ($onlinePlayers as $onlinePlayer) { $onlinePlayer->sendMessage($subtype); } } elseif ($actionType === 'POPUP') { foreach ($onlinePlayers as $onlinePlayer) { $onlinePlayer->sendPopup($subtype); } } elseif ($actionType === 'TELEPORT') { if ($target instanceof Player) { foreach ($onlinePlayers as $onlinePlayer) { $onlinePlayer->teleport($target); } } elseif ($coordinates !== null && count($coordinates) === 3) { foreach ($onlinePlayers as $onlinePlayer) { $onlinePlayer->teleport(Server::getInstance()->getDefaultLevel()->getSafeSpawn()->add($coordinates)); } } else { $player->sendMessage("§cНеверный формат телепортации."); } } break; case 'ALLNOTME': if ($actionType === 'TELEPORT') { if ($target instanceof Player || ($coordinates !== null && count($coordinates) === 3)) { $onlinePlayers = $this->getServer()->getOnlinePlayers(); foreach ($onlinePlayers as $onlinePlayer) { if ($onlinePlayer !== $player) { if ($target instanceof Player) { $onlinePlayer->teleport($target); } elseif ($coordinates !== null && count($coordinates) === 3) { $onlinePlayer->teleport(Server::getInstance()->getDefaultLevel()->getSafeSpawn()->add($coordinates)); } } } } else { $player->sendMessage("§cНеверный формат телепортации."); } } else { $onlinePlayers = $this->getServer()->getOnlinePlayers(); foreach ($onlinePlayers as $onlinePlayer) { if ($onlinePlayer !== $player) { if ($actionType === 'MSG') { $onlinePlayer->sendMessage($subtype); } elseif ($actionType === 'POPUP') { $onlinePlayer->sendPopup($subtype); } } } } break; default: $player->sendMessage("§cНеизвестный модификатор: $modificator"); break; } } public function ActionTypeModificator(Player $player, array $actions): void { $actionType = $actions[0]; $actionSubType = $actions[1]; $actionData = implode(' ', array_slice($actions, 2)); if (!in_array($actionType, ['ME', 'ALL', 'ALLNOTME'])) { $this->getLogger()->warning("Неизвестный модификатор: $actionType"); $player->sendMessage("§cНеизвестный модификатор: $actionType"); return; } switch ($actionSubType) { case 'MSG': case 'POPUP': $this->Modificator($player, $actionType, $actionData, $actionSubType); break; case 'TELEPORT': $this->teleportPlayer($player, $actionData, $actionType); break; default: $this->getLogger()->warning("Неизвестный тип действия: $actionSubType"); $player->sendMessage("§cНеизвестный тип действия: $actionSubType"); break; } } private function teleportPlayer(Player $player, string $actionData): void { $args = explode(' ', $actionData); $count = count($args); if ($count === 1) { $targetPlayer = $this->getServer()->getPlayer($args[0]); if ($targetPlayer instanceof Player) { $player->teleport($targetPlayer); } else { $player->sendMessage("§cИгрок с именем '{$args[0]}' не найден."); } } elseif ($count === 3) { $x = (float) $args[0]; $y = (float) $args[1]; $z = (float) $args[2]; $player->teleport(new Vector3($x, $y, $z)); } else { $player->sendMessage("§cНеверное количество аргументов для телепортации."); } } private function saveItemConfig(string $itemName, int $itemId, string $displayName, string $displayLore, array $activators): void { if ($itemId === Item::AIR) { $this->getServer()->getLogger()->warning("Ошибка: Вы не можете создать кастомный предмет из пустой руки."); return; } $this->itemsConfig[$itemName] = [ "name" => $displayName, "tag" => $itemName . "Tag", "item" => $itemId, "display-name" => $displayName, "display-lore" => $displayLore, "activators" => $activators, ]; $yamlData = yaml_emit($this->itemsConfig, YAML_UTF8_ENCODING); file_put_contents($this->getDataFolder() . 'items.yml', $yamlData); } private function getItemConfig(string $itemName): ?array { return $this->itemsConfig[$itemName] ?? null; } } ?>ставим 3 символа ` и вставляем вниз код
Может дашь код в нормальном ввиде?
интересно что это))
Плагин на снг, жоска