Помогите пофиксить баг, за сотку

В общем,


Бывает все работает нормально, а иногда просто пишет по всем префиксам что они недоступны при этом они куплены. При попытке выбрать префикс пишет “Нет прав!”

Кто скинет zip файлом исправленный плагин, скину сотку на карту
NewPrefixes.zip (9,6 КБ)

Вк/тг @twizqwif

Сразу видно что из группы NewPlugins…

Угу

Class Utils

code
<?php


declare(strict_types=1);

namespace darealaqua\utils;

use darealaqua\Main;
use libs\FormAPI\SimpleForm;
use pocketmine\console\ConsoleCommandSender;
use pocketmine\level\sound\AnvilBreakSound;
use pocketmine\level\sound\BlazeShootSound;
use pocketmine\player\Player;

class Utils {
	/**
	 * @param Player $player
	 * @return mixed
	 */
	public static function getPlayerTag(Player $player) {
		return Main::getInstance()->tag->getAll()[strtolower($player->getName())]["tag"];
	}

	/**
	 * @param Player $player
	 */
	public static function setPlayerTag(Player $player, $tag) {
		Main::getInstance()->tag->setNested(strtolower($player->getName()) . ".tag", $tag);
		Main::getInstance()->tag->save();
	}

	/**
	 * @param Player $player
	 * @return SimpleForm
	 */
	public static function openTagSelectorForm(Player $player) {
		$form = new SimpleForm(function (Player $player, $data = NULL) {
			$result = $data;
			if ($result == NULL) {
				return;
			}
			switch ($result) {
				case 0:
					return;
				case 1:
					Utils::openTagForm($player);
					return;
				case 2:
					Utils::openTagShopForm($player);
					return;
			}
		});
		$form->setTitle(Main::getInstance()->config["menu-selector"]["title"]);
		$form->setContent(str_replace(["{money}", "{tag}", "{line}"], [number_format(Main::getInstance()->economy->myMoney($player)), Utils::getPlayerTag($player), "\n"], Main::getInstance()->config["menu-selector"]["content"]));
		$form->addButton(str_replace("{line}", "\n", Main::getInstance()->config["menu-selector"]["exit-button"]), 0);
		$form->addButton(str_replace("{line}", "\n", Main::getInstance()->config["menu-selector"]["tags-button"]));
		$form->addButton(str_replace("{line}", "\n", Main::getInstance()->config["menu-selector"]["shop-button"]));
		$form->sendToPlayer($player);
		return $form;
	}

	public static function openTagForm(Player $player) {
    $form = new SimpleForm(function (Player $player, $data = NULL) {
        if ($data !== NULL) {
            $tags = Main::getInstance()->config["tags"];
            if (isset($tags[$data])) {
                $tag = $tags[$data];
                if (!$player->hasPermission($tag["perm"])) {
                    $player->sendMessage(Main::getInstance()->messages->getNested("messages.no-perm"));
                } else {
                    Utils::setPlayerTag($player, $tag["name"]);
                    $player->sendMessage(str_replace(["{tag}", "{line}"], [$tag["name"], "\n"], Main::getInstance()->messages->getNested("messages.selected")));
                }
            }
        }
    });
    $form->setTitle(Main::getInstance()->config["menu-tags"]["title"]);
    $form->setContent(str_replace(["{tag}", "{line}"], [Utils::getPlayerTag($player), "\n"], Main::getInstance()->config["menu-tags"]["content"]));
    
    $atags = [];
    
    foreach (Main::getInstance()->config["tags"] as $index => $tag) {
        if ($player->hasPermission($tag["perm"])) {
            $atags[$index] = $tag;
        }
    }
    
    if (empty($atags)) {
        
        return;
    }

    foreach ($atags as $tag) {
        $form->addButton(str_replace(["{tag}", "{line}"], [$tag["name"], "\n"], Main::getInstance()->config["menu-tags"]["unlocked-button"]));
    }

    $form->sendToPlayer($player);
    return $form;
}


	/**
	 * @param Player $player
	 * @return SimpleForm
	 */
	public static function openTagShopForm(Player $player) {
		$form = new SimpleForm(function (Player $player, $data = NULL) {
			if ($data !== NULL) {
				$tag = array_values(Main::getInstance()->config["tags"])[$data];
				$myMoney = Main::getInstance()->economy->myMoney($player);
				$cost = $tag["cost"];
				if ($player->hasPermission($tag["perm"])) {
					$player->sendMessage(str_replace(["{player}", "{tag}"], [$player->getName(), $tag["name"]], Main::getInstance()->messages->getNested("messages.already")));
				} else {
					if ($myMoney >= $cost) {
						Main::getInstance()->economy->reduceMoney($player, $cost);
						$server = Main::getInstance()->getServer();
						Main::getInstance()->getServer()->dispatchCommand(new ConsoleCommandSender($server, $server->getLanguage()), str_replace(["{player}", "{permission}"], [$player->getName(), $tag["perm"]], Main::getInstance()->config["menu-shop"]["command"]));
						$player->sendMessage(str_replace(["{player}", "{tag}"], [$player->getName(), $tag["name"]], Main::getInstance()->messages->getNested("messages.bought")));
						return TRUE;
					} else {
						$player->sendMessage(str_replace(["{player}", "{tag}"], [$player->getName(), $tag["name"]], Main::getInstance()->messages->getNested("messages.no-money")));
					}
				}
			}
			return TRUE;
		});
		$form->setTitle(Main::getInstance()->config["menu-shop"]["title"]);
		$form->setContent(str_replace(["{money}", "{tag}", "{line}"], [number_format(Main::getInstance()->economy->myMoney($player)), Utils::getPlayerTag($player), "\n"], Main::getInstance()->config["menu-shop"]["content"]));
		foreach (Main::getInstance()->config["tags"] as $tag) {
			$form->addButton(str_replace(["{cost}", "{tag}", "{line}"], [number_format($tag["cost"]), $tag["name"], "\n"], Main::getInstance()->config["menu-shop"]["button"]));
		}
		$form->sendToPlayer($player);
		return $form;
	}
}```
1 лайк

Ну так пиши им что плагин с багом

Эта тема была автоматически закрыта через 12 часов после последнего ответа. В ней больше нельзя отвечать.