Added ChestComponent

Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-14 03:36:41 -04:00
parent d5a144f377
commit ca27591485
5 changed files with 105 additions and 23 deletions

View File

@ -64,7 +64,12 @@ class SimpleTeam implements Team {
*/
function getName()
{
$this->name;
return $this->name;
}
function getDisplayName()
{
return $this->getColor() . $this->getName();
}
/**
@ -72,7 +77,8 @@ class SimpleTeam implements Team {
*/
function getColor()
{
$this->color;
return $this->color;
}
}
}

View File

@ -11,6 +11,7 @@ namespace mineplex\plugin\gameengine\game\components\team;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\util\UtilArray;
use pocketmine\item\LeatherTunic;
use pocketmine\Player;
use InvalidArgumentException;
@ -36,6 +37,7 @@ class SimpleTeamManager implements TeamManager {
function addTeam(Team $team)
{
print "adding team: " . $team->getDisplayName() ."\n";
$this->teams[$team->getName()] = $team;
}
@ -91,5 +93,4 @@ class SimpleTeamManager implements TeamManager {
$team->addPlayer_forUseByManagerOnly($player);
}
}

View File

@ -8,26 +8,10 @@
namespace mineplex\plugin\gameengine\game\components\team;
use pocketmine\Player;
interface Team {
function addPlayer_forUseByManagerOnly(Player $player);
function removePlayer_forUseByManagerOnly(Player $player);
/**
* @return Player[]
*/
function getPlayers();
/**
* @param Player $player
* @return bool
*/
function hasPlayer(Player $player);
/**
* @return string
*/
@ -36,6 +20,9 @@ interface Team {
/**
* @return string
*/
function getDisplayName();
function getColor();
}
}

View File

@ -43,12 +43,18 @@ class TeamDealer implements Listener {
function deal()
{
$teams = array_values($this->teamManager->getTeams());
$counter = 0;
foreach ($this->arena->getPlayers() as $player)
{
Server::getInstance()->broadcastMessage($counter % count($teams));
$this->teamManager->setPlayersTeam($player, $teams[$counter % count($teams)]);
$counter++;
Server::getInstance()->broadcastMessage("counter: " . ($counter));
Server::getInstance()->broadcastMessage("count: " . count($teams));
Server::getInstance()->broadcastMessage("total: " . ($counter % count($teams)));
$this->teamManager->setPlayersTeam($player, $teams[$counter % count($teams)]);
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/14/2015
* Time: 3:26 AM
*/
namespace mineplex\plugin\gameengine\game\games\sg;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class ChestComponent implements Listener {
private $arena;
private $worldComponent;
//You can put what you want in the constructor, but for chests this is all you should need.
/**
* @param Arena $arena
* @param WorldComponent $worldComponent
*/
function __construct(Arena $arena, WorldComponent $worldComponent)
{
$this->arena = $arena;
$this->worldComponent = $worldComponent;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
//Don't to game start stuff here cause there might be other components not enabled yet
}
function onStart(ArenaStartEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
//Do stuff on Game start if you want
}
function onLoad(WorldLoadSuccessEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
//Called after the world is loaded
}
function onStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
//Change this to what ever state you want
if ($event->getToGameState() == GameState::GAME)
{
//Do this when the state becomes GAME
}
elseif ($event->getFromGameState() == GameState::GAME)
{
//Do this when the state is no longer GAME
}
}
function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
//Do end of game stuff if you need to
}
}