Starting testing...

This commit is contained in:
Ad5001 2016-08-01 13:29:14 +03:00
parent 665426e7cf
commit a550fa1f8d
6 changed files with 36 additions and 11 deletions

View file

@ -1,3 +1,21 @@
---
# This is the default config generated with ImagicalPlugCreator. (C) ImagicalPlugCreator - Ad5001 2016
# Welcome to GameManager config.
# Here you can configure how does game signs looks.
# 1 is line 1, 2 is line 2, 3 is line 3 and 4 is line 4.
# Note that {Game} MUST be included in the first line and {level} in the second one (detection).
Game1: "§l§o[§r§l{Game}§o]"
Game2: "-=<{level}>=-"
# When the game need more players:
GameWait3: "{players}/{max}"
GameWait4: "> > > CLICK TO JOIN < < <"
# When the game is already started:
InGame3: "Game already started"
InGame4: "> > > CLICK TO SPECTATE < < <"
# Now you can choose all worlds game's
# Example:
rougepierre: Example
...

View file

@ -14,6 +14,9 @@ class Example extends Game {
}
public function getName() : string {
return "Example";
}

View file

@ -5,6 +5,7 @@ use pocketmine\Server;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\utils\Config;
use pocketmine\level\Level;
use Ad5001\GameManager\Main;
@ -22,7 +23,7 @@ abstract class Game {
$this->server = $level->getServer();
$this->level = $level;
$this->name = $name;
$this->main = $this->server->getPlugin("GameManager");
$this->main = $this->server->getPluginManager()->getPlugin("GameManager");
$this->gm = $this->main->getGameManager();
$this->gm->backup($level);
}
@ -59,7 +60,7 @@ abstract class Game {
if($this->getLevel()->getPlayers() >= $this->getMinPlayers() and !$this->isStarted()) {
$this->gm->startGame($this->getLevel());
}
if($this->getLevel()->getPlayers() <= $this->getMaxPlayers()) {
if($this->getLevel()->getPlayers() <= $this->getMaxPlayers() and !$this->isStarted()) {
$player->teleport($this->getServer()->getDefaultLevel()->getDefaultSpawn());
}
}

View file

@ -63,7 +63,7 @@ class GameManager {
public function registerLevel(Level $level, string $game) {
if(!array_key_exists($level->getName(), $this->levels)) {
if(isset($this->games[$game])) {
$this->levels[$level->getName()] = new $this->games[$game]($level);
$this->levels[$level->getName()] = new $this->games[$game]($game, $level);
} else {
$this->main->getLogger()->warn("No game found with name $game");
}
@ -88,15 +88,15 @@ class GameManager {
public function restoreBackup(Level $level) {
rrmdir($this->server->getFilePath() . "worlds/{$level->getName()}");
copydir($this->server->getFilePath() . "worldsBackups/{$level->getName()}", $this->server->getFilePath() . "worlds/{$level->getName()}");
$this->rrmdir($this->server->getFilePath() . "worlds/{$level->getName()}");
$this->copydir($this->server->getFilePath() . "worldsBackups/{$level->getName()}", $this->server->getFilePath() . "worlds/{$level->getName()}");
}
public function backup(Level $level) {
rrmdir($this->server->getFilePath() . "worldsBackups/{$level->getName()}");
copydir($this->server->getFilePath() . "worlds/{$level->getName()}", $this->server->getFilePath() . "worldsBackup/{$level->getName()}");
$this->rrmdir($this->server->getFilePath() . "worldsBackups/{$level->getName()}");
$this->copydir($this->server->getFilePath() . "worlds/{$level->getName()}", $this->server->getFilePath() . "worldsBackup/{$level->getName()}");
}

View file

@ -35,11 +35,12 @@ class Main extends PluginBase implements Listener {
public function onInteract(PlayerInteractEvent $event) {
// echo "Interacted";
if($event->getBlock()->getId() == Block::SIGN_POST and $event->getBlock()->getId() == Block::WALL_SIGN) {
echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN;
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
$t = $event->getBlock()->getLevel()->getTile($event->getBlock());
echo "Sign.";
if(str_ireplace("{game}", $class->getName(), $this->getConfig()->get("Game1")) == $t->getText()[0]) {
foreach($this->manager->getLevels() as $class) {
if(str_ireplace("{game}", $class->getName(), $this->getConfig()->get("Game1")) == $t->getText()[0]) {
$lvlex = explode("{level}", $this->getConfig()->get("Game2"));
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
$lvl = str_ireplace($lvlex[1], "", $lvl);
@ -52,6 +53,7 @@ class Main extends PluginBase implements Listener {
$this->gameManager->getLevels()[$lvl->getName()]->onJoin($event->getPlayer());
}
}
}
}
}
}

View file

@ -28,6 +28,7 @@ class SignReloadTask extends PluginTask {
foreach($this->server->getLevels() as $level) {
foreach($level->getTiles() as $t) {
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]) {