Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-05 19:48:35 -04:00
parent 5339b792ac
commit 45146aa75b
2 changed files with 106 additions and 1 deletions

View File

@ -0,0 +1,103 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/5/2015
* Time: 7:41 PM
*/
namespace mineplex\plugin\gameengine\game\components\countdown;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class LobbyCountdown implements Listener, BenchTask {
private $startCount;
private $count;
private $gameStateComponent;
private $arena;
private $startGameState;
private $setGameState;
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $count, $startGameState, $setGameState)
{
$this->arena = $arena;
$this->gameStateComponent = $gameStateComponent;
$this->startCount = $count;
$this->count = $count;
$this->startGameState = $startGameState;
$this->setGameState = $setGameState;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
function checkCountdown()
{
}
public function onGameStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
if ($event->getToGameState() == $this->startGameState)
{
BenchSchedule::runTaskTimer($this, 1000, 1000);
}
else
{
BenchSchedule::cancelTask($this);
$this->count = $this->startCount;
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
}
public function run(BenchTaskData $data)
{
print "Count: $this->count"."\n";
if ($this->count <= 0)
{
$this->gameStateComponent->setGameState($this->setGameState);
$data->end();
}
$this->popup();
$this->count--;
}
public function popup()
{
foreach ($this->arena->getPlayers() as $player)
{
$player->sendPopup("Countdown: $this->count");
}
}
}

View File

@ -128,6 +128,8 @@ class WorldComponent implements Listener
print("Error Loading World: " . $this->gameFolder . "\n"); print("Error Loading World: " . $this->gameFolder . "\n");
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena)); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
$this->arena->endGame();
} }
} }