Working on games...

This commit is contained in:
Ad5001 2016-07-31 13:25:30 +03:00
parent ab17e5be2a
commit fb22b22bd3
5 changed files with 25 additions and 2 deletions

3
.gitignore vendored
View file

@ -45,3 +45,6 @@ $RECYCLE.BIN/
Network Trash Folder Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
# VS Manager files:
*.vscode

10
games/Example.php Normal file
View file

@ -0,0 +1,10 @@
<?php
use Ad5001\GameManager\Game;
use pocketmine\Player;
class Example extends Game {
public function onGameStart() {
$this->getLogger()->info("Game");
}
}

View file

@ -61,6 +61,9 @@ abstract class Game {
public function onQuit(Player $player) {} public function onQuit(Player $player) {}
public function onInteract(\pocketmine\event\player\PlayerInteract $event) {}
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {} public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {}

View file

@ -22,7 +22,7 @@ class GameManager {
public function __construct(Main $main) { public function __construct(Main $main) {
$this->main = $main; $this->main = $main;
$this->server = $main->getServer(); $this->server = $main->getServer();
$files = array_diff(scandir($this->getDataFolder() . "/games"), [".", ".."]); $files = array_diff(scandir($main->getDataFolder() . "games"), [".", ".."]);
$this->games = []; $this->games = [];
$this->levels = []; $this->levels = [];
$this->startedgames = []; $this->startedgames = [];

View file

@ -6,6 +6,7 @@ use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginBase;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\level\Level;
use pocketmine\Player; use pocketmine\Player;
use Ad5001\GameManager\GameManager; use Ad5001\GameManager\GameManager;
@ -20,7 +21,13 @@ class Main extends PluginBase implements Listener {
$this->reloadConfig(); $this->reloadConfig();
$this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getPluginManager()->registerEvents($this, $this);
@mkdir($this->getServer()->getFilePath() . "worldsBackups/"); @mkdir($this->getServer()->getFilePath() . "worldsBackups/");
@mkdir($this->getDataFolder() . "games");
$this->manager = new GameManager($this); $this->manager = new GameManager($this);
foreach(array_diff_key($this->getConfig()->getAll(), ["Game1" => "", "Game2" => "", "InGame3" => "", "InGame4" => "", "GameWait3" => "", "GameWait4" => ""]) as $worldname => $gamename) {
if($this->getServer()->getLevelByName($worldname) instanceof Level) {
$this->manager->registerLevel($this->getServer()->getLevelByName($worldname), $gamename);
}
}
} }
@ -32,7 +39,7 @@ class Main extends PluginBase implements Listener {
$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($name == $lvl) {
if($this->gameManager->getLevels()[$lvl->getName()]->isStarted()) { if($this->manager->getLevels()[$lvl->getName()]->isStarted()) {
$event->getPlayer()->teleport($lvl->getDefaultSpawn()); $event->getPlayer()->teleport($lvl->getDefaultSpawn());
$event->getPlayer()->setGamemode(3); $event->getPlayer()->setGamemode(3);
} else { } else {