Fixing signs, starting a fix on spec errors, should work now :D

This commit is contained in:
Ad5001 2016-08-05 15:31:34 +03:00
parent 1ead9c7570
commit 859c286585
5 changed files with 60 additions and 30 deletions

View file

@ -11,6 +11,10 @@ class Example extends Game {
public function onGameStop() { public function onGameStop() {
$this->getLogger()->info("Game stoped"); $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 { public function getName() : string {
return "Example"; return "Example";

View file

@ -63,10 +63,10 @@ abstract class Game {
public function onJoin(Player $player) { 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()); $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->teleport($this->getServer()->getDefaultLevel()->getDefaultSpawn());
$player->sendMessage("Too many players already in the game !"); $player->sendMessage("Too many players already in the game !");
} }

View file

@ -130,7 +130,7 @@ class GameManager {
$this->copydir($Entry, $target . '/' . $entry); $this->copydir($Entry, $target . '/' . $entry);
continue; continue;
} }
copy($target . '/' . $entry, $Entry); @copy($Entry, $target . '/' . $entry);
} }
$d->close(); $d->close();

View file

@ -60,24 +60,9 @@ class Main extends PluginBase implements Listener {
$sender->sendMessage("§l§o[§r§lGameManager§o]§r Current levels running $args[0]:"); $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current levels running $args[0]:");
foreach($this->manager->getLevels() as $levelname => $game) { foreach($this->manager->getLevels() as $levelname => $game) {
if(strtolower($game->getName()) == strtolower($args[0])) { if(strtolower($game->getName()) == strtolower($args[0])) {
$p = 0; $p = $this->getInGamePlayers($game->getLevel());
$s = 0; $s = $this->getSpectators($game->getLevel());
foreach($game->getLevel()->getPlayers() as $pl) { $sender->sendMessage("§l§o[§r§lGameManager§o]§r§a " . $levelname . " Is started: " . $game->isStarted() . " Players: " . $p . " Spectators: " . $s);
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));
} }
} }
} }
@ -90,6 +75,38 @@ class Main extends PluginBase implements Listener {
return false; 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) { public function getClasses(string $file) {
$tokens = token_get_all($file); $tokens = token_get_all($file);
@ -132,12 +149,12 @@ public function onInteract(PlayerInteractEvent $event) {
$lvlex = explode("{level}", $this->getConfig()->get("Game2")); $lvlex = explode("{level}", $this->getConfig()->get("Game2"));
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]); $lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
$lvl = str_ireplace($lvlex[1], "", $lvl); $lvl = str_ireplace($lvlex[1], "", $lvl);
if($name == $lvl) { if($class->getLevel()->getName() == $lvl) {
if($this->manager->getLevels()[$lvl->getName()]->isStarted()) { if($this->manager->getLevels()[$lvl]->isStarted()) {
$event->getPlayer()->teleport($lvl->getDefaultSpawn()); $event->getPlayer()->teleport($class->getLevel()->getSafeSpawn());
$event->getPlayer()->setGamemode(3); $event->getPlayer()->setGamemode(3);
} else { } else {
$event->getPlayer()->teleport($lvl->getDefaultSpawn()); $event->getPlayer()->teleport($class->getLevel()->getSafeSpawn());
} }
} }
} }

View file

@ -30,12 +30,14 @@ class SignReloadTask extends PluginTask {
if($t instanceof \pocketmine\tile\Sign) { if($t instanceof \pocketmine\tile\Sign) {
// echo "Sign."; // echo "Sign.";
foreach($this->gameManager->getLevels() as $name => $class) { foreach($this->gameManager->getLevels() as $name => $class) {
// echo $class->getLevel()->getName(); // echo PHP_EOL . strtolower($t->getText()[0]) . " == " . strtolower("[GAME]") . " and " . strtolower($class->getLevel()->getName()) . " == " . strtolower($t->getText()[1]);
if($t->getText()[0] == "[GAME]" and $class->getLevel()->getName() == $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(); $texts = $t->getText();
foreach($texts as $key => $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[$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[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]); $t->setText($texts[0], $texts[1], $texts[2], $texts[3]);
} }
/*if(str_ireplace("{game}", $class->getName(), $this->cfg->get("Game1")) == $t->getText()[0]) {*/ /*if(str_ireplace("{game}", $class->getName(), $this->cfg->get("Game1")) == $t->getText()[0]) {*/