Correcting some problems
This commit is contained in:
parent
b44bda9bf0
commit
af5e2ae3df
2 changed files with 4 additions and 195 deletions
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
namespace Ad5001\GameManager;
|
||||
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\utils\Config;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
use Ad5001\GameManager\Main;
|
||||
|
||||
|
||||
|
||||
abstract class Game {
|
||||
|
||||
|
||||
protected $name;
|
||||
protected $level;
|
||||
protected $server;
|
||||
|
||||
|
||||
public function __construct(string $name, Level $level) {
|
||||
$this->server = $level->getServer();
|
||||
$this->level = $level;
|
||||
$this->name = $name;
|
||||
$this->main = $this->server->getPluginManager()->getPlugin("GameManager");
|
||||
$this->gm = $this->main->getGameManager();
|
||||
$this->gm->backup($level);
|
||||
}
|
||||
|
||||
|
||||
public function getPlugin() {
|
||||
return $this->main;
|
||||
}
|
||||
|
||||
|
||||
public function getLevel() {
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
|
||||
public function isStarted() {
|
||||
return isset($this->gm->getStartedGames()[$this->level->getName()]);
|
||||
}
|
||||
|
||||
|
||||
abstract public function onGameStart();
|
||||
|
||||
|
||||
abstract public function onGameStop();
|
||||
|
||||
|
||||
public function stop() {
|
||||
$this->gm->stopGame($this->level);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function start() {
|
||||
$this->gm->stopGame($this->level);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function onJoin(Player $player) {
|
||||
if($this->getLevel()->getPlayers() >= $this->getMinPlayers() and !$this->isStarted()) {
|
||||
$this->gm->startGame($this->getLevel());
|
||||
}
|
||||
if($this->getLevel()->getPlayers() <= $this->getMaxPlayers() and !$this->isStarted()) {
|
||||
$player->teleport($this->getServer()->getDefaultLevel()->getDefaultSpawn());
|
||||
$player->sendMessage("Too many players already in the game !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onQuit(Player $player) {
|
||||
if($this->getLevel()->getPlayers() <= $this->getMinPlayers()) {
|
||||
$this->gm->stopGame($this->getLevel());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getLogger() {
|
||||
return $this->getPlugin()->getLogger();
|
||||
}
|
||||
|
||||
|
||||
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}
|
||||
|
||||
|
||||
public function onChat(\pocketmine\event\player\PlayerChatEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {}
|
||||
|
||||
|
||||
public function onDeath(\pocketmine\event\player\PlayerDeathEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {}
|
||||
|
||||
|
||||
public function onDrop(\pocketmine\event\player\PlayerDropItemEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {}
|
||||
|
||||
|
||||
public function onMove(\pocketmine\event\player\PlayerMoveEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {}
|
||||
|
||||
|
||||
public function onItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {}
|
||||
|
||||
|
||||
public function onItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {}
|
||||
|
||||
|
||||
public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {}
|
||||
|
||||
|
||||
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {}
|
||||
|
||||
|
||||
public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
|
||||
|
||||
|
||||
public function onBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {}
|
||||
|
||||
|
||||
public function onPlace(\pocketmine\event\block\BlockPlaceEvent $event) {}
|
||||
|
||||
|
||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {}
|
||||
|
||||
|
||||
public function getConfig() {
|
||||
return new Config($this->main->getDataFolder() . "games/$this->name");
|
||||
}
|
||||
|
||||
|
||||
public function saveDefaultConfig() {
|
||||
@mkdir($this->main->getDataFolder() . "games/" . $this->name);
|
||||
file_put_contents($this->main->getDataFolder() . "games/$this->name", "");
|
||||
}
|
||||
|
||||
|
||||
public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd, $label, array $args) {}
|
||||
|
||||
|
||||
|
||||
abstract public function getName() : string;
|
||||
|
||||
|
||||
abstract public function getMinPlayers() : int;
|
||||
|
||||
|
||||
abstract public function getMaxPlayers() : int;
|
||||
|
||||
|
||||
public function getDataFolder() {
|
||||
return $this->main->getDataFolder() . "games/$this->name";
|
||||
}
|
||||
|
||||
|
||||
public function registerCommand(string $cmd, string $desc, string $usage, array $aliases, string $perm = "gamemanager.command.use") {
|
||||
if(!isset($this->main->cmds[$cmd])) {
|
||||
$this->main->cmds[$cmd] = new GameCommand($this->main, $cmd, $desc, $usage, $aliases, $this->gm->getGames()[$this->getName()], $perm);
|
||||
$this->getServer()->getCommandMap()->register($cmd, $this->main->cmds[$cmds]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -25,9 +25,9 @@ class GameManager {
|
|||
$this->levels = [];
|
||||
$this->startedgames = [];
|
||||
foreach ($files as $file) {
|
||||
if(!is_dir($this->main->getDataFolder() . "/games/" . $file)) {
|
||||
require($this->main->getDataFolder() . "/games/" . $file);
|
||||
$classn = $this->main->getClasses(file_get_contents($this->main->getDataFolder() . "/games/" . $file));
|
||||
if(!is_dir($this->main->getDataFolder() . "games/" . $file)) {
|
||||
require($this->main->getDataFolder() . "games/" . $file);
|
||||
$classn = $this->main->getClasses(file_get_contents($this->main->getDataFolder() . "games/" . $file));
|
||||
$this->games[explode("\\", $classn)[count(explode("\\", $classn)) - 1]] = $classn;
|
||||
@mkdir($this->main->getDataFolder() . "games/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]);
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class GameManager {
|
|||
private function copydir($source, $target) {
|
||||
if (is_dir($source)) {
|
||||
@mkdir($target);
|
||||
@mkdir($target . "/region");
|
||||
@mkdir($target . "region");
|
||||
$d = dir($source);
|
||||
while ( FALSE !== ( $entry = $d->read() ) ) {
|
||||
if ($entry == '.' || $entry == '..') {
|
||||
|
|
Loading…
Reference in a new issue