From e768a0f6b455bc84e537a4bd29cc21358053ccc8 Mon Sep 17 00:00:00 2001 From: xpyctum Date: Sun, 20 Dec 2015 00:57:05 +0500 Subject: [PATCH] Ooops... use import from api 2.0.0 :) --- src/SignStatus/SignStatus.php | 50 ++++++++++++++++++----------------- src/SignStatus/Task.php | 9 +++---- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/SignStatus/SignStatus.php b/src/SignStatus/SignStatus.php index 8b565b8..5485464 100644 --- a/src/SignStatus/SignStatus.php +++ b/src/SignStatus/SignStatus.php @@ -7,7 +7,6 @@ use pocketmine\item\Item; use pocketmine\plugin\PluginBase; use pocketmine\tile\Sign; -use pocketmine\tile\Tile; use pocketmine\utils\Config; use pocketmine\utils\TextFormat as F; @@ -24,8 +23,9 @@ ─███──█──────█───█──█──█──█─█─█───█ ██─██─█──────█───████──█──███─█───█ */ -//TODO: Make configurable format of sign -class SignStatus extends PluginBase implements Listener{ + +class SignStatus extends PluginBase implements Listener +{ /** @var Config sign */ public $sign; @@ -39,11 +39,11 @@ class SignStatus extends PluginBase implements Listener{ /** @var Config config */ public $format; - /** @var string */ + /** @var string */ public $prefix = "§4[§2SignStatus§4]§6 "; public function onEnable(){ - if(!is_dir($this->getDataFolder())){ + if (!is_dir($this->getDataFolder())) { @mkdir($this->getDataFolder()); //Use default, not PM. } @@ -53,23 +53,25 @@ public function onEnable(){ $this->saveResource("config.yml"); $this->saveResource("format.yml"); - $this->sign = new Config($this->getDataFolder()."sign.yml", Config::YAML); //FIXED ! - $this->translation = new Config($this->getDataFolder()."translations.yml",Config::YAML); - $this->config = new Config($this->getDataFolder()."config.yml",Config::YAML); - $this->format = new Config($this->getDataFolder()."format.yml",Config::YAML); + $this->sign = new Config($this->getDataFolder() . "sign.yml", Config::YAML); //FIXED ! + $this->translation = new Config($this->getDataFolder() . "translations.yml", Config::YAML); + $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML); + $this->format = new Config($this->getDataFolder() . "format.yml", Config::YAML); $this->getServer()->getPluginManager()->registerEvents($this, $this); $time = $this->config->get("time"); - if(!(is_numeric($time))){ + if (!(is_numeric($time))) { $time = 20; - $this->getLogger()->alert("Can't read time for update sign! Please, check your config file! Default: ".F::AQUA." 1 ".F::WHITE." second"); - }else{ $time = $time * 20; } + $this->getLogger()->alert("Can't read time for update sign! Please, check your config file! Default: " . F::AQUA . " 1 " . F::WHITE . " second"); + } else { + $time = $time * 20; + } $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), $time); - $this->getLogger()->notice(F::GREEN."SignStatus loaded"); + $this->getLogger()->notice(F::GREEN . "SignStatus loaded"); } public function onDisable(){ - $this->getLogger()->notice(F::RED."SignStatus disabled"); + $this->getLogger()->notice(F::RED . "SignStatus disabled"); } @@ -78,8 +80,8 @@ public function onDisable(){ */ public function onSignChange(SignChangeEvent $event){ $player = $event->getPlayer(); - if(strtolower(trim($event->getLine(0))) == "status" || strtolower(trim($event->getLine(0))) == "[status]"){ - if($player->hasPermission("signstatus") or $player->hasPermission("signstatus.create")){ + if (strtolower(trim($event->getLine(0))) == "status" || strtolower(trim($event->getLine(0))) == "[status]") { + if ($player->hasPermission("signstatus") or $player->hasPermission("signstatus.create")) { $tps = $this->getServer()->getTicksPerSecond(); $p = count($this->getServer()->getOnlinePlayers()); $level = $event->getBlock()->getLevel()->getName(); @@ -88,18 +90,18 @@ public function onSignChange(SignChangeEvent $event){ $format = $this->format->getAll(); for ($x = 0; $x <= 3; $x++) { - $v = $format["format"][$x+1]; + $v = $format["format"][$x + 1]; $v = str_replace("{ONLINE}", $p, $v); $v = str_replace("{MAX_ONLINE}", $full, $v); $v = str_replace("{WORLD_NAME}", $level, $v); $v = str_replace("{TPS}", $tps, $v); $v = str_replace("{SERVER_LOAD}", $load, $v); - $event->setLine($x,$v); + $event->setLine($x, $v); } //$event->setText(F::GREEN."[STATUS]",F::YELLOW."TPS: [$tps]",F::AQUA."ONLINE: ".F::GREEN.$p.F::WHITE."/".F::RED.$full.",".F::GOLD."******"); - $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_created")); - }else{ - $player->sendMessage($this->prefix.$this->translation->get("sign_no_perms")); + $event->getPlayer()->sendMessage($this->prefix . $this->translation->get("sign_created")); + } else { + $player->sendMessage($this->prefix . $this->translation->get("sign_no_perms")); $event->setCancelled(); } } @@ -111,10 +113,10 @@ public function onSignChange(SignChangeEvent $event){ public function onPlayerBreakBlock(BlockBreakEvent $event){ if ($event->getBlock()->getID() == Item::SIGN || $event->getBlock()->getID() == Item::WALL_SIGN || $event->getBlock()->getID() == Item::SIGN_POST) { $signt = $event->getBlock(); - if (($tile = $signt->getLevel()->getTile($signt))){ - if($tile instanceof Sign) { + if (($tile = $signt->getLevel()->getTile($signt))) { + if ($tile instanceof Sign) { if ($event->getBlock()->getX() == $this->sign->getNested("sign.x") && $event->getBlock()->getY() == $this->sign->getNested("sign.y") && $event->getBlock()->getZ() == $this->sign->getNested("sign.z")) { - if($tile->getText()[0] == strtolower($this->format->getAll()["format"][1])) { + if ($tile->getText()[0] == strtolower($this->format->getAll()["format"][1])) { if ($event->getPlayer()->hasPermission("signstatus.break")) { $event->getPlayer()->sendMessage($this->prefix . $this->translation->get("sign_destroyed")); } else { diff --git a/src/SignStatus/Task.php b/src/SignStatus/Task.php index 5519c87..49c4a5b 100644 --- a/src/SignStatus/Task.php +++ b/src/SignStatus/Task.php @@ -2,18 +2,15 @@ namespace SignStatus; -use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\String; use pocketmine\scheduler\PluginTask; use pocketmine\tile\Sign; -class Task extends PluginTask -{ +class Task extends PluginTask{ private $plugin; private $countable; - public function __construct(SignStatus $plugin) - { + public function __construct(SignStatus $plugin){ parent::__construct($plugin); $this->plugin = $plugin; $this->countable = 0; @@ -41,7 +38,7 @@ public function onRun($currentTick){ $v = str_replace("{SERVER_LOAD}", $load, $v); $index[$x] = $v; } - $tile->setText($index[0],$index[1],$index[2],$index[3]); + $tile->setText($index[0], $index[1], $index[2], $index[3]); } } }