From 859c2865856477a6116bcea68e3bfdd70569f963 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 5 Aug 2016 15:31:34 +0300 Subject: [PATCH] Fixing signs, starting a fix on spec errors, should work now :D --- games/Example.php | 11 ++++ src/Ad5001/GameManager/Game.php | 4 +- src/Ad5001/GameManager/GameManager.php | 2 +- src/Ad5001/GameManager/Main.php | 61 ++++++++++++------- .../GameManager/tasks/SignReloadTask.php | 12 ++-- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/games/Example.php b/games/Example.php index e641ba7..56f40b3 100644 --- a/games/Example.php +++ b/games/Example.php @@ -11,6 +11,10 @@ class Example extends Game { public function onGameStop() { $this->getLogger()->info("Game stoped"); + foreach($this->getLevel()->getPlayers() as $p) { + $p->setGamemode(0); + $p->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn()); + } } @@ -26,6 +30,13 @@ class Example extends Game { } + public function onPlayerDeath(\pocketmine\event\PlayerDeathEvent $event) { + if(($this->getPlugin()->getInGamePlayers($this->getLevel()) - 1) == 0) { + $this->stop(); + } + } + + public function getName() : string { return "Example"; diff --git a/src/Ad5001/GameManager/Game.php b/src/Ad5001/GameManager/Game.php index 5fbf2ae..86bac75 100644 --- a/src/Ad5001/GameManager/Game.php +++ b/src/Ad5001/GameManager/Game.php @@ -63,10 +63,10 @@ abstract class Game { public function onJoin(Player $player) { - if($this->getLevel()->getPlayers() >= $this->getMinPlayers() and !$this->isStarted()) { + if($this->main->getInGamePlayers($this->getLevel()) >= $this->getMinPlayers() and !$this->isStarted()) { $this->gm->startGame($this->getLevel()); } - if($this->getLevel()->getPlayers() <= $this->getMaxPlayers() and !$this->isStarted()) { + if($this->main->getInGamePlayers($this->getLevel())<= $this->getMaxPlayers() and !$this->isStarted()) { $player->teleport($this->getServer()->getDefaultLevel()->getDefaultSpawn()); $player->sendMessage("Too many players already in the game !"); } diff --git a/src/Ad5001/GameManager/GameManager.php b/src/Ad5001/GameManager/GameManager.php index ab5d43a..6a4d3b0 100644 --- a/src/Ad5001/GameManager/GameManager.php +++ b/src/Ad5001/GameManager/GameManager.php @@ -130,7 +130,7 @@ class GameManager { $this->copydir($Entry, $target . '/' . $entry); continue; } - copy($target . '/' . $entry, $Entry); + @copy($Entry, $target . '/' . $entry); } $d->close(); diff --git a/src/Ad5001/GameManager/Main.php b/src/Ad5001/GameManager/Main.php index d409e36..8ea8bfa 100644 --- a/src/Ad5001/GameManager/Main.php +++ b/src/Ad5001/GameManager/Main.php @@ -60,24 +60,9 @@ class Main extends PluginBase implements Listener { $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current levels running $args[0]:"); foreach($this->manager->getLevels() as $levelname => $game) { if(strtolower($game->getName()) == strtolower($args[0])) { - $p = 0; - $s = 0; - foreach($game->getLevel()->getPlayers() as $pl) { - if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { - if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { - array_push($s, $pl); - } else { - array_push($p, $pl); - } - } else { - if($pl->isSpectator()) { - array_push($s, $pl); - } else { - array_push($p, $pl); - } - } - } - $sender->sendMessage("§l§o[§r§lGameManager§o]§r§a " . $levelname . " Is started: " . $game->isStarted() . " Players: " . count($p) . " Spectators: " . count($s)); + $p = $this->getInGamePlayers($game->getLevel()); + $s = $this->getSpectators($game->getLevel()); + $sender->sendMessage("§l§o[§r§lGameManager§o]§r§a " . $levelname . " Is started: " . $game->isStarted() . " Players: " . $p . " Spectators: " . $s); } } } @@ -90,6 +75,38 @@ class Main extends PluginBase implements Listener { return false; } + public function getInGamePlayers(Level $level) { + $p = 0; + foreach($level->getPlayers() as $pl) { + if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { + if(!$this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { + array_push($p, $pl); + } + } else { + if(!$pl->isSpectator()) { + array_push($p, $pl); + } + } + } + return count($p); + } + + + public function getSpectators(Level $level) { + $s = 0; + foreach($level->getPlayers() as $pl) { + if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { + if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { + array_push($s, $pl); + } + } else { + if($pl->isSpectator()) { + array_push($s, $pl); + } + } + } + } + public function getClasses(string $file) { $tokens = token_get_all($file); @@ -132,12 +149,12 @@ public function onInteract(PlayerInteractEvent $event) { $lvlex = explode("{level}", $this->getConfig()->get("Game2")); $lvl = str_ireplace($lvlex[0], "", $t->getText()[1]); $lvl = str_ireplace($lvlex[1], "", $lvl); - if($name == $lvl) { - if($this->manager->getLevels()[$lvl->getName()]->isStarted()) { - $event->getPlayer()->teleport($lvl->getDefaultSpawn()); + if($class->getLevel()->getName() == $lvl) { + if($this->manager->getLevels()[$lvl]->isStarted()) { + $event->getPlayer()->teleport($class->getLevel()->getSafeSpawn()); $event->getPlayer()->setGamemode(3); } else { - $event->getPlayer()->teleport($lvl->getDefaultSpawn()); + $event->getPlayer()->teleport($class->getLevel()->getSafeSpawn()); } } } diff --git a/src/Ad5001/GameManager/tasks/SignReloadTask.php b/src/Ad5001/GameManager/tasks/SignReloadTask.php index 5f8392e..42eadf7 100644 --- a/src/Ad5001/GameManager/tasks/SignReloadTask.php +++ b/src/Ad5001/GameManager/tasks/SignReloadTask.php @@ -30,12 +30,14 @@ class SignReloadTask extends PluginTask { if($t instanceof \pocketmine\tile\Sign) { // echo "Sign."; foreach($this->gameManager->getLevels() as $name => $class) { - // echo $class->getLevel()->getName(); - if($t->getText()[0] == "[GAME]" and $class->getLevel()->getName() == $t->getText()[1]) { + // 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"; $texts = $t->getText(); - foreach($texts as $key => $text) { - $texts[$key] = str_ireplace("{players}", count($class->getLevel()->getPlayers()), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), $text)))); - } + $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"))))); $t->setText($texts[0], $texts[1], $texts[2], $texts[3]); } /*if(str_ireplace("{game}", $class->getName(), $this->cfg->get("Game1")) == $t->getText()[0]) {*/