More stuff...
Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
parent
88241fa4d5
commit
a240181650
@ -10,30 +10,38 @@ namespace mineplex\plugin\bench\game\components\countdown;
|
|||||||
|
|
||||||
|
|
||||||
use mineplex\plugin\bench\arenas\Arena;
|
use mineplex\plugin\bench\arenas\Arena;
|
||||||
use mineplex\plugin\bench\arenas\events\GameStateChangeEvent;
|
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
||||||
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
|
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
|
||||||
|
use pocketmine\event\HandlerList;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
use pocketmine\scheduler\PluginTask;
|
use pocketmine\scheduler\PluginTask;
|
||||||
|
use pocketmine\Server;
|
||||||
|
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
|
||||||
|
|
||||||
class GameStateCountdown extends PluginTask implements Listener {
|
class GameStateCountdown extends PluginTask implements Listener {
|
||||||
|
|
||||||
private $startCount;
|
private $startCount;
|
||||||
private $count;
|
private $count;
|
||||||
private $gameStateComponent;
|
private $gameStateComponent;
|
||||||
|
private $arena;
|
||||||
|
|
||||||
|
|
||||||
private $startGameState;
|
private $startGameState;
|
||||||
private $endGameState;
|
private $setGameState;
|
||||||
|
|
||||||
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $count, $startGameState, $endGameState)
|
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $count, $startGameState, $setGameState)
|
||||||
{
|
{
|
||||||
parent::__construct($arena->getPlugin());
|
parent::__construct($arena->getPlugin());
|
||||||
|
$this->arena = $arena;
|
||||||
$this->gameStateComponent = $gameStateComponent;
|
$this->gameStateComponent = $gameStateComponent;
|
||||||
|
|
||||||
$this->startCount = $count;
|
$this->startCount = $count;
|
||||||
$this->count = $count;
|
$this->count = $count;
|
||||||
|
|
||||||
$this
|
$this->startGameState = $startGameState;
|
||||||
|
$this->setGameState = $setGameState;
|
||||||
|
|
||||||
|
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onGameStateChange(GameStateChangeEvent $event)
|
public function onGameStateChange(GameStateChangeEvent $event)
|
||||||
@ -41,12 +49,48 @@ class GameStateCountdown extends PluginTask implements Listener {
|
|||||||
if ($event->getArena() !== $this->arena)
|
if ($event->getArena() !== $this->arena)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Server::getInstance()->broadcastMessage("ToGameState:".(string)$event->getToGameState());
|
||||||
|
Server::getInstance()->broadcastMessage("StartGameState: $this->startGameState");
|
||||||
|
|
||||||
|
if ($event->getToGameState() == $this->startGameState)
|
||||||
|
{
|
||||||
|
Server::getInstance()->getScheduler()->scheduleRepeatingTask($this, 20);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->count = $this->startCount;
|
||||||
|
|
||||||
|
Server::getInstance()->getScheduler()->cancelTask($this->getTaskId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function onEnd(ArenaEndEvent $event)
|
||||||
|
{
|
||||||
|
if ($event->getArena() !== $this->arena)
|
||||||
|
return;
|
||||||
|
HandlerList::unregisterAll($this);
|
||||||
|
}
|
||||||
|
|
||||||
public function onRun($currentTick)
|
public function onRun($currentTick)
|
||||||
{
|
{
|
||||||
$this->plugin->getServer()->getPluginManager()->callEvent(new TickEvent($currentTick));
|
print "Count: $this->count"."\n";
|
||||||
|
|
||||||
|
$this->popup();
|
||||||
|
|
||||||
|
$this->count--;
|
||||||
|
|
||||||
|
if ($this->count <= 0)
|
||||||
|
{
|
||||||
|
$this->gameStateComponent->setGameState($this->setGameState);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public function popup()
|
||||||
|
{
|
||||||
|
foreach ($this->arena->getPlayers() as $player)
|
||||||
|
{
|
||||||
|
$player->sendPopup("Countdown: $this->count");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace mineplex\plugin\bench\game\components\gamestate;
|
|||||||
|
|
||||||
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
||||||
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
|
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
|
||||||
use mineplex\plugin\bench\arenas\events\GameStateChangeEvent;
|
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
|
||||||
use mineplex\plugin\bench\arenas\Arena;
|
use mineplex\plugin\bench\arenas\Arena;
|
||||||
use pocketmine\event\HandlerList;
|
use pocketmine\event\HandlerList;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
|
@ -6,13 +6,15 @@
|
|||||||
* Time: 10:49 AM
|
* Time: 10:49 AM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace mineplex\plugin\bench\arenas\events;
|
namespace mineplex\plugin\bench\game\components\gamestate\events;
|
||||||
|
|
||||||
use mineplex\plugin\bench\arenas\ArenaEvent;
|
use mineplex\plugin\bench\arenas\ArenaEvent;
|
||||||
use mineplex\plugin\bench\arenas\Arena;
|
use mineplex\plugin\bench\arenas\Arena;
|
||||||
|
|
||||||
class GameStateChangeEvent extends ArenaEvent {
|
class GameStateChangeEvent extends ArenaEvent {
|
||||||
|
|
||||||
|
public static $handlerList = null;
|
||||||
|
|
||||||
private $fromGameState;
|
private $fromGameState;
|
||||||
private $toGameState;
|
private $toGameState;
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
namespace mineplex\plugin\bench\game\games\pvp;
|
namespace mineplex\plugin\bench\game\games\pvp;
|
||||||
|
|
||||||
|
use mineplex\plugin\bench\game\components\countdown\GameStateCountdown;
|
||||||
|
use mineplex\plugin\bench\game\components\gamestate\GameState;
|
||||||
|
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
use mineplex\plugin\bench\game\Game;
|
use mineplex\plugin\bench\game\Game;
|
||||||
use mineplex\plugin\bench\arenas\Arena;
|
use mineplex\plugin\bench\arenas\Arena;
|
||||||
@ -15,7 +18,15 @@ class Pvp implements Game, Listener {
|
|||||||
|
|
||||||
public function start(Arena $arena)
|
public function start(Arena $arena)
|
||||||
{
|
{
|
||||||
new PvpComponent($arena);
|
$gameStateComponent = new GameStateComponent($arena);
|
||||||
|
|
||||||
|
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
|
||||||
|
|
||||||
|
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
|
||||||
|
|
||||||
|
//new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME);
|
||||||
|
|
||||||
|
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user