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() {
$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";

View file

@ -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 !");
}

View file

@ -130,7 +130,7 @@ class GameManager {
$this->copydir($Entry, $target . '/' . $entry);
continue;
}
copy($target . '/' . $entry, $Entry);
@copy($Entry, $target . '/' . $entry);
}
$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]:");
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());
}
}
}

View file

@ -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]) {*/