Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex
This commit is contained in:
commit
607a94f985
@ -18,6 +18,7 @@ use mineplex\plugin\bench\game\Game;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaCanJoinEvent;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaQuitEvent;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
|
||||
|
||||
class SingleGameArena implements Arena, Listener {
|
||||
//I really have no idea if there is a better way to store players... but this is what I'm using for now.
|
||||
@ -35,6 +36,7 @@ class SingleGameArena implements Arena, Listener {
|
||||
$this->game = $game;
|
||||
$this->plugin = $plugin;
|
||||
$this->getCurrentGame()->start($this);
|
||||
Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this));
|
||||
}
|
||||
|
||||
public function canJoin(Player $player)
|
||||
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 6/30/2015
|
||||
* Time: 10:12 PM
|
||||
*/
|
||||
namespace mineplex\plugin\bench\arenas\events;
|
||||
|
||||
use mineplex\plugin\bench\arenas\ArenaEvent;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
|
||||
class ArenaStartEvent extends ArenaEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
parent::__construct($arena);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 5:52 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\game\components\countdown;
|
||||
|
||||
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\arenas\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\scheduler\PluginTask;
|
||||
|
||||
|
||||
class GameStateCountdown extends PluginTask implements Listener {
|
||||
|
||||
private $startCount;
|
||||
private $count;
|
||||
private $gameStateComponent;
|
||||
|
||||
private $startGameState;
|
||||
private $endGameState;
|
||||
|
||||
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $count, $startGameState, $endGameState)
|
||||
{
|
||||
parent::__construct($arena->getPlugin());
|
||||
$this->gameStateComponent = $gameStateComponent;
|
||||
|
||||
$this->startCount = $count;
|
||||
$this->count = $count;
|
||||
|
||||
$this
|
||||
}
|
||||
|
||||
public function onGameStateChange(GameStateChangeEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function onRun($currentTick)
|
||||
{
|
||||
$this->plugin->getServer()->getPluginManager()->callEvent(new TickEvent($currentTick));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:33 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\game\components\gamestate;
|
||||
|
||||
|
||||
//Yes yes I know this is a horrible way of doing things, I'm just trying to get done fast.
|
||||
class GameState {
|
||||
|
||||
const LOBBY = 1;
|
||||
const PRE_GAME = 2;
|
||||
const GAME = 3;
|
||||
const POST_GAME = 4;
|
||||
const RESTARTING = 5;
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:26 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\game\components\gamestate;
|
||||
|
||||
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
|
||||
use mineplex\plugin\bench\arenas\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Server;
|
||||
|
||||
//require_once __DIR__ . '\GameState.php';
|
||||
|
||||
class GameStateComponent implements Listener {
|
||||
|
||||
private $gameState;
|
||||
private $arena;
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
$this->gameState = GameState::RESTARTING;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
}
|
||||
|
||||
public function onStart(ArenaStartEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
$this->setGameState(GameState::LOBBY);
|
||||
}
|
||||
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
HandlerList::unregisterAll($this);
|
||||
$this->setGameState(GameState::RESTARTING);
|
||||
}
|
||||
|
||||
|
||||
public function setGameState($gameState)
|
||||
{
|
||||
|
||||
if ($gameState < GameState::LOBBY)
|
||||
$gameState = GameState::LOBBY;
|
||||
|
||||
if ($gameState > GameState::RESTARTING)
|
||||
$gameState = GameState::RESTARTING;
|
||||
|
||||
if ($gameState == $this->gameState)
|
||||
return false;
|
||||
|
||||
if ($gameState == GameState::RESTARTING)
|
||||
{
|
||||
$this->arena->endGame();
|
||||
return true;
|
||||
}
|
||||
|
||||
$event = new GameStateChangeEvent($this->arena, $this->gameState, $gameState);
|
||||
|
||||
//Not sure if I should call the event before of after...
|
||||
Server::getInstance()->getPluginManager()->callEvent($event);
|
||||
$this->gameState = $gameState;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getGameState()
|
||||
{
|
||||
return $this->gameState;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//$john = new GameStateComponent();
|
||||
//echo $john->getGameState();
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 1:25 PM
|
||||
*/
|
||||
namespace mineplex\plugin\bench\game\components\gamestate;
|
||||
|
||||
|
||||
print 'hi\n';
|
||||
|
||||
$gameStateComponent = new GameStateComponent();
|
||||
|
||||
echo 'State: '.$gameStateComponent->getGameState();
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:49 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\arenas\events;
|
||||
|
||||
use mineplex\plugin\bench\arenas\ArenaEvent;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
|
||||
class GameStateChangeEvent extends ArenaEvent {
|
||||
|
||||
private $fromGameState;
|
||||
private $toGameState;
|
||||
|
||||
public function __construct(Arena $arena, $fromGameState, $toGameState)
|
||||
{
|
||||
parent::__construct($arena);
|
||||
$this->fromGameState = $fromGameState;
|
||||
$this->toGameState = $toGameState;
|
||||
}
|
||||
|
||||
public function getFromGameState()
|
||||
{
|
||||
return $this->fromGameState;
|
||||
}
|
||||
|
||||
public function getToGameState()
|
||||
{
|
||||
return $this->toGameState;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user