GameManager/src/Ad5001/GameManager/tasks/SignReloadTask.php

70 lines
4.5 KiB
PHP
Raw Normal View History

2016-07-31 07:27:54 +00:00
<?php
2016-07-31 19:46:09 +00:00
namespace Ad5001\GameManager\tasks;
2016-07-31 07:27:54 +00:00
use pocketmine\scheduler\PluginTask;
use pocketmine\Server;
use pocketmine\Player;
use Ad5001\GameManager\GameManager;
use Ad5001\GameManager\Main;
class SignReloadTask extends PluginTask {
protected $manager;
public function __construct(Main $main) {
parent::__construct($main);
$this->main = $main;
$this->server = $main->getServer();
$this->cfg = $main->getConfig();
$this->gameManager = $main->getGameManager();
}
public function onRun($tick) {
2016-07-31 19:46:09 +00:00
// echo "Running...";
2016-07-31 07:27:54 +00:00
foreach($this->server->getLevels() as $level) {
foreach($level->getTiles() as $t) {
if($t instanceof \pocketmine\tile\Sign) {
2016-08-01 10:29:14 +00:00
// echo "Sign.";
2016-07-31 07:27:54 +00:00
foreach($this->gameManager->getLevels() as $name => $class) {
// echo PHP_EOL . strtolower($t->getText()[0]) . " == " . strtolower("[GAME]") . " and " . strtolower($class->getLevel()->getName()) . " == " . strtolower($t->getText()[1]);
if(strtolower($t->getText()[0]) == strtolower("[GAME]") and strtolower($class->getLevel()->getName()) == strtolower($t->getText()[1])) {
// echo "Found\n";
2016-07-31 09:17:15 +00:00
$texts = $t->getText();
$texts[0] = str_ireplace("{players}", count($this->main->getInGamePlayers($class->getLevel())), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), $this->cfg->get("Game1")))));
$texts[1] = str_ireplace("{players}", count($this->main->getInGamePlayers($class->getLevel())), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), $this->cfg->get("Game2")))));
$texts[2] = str_ireplace("{players}", count($this->main->getInGamePlayers($class->getLevel())), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), $this->cfg->get("GameWait3")))));
$texts[3] = str_ireplace("{players}", count($this->main->getInGamePlayers($class->getLevel())), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), $this->cfg->get("GameWait4")))));
2016-07-31 09:17:15 +00:00
$t->setText($texts[0], $texts[1], $texts[2], $texts[3]);
}
2016-08-03 15:44:52 +00:00
/*if(str_ireplace("{game}", $class->getName(), $this->cfg->get("Game1")) == $t->getText()[0]) {*/
2016-07-31 07:27:54 +00:00
$lvlex = explode("{level}", $this->cfg->get("Game2"));
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
$lvl = str_ireplace($lvlex[1], "", $lvl);
2016-08-03 17:02:12 +00:00
$lvl = $this->main->getServer()->getLevelByName($lvl);
// $this->main->getLogger()->info($name . " == " . $lvl . " . Game: " . $t->getText()[0]);
2016-07-31 07:27:54 +00:00
if($name == $lvl) {
2016-08-03 17:02:12 +00:00
if($this->gameManager->getLevels()[$lvl->getName()]->isStarted()) {
2016-07-31 07:27:54 +00:00
$l3 = str_ireplace("{players}", count($lvl->getPlayers()), $this->cfg->get("InGame3"));
$l3 = str_ireplace("{max}", $class->getMaxPlayers(), $l3);
$l4 = str_ireplace("{players}", count($lvl->getPlayers()), $this->cfg->get("InGame4"));
$l4 = str_ireplace("{max}", $class->getMaxPlayers(), $l4);
$t->setText($t->getText()[0], $t->getText()[1], $l3, $t4);
} else {
$l3 = str_ireplace("{players}", count($lvl->getPlayers()), $this->cfg->get("GameWait3"));
$l3 = str_ireplace("{max}", $class->getMaxPlayers(), $l3);
$l4 = str_ireplace("{players}", count($lvl->getPlayers()), $this->cfg->get("GameWait4"));
$l4 = str_ireplace("{max}", $class->getMaxPlayers(), $l4);
$t->setText($t->getText()[0], $t->getText()[1], $l3, $t4);
}
}
2016-08-03 15:44:52 +00:00
// }
2016-07-31 07:27:54 +00:00
}
}
}
}
}
}