GameManager/src/Ad5001/GameManager/Game.php

104 lines
2 KiB
PHP
Raw Normal View History

2016-07-28 06:39:24 +00:00
<?php
namespace Ad5001\GameManager;
use pocketmine\Server;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\utils\Config;
use Ad5001\GameManager\Main;
abstract class Game {
protected $name;
protected $level;
2016-07-31 07:27:54 +00:00
protected $server;
2016-07-28 06:39:24 +00:00
public function __construct(string $name, Level $level) {
$this->server = $level->getServer();
$this->level = $level;
$this->name = $name;
$this->main = $this->server->getPlugin("GameManager");
2016-07-31 07:27:54 +00:00
$this->gm = $this->main->getGameManager();
2016-07-28 07:31:52 +00:00
$this->main->backup($level);
2016-07-28 06:39:24 +00:00
}
public function getPlugin() {
return $this->main;
}
public function getLevel() {
return $this->main;
}
2016-07-31 07:27:54 +00:00
public function isStarted() {
return isset($this->gm->getStartedGames()[$this->level->getName()]);
2016-07-28 06:39:24 +00:00
}
public function onGameStart();
2016-07-28 07:31:52 +00:00
public function onGameStop();
public function stopGame() {
$this->main->getGameManager()->reloadLevel($this->level);
return true;
}
2016-07-28 06:39:24 +00:00
public function onJoin(Player $player) {}
public function onQuit(Player $player) {}
2016-07-31 10:25:30 +00:00
public function onInteract(\pocketmine\event\player\PlayerInteract $event) {}
2016-07-31 09:17:15 +00:00
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
2016-07-28 06:39:24 +00:00
2016-07-31 09:17:15 +00:00
public function onBlockPlace(\pocketmine\event\entity\EntityDamageEvent $event) {}
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {}
2016-07-28 06:39:24 +00:00
public function getConfig() {
return new Config($this->main->getDataFolder() . "games/$this->name");
}
public function saveDefaultConfig() {
2016-07-31 09:17:15 +00:00
file_put_contents($this->main->getDataFolder() . "games/$this->name", "");
2016-07-28 06:39:24 +00:00
}
public function getName() : string;
public function getMinPlayers() : int;
public function getMaxPlayers() : int;
public function useEvent(\pocketmine\event\Event $event) : bool;
2016-07-28 07:31:52 +00:00
public function getDataFolder() {
return $this->main->getDataFolder() . "games/$this->name";
}
2016-07-28 06:39:24 +00:00
}