[LiteCore, Genisys] HomeSystem

Название: HomeSystem на 1.1.5

Статус: не слит
Конфиг:


declare(strict_types=1);

namespace HomeSystem;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\level\Location;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\utils\Config;
use function array_keys;
use function array_pop;
use function array_reverse;
use function array_shift;
use function count;
use function min;
use function strtolower;
use const JSON_BIGINT_AS_STRING;

class MishaShulman extends PluginBase{

	const PREFIX = "§8§l(§eТочка Домов§8) §l§7▷§r ";

	const AUTODONATE_SITE = "vk.com/mishkashulman";

	const POINT_CREATED = 1;
	const POINT_UPDATED = 2;

	/** @var Config */
	private $data;

	/** @var int[] */
	private $permissions = [
		//указывать пермишен и сколько точек дома для него доступно
		//ВАЖНО: не добавлять максимальное число домов для администрации. Т.е. только то, что можно купить на автодонате.
		"default" => 7,

		"home.command.vip" => 10,
		"home.command.vip+" => 15,
		"home.command.mvp" => 20,
		"home.command.mvp+" => 30,
	];

    private $warps = [
        "pvp" => array(382, 67, 119),
        "shop" => array(411, 68, 143),
        "duel" => array(453, 60, 173),
        "obmennik" => array(418, 68, 146),
        "char" => array(451, 67, 135),
        "quest" => array(413, 67, 84),
        "cases" => array(397, 68, 134),
        "mine" => array(427, 54, 66)
    ];

	public function onEnable(){
		if(!is_dir($dataFolder = $this->getDataFolder())){
			mkdir($dataFolder, 0777, true);
		}
		$this->data = new Config($dataFolder . "homes.json", Config::JSON);

		$this->permissions = array_reverse($this->permissions, true);
	}

	public function toArray(Location $location) : array{
		$levelName = ($level = $location->getLevel()) === null ? Server::getInstance()->getDefaultLevel()->getName() : $level->getName();

		return [
			$location->getFloorX() + 0.5,
			$location->getFloorY(),
			$location->getFloorZ() + 0.5,
			round($location->yaw, -1),
			round($location->pitch, -1),
			$levelName
		];
	}

	public function toLocation(array $array) : Location{
		$levelName = array_pop($array);
		if(!($server = Server::getInstance())->isLevelLoaded($levelName)){
			$server->loadLevel($levelName);
		}
		$pitch = array_pop($array);
		$yaw = array_pop($array);
		return Location::fromObject(new Vector3(... $array), $server->getLevelByName($levelName), $yaw, $pitch);
	}

	public function hasHomePoint(Player $player, string $point) : bool{
		$playerName = strtolower($player->getName());
		$data = (array)$this->data->get($playerName, []);
		return isset($data[$point]);
	}

	public function removeHomePoint(Player $player, string $point) : bool{
		$playerName = strtolower($player->getName());
		if(!$this->hasHomePoint($player, $point)){
			return false;
		}
		$data = (array)$this->data->get($playerName, []);
		unset($data[$point]);
		if(empty($data)){
			$this->data->remove($playerName);
		}else{
			$this->data->set($playerName, $data);
		}
		$this->data->save();

		return true;
	}

	public function createHomePoint(Player $player, string $point) : int{
		$playerName = strtolower($player->getName());
		$result = $this->hasHomePoint($player, $point) ? MishaShulman::POINT_UPDATED : MishaShulman::POINT_CREATED;
		$data = (array)$this->data->get($playerName, []);
		$data[$point] = $this->toArray($player->asLocation());
		$this->data->set($playerName, $data);
		$this->data->save();

		return $result;
	}

	public function getHomePoint(Player $player, string $point){
		$playerName = strtolower($player->getName());
		if(!$this->hasHomePoint($player, $point)){
			return null;
		}
		$data = (array)$this->data->get($playerName, []);

		return $this->toLocation($data[$point]);
	}

	public function getHomesList(Player $player) : array{
		$playerName = strtolower($player->getName());
		$data = (array)$this->data->get($playerName, []);
		return array_keys($data);
	}

	public function getHomesCount(Player $player) : int{
		$playerName = strtolower($player->getName());
		$data = (array)$this->data->get($playerName, []);
		return count($data);
	}

	public function getMaxHomePoints(Player $player) : int{
		foreach($this->permissions as $permission => $count){
			if($player->hasPermission($permission)){
				return $count;
			}
		}
		return $this->permissions["default"];
	}

	public function canIncreaseTheLimit(Player $player) : bool{
		return $this->getHomesCount($player) < max($this->permissions);
	}

	public function onCommand(CommandSender $player, Command $command, $commandLabel, array $args){
		if(!$player instanceof Player){
			$player->sendMessage(MishaShulman::PREFIX . "Домы и варпы можно установить только в игре.");
			return true;
		}
		if(($commandName = $command->getName()) === "homelist"){
			$homes = $this->getHomesList($player);
			if(count($homes) > 0){
				$player->sendMessage("§l§a▷§r §fВаши точки домов§7:");
				$player->sendMessage(" §7• §e§l". implode("§r\n §7• §e§l", $homes));
			}else{
				$player->sendMessage(MishaShulman::PREFIX . "§fУ вас нет §a§lдомов§r§7. §fДля установки введите §b§l/sethome §7(имя дома)§r");
			}
			return true;
		}elseif($commandName === "warps"){
            $player->sendMessage("§8§l(§eПомощь по варпам§8) §l§7▷§r");
            foreach($this->warps as $warp => $coords){
                $player->sendMessage("§7• §a$warp §7- §fдля телепортации используйте §a/$warp");
            }
            return true;
        }elseif($commandName === "pvp" or $commandName === "shop" or $commandName === "duel" or $commandName === "obmennik" or $commandName === "char" or $commandName === "quest" or $commandName === "cases" or $commandName === "mine") {
            $player->teleport(new Vector3($this->warps[$commandName][0], $this->warps[$commandName][1], $this->warps[$commandName][2]));
            $player->sendMessage("§8§l(§eВарпы§8) §l§7▷§r §fВы успешно §a§lтелепортированы§r §fна варп §b§l$commandName");
            return true;
        }
		if(!isset($args[0])){
			$player->sendMessage(MishaShulman::PREFIX . "§fФормат использования: §a§l/". $commandLabel ." §7(имя дома)§r");
			if($commandName !== "sethome"){
				$player->sendMessage("§l§7▷§r §fЧтобы §a§lпосмотреть§r §fваши дома§7, §fвведите §b§l/homelist§r");
			}
			return true;
		}
		$point = array_shift($args);
		if($commandName == "sethome"){
			if($this->getHomesCount($player) >= ($maxPoints = $this->getMaxHomePoints($player))){
				$toValid = function() use ($maxPoints) {
					$str = ["дома", "домов", "домов"];
					$cases = [2, 0, 1, 1, 1, 2];
					return $str[($maxPoints % 100 > 4 and $maxPoints % 100 < 20) ? 2 : $cases[min($maxPoints % 10, 5)]];
				};
				$player->sendMessage(MishaShulman::PREFIX . "§fВы можете установить не больше §a§l". $maxPoints ." §b§l". $toValid() ."§r");
				if($this->canIncreaseTheLimit($player)){
					$player->sendMessage("§l§7▷§r §fЧтобы увеличить лимит§7, купите §a§lпривилегию§r §fна сайте §e". MishaShulman::AUTODONATE_SITE);
				}
				$pk = new PlaySoundPacket();
				$pk->x = $player->x;
				$pk->y = $player->y;
				$pk->z = $player->z;
				$pk->soundName = "note.hat";
				$pk->volume = $pk->pitch = 1.0;
				$player->dataPacket($pk);
				return true;
			}
			$result = $this->createHomePoint($player, $point);
			$player->sendMessage(MishaShulman::PREFIX . "§fВы §a§lуспешно§r " . ($result === MishaShulman::POINT_CREATED ? "§fсоздали" : "§fобновили") . " §fдом §b§l". $point .". §r\n§l§7▷§r §fКоординаты§7: §a§l" . $player->getFloorX() . ", " . $player->getFloorY() . ", " . $player->getFloorZ());
		}elseif($commandName == "delhome"){
			if($this->removeHomePoint($player, $point)){
				$player->sendMessage(MishaShulman::PREFIX ."§a§lУдаление§8...§r");
				$player->sendMessage(MishaShulman::PREFIX . "§fДом с именем §c§l". $point ."§r §fудалён§7!");
			}else{
				$player->sendMessage(MishaShulman::PREFIX . "§fУ Вас нет дома с именем §b§l". $point ."§r§7. §fДля установки введите §e§l/sethome §7(имя дома)§r");
			}
		}elseif($commandName == "home"){
			$homeLocation = $this->getHomePoint($player, $point);
			if($homeLocation instanceof Location){
				if($homeLocation->level === null){
					$player->sendMessage(MishaShulman::PREFIX . "§fЭтот дом §cнедоступен §fдля §aтелепортации§7.");
					return true;
				}
				$player->sendMessage(MishaShulman::PREFIX . "§aТелепортация домой§8...§r");
				$player->teleport($homeLocation);
			}else{
				$player->sendMessage(MishaShulman::PREFIX . "§fУ Вас нет дома с именем §b§l". $point ."§r§7. §fДля установки введите §e§l/sethome §7(имя дома)§r");
			}
		}
	}
}

  • Плагин писал Тимур меметов для uGame, кастомные хомы, варпы, Хорошая настройка для каждой привелегии!

HomeSystem_CODE.rar (3,4 КБ)

Если название HomeSystem, причем тут Варпы?

ну хз

Варп в бонус

переписал команды, ибо дохуя ненужного


1. * > введите или вставьте сюда код

MishaShulman