LobbyComponent.php added
Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
parent
bde58fcad9
commit
b8b12d7f17
@ -32,7 +32,7 @@ class Main extends PluginBase implements Listener
|
||||
public function onLogin(PlayerLoginEvent $event)
|
||||
{
|
||||
if ($this->arena->canJoin($event->getPlayer()))
|
||||
retun;
|
||||
return;
|
||||
|
||||
$event->setKickMessage("Unable to join game!");
|
||||
$event->setCancelled();
|
||||
|
@ -61,23 +61,20 @@ class GameStateFeatureManager implements Listener {
|
||||
else
|
||||
$theseFeatures = [];
|
||||
|
||||
|
||||
|
||||
/** @var Feature[] $toEnable */
|
||||
$toEnable = array_udiff($theseFeatures, $lastFeatures, array($this, 'comp'));
|
||||
|
||||
/** @var Feature[] $toDisable */
|
||||
$toDisable = array_udiff($lastFeatures, $theseFeatures, array($this, 'comp'));
|
||||
|
||||
foreach ($toEnable as $feature) {
|
||||
if (!$feature->isEnabled())
|
||||
$feature->enable();
|
||||
}
|
||||
|
||||
foreach ($toDisable as $feature) {
|
||||
if ($feature->isEnabled())
|
||||
$feature->disable();
|
||||
}
|
||||
foreach ($toEnable as $feature) {
|
||||
if (!$feature->isEnabled())
|
||||
$feature->enable();
|
||||
}
|
||||
}
|
||||
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
|
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/4/2015
|
||||
* Time: 11:10 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\game\components\lobby;
|
||||
|
||||
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\bench\game\components\feature\Feature;
|
||||
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\bench\game\components\gamestate\GameState;
|
||||
use pocketmine\event\block\BlockBreakEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityShootBowEvent;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\inventory\InventoryPickupItemEvent;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\player\PlayerDropItemEvent;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class LobbyComponent implements Listener {
|
||||
|
||||
|
||||
/** @var Arena */
|
||||
private $arena;
|
||||
|
||||
/** @var String */
|
||||
private $worldName;
|
||||
|
||||
private $duringLobbyGameState;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
* @param Level $world
|
||||
*/
|
||||
public function __construct(Arena $arena, $world = null)
|
||||
{
|
||||
|
||||
if ($world == null)
|
||||
$world = Server::getInstance()->getDefaultLevel();
|
||||
|
||||
$world->setTime(6000);
|
||||
$world->stopTime();
|
||||
|
||||
$this->worldName = $world->getName();
|
||||
|
||||
$this->arena = $arena;
|
||||
$this->duringLobbyGameState = new DuringLobbyGameState($arena);
|
||||
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
}
|
||||
|
||||
public function onBlockBreak(BlockBreakEvent $event)
|
||||
{
|
||||
if ($event->getBlock()->getLevel()->getName() != $this->worldName)
|
||||
return;
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
|
||||
public function gameStateChange(GameStateChangeEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
if ($event->getToGameState() == GameState::LOBBY) {
|
||||
if (!$this->duringLobbyGameState->isEnabled())
|
||||
{
|
||||
$this->duringLobbyGameState->enable();
|
||||
}
|
||||
}
|
||||
elseif ($event->getFromGameState() == GameState::LOBBY)
|
||||
{
|
||||
if ($this->duringLobbyGameState->isEnabled())
|
||||
{
|
||||
$this->duringLobbyGameState->disable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function onGameEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
HandlerList::unregisterAll($this);
|
||||
if ($this->duringLobbyGameState->isEnabled())
|
||||
$this->duringLobbyGameState->disable();
|
||||
}
|
||||
}
|
||||
|
||||
class DuringLobbyGameState implements Feature, Listener {
|
||||
|
||||
private $arena;
|
||||
|
||||
/** @var bool */
|
||||
private $enabled = false;
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
}
|
||||
|
||||
|
||||
function onDamage(EntityDamageEvent $event)
|
||||
{
|
||||
if (!in_array($event->getEntity(), $this->arena->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
function onDrop(PlayerDropItemEvent $event)
|
||||
{
|
||||
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
|
||||
return;
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
function onPickUp(InventoryPickupItemEvent $event)
|
||||
{
|
||||
if (!in_array($event->getInventory()->getHolder(), $this->arena->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
function onBowShoot(EntityShootBowEvent $event)
|
||||
{
|
||||
if (!in_array($event->getEntity(), $this->arena->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
function enable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Enabled!");
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ use mineplex\plugin\bench\game\components\feature\features\NoBlockBreak;
|
||||
use mineplex\plugin\bench\game\components\feature\GameStateFeatureManager;
|
||||
use mineplex\plugin\bench\game\components\gamestate\GameState;
|
||||
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
|
||||
use mineplex\plugin\bench\game\components\lobby\LobbyComponent;
|
||||
use mineplex\plugin\bench\game\Game;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\game\components\feature\Feature;
|
||||
@ -24,16 +25,20 @@ class SurvivalGames implements Game {
|
||||
{
|
||||
$gameStateComponent = new GameStateComponent($arena);
|
||||
|
||||
$noBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
|
||||
$noBlockBreak = new NoBlockBreak($arena);
|
||||
$someBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
|
||||
|
||||
/** @var Feature[][] $features */
|
||||
$features = array(
|
||||
GameState::LOBBY => array($noBlockBreak),
|
||||
GameState::PRE_GAME => array($noBlockBreak),
|
||||
GameState::GAME => array($someBlockBreak),
|
||||
GameState::POST_GAME => array($noBlockBreak)
|
||||
);
|
||||
|
||||
new GameStateFeatureManager($arena, $features);
|
||||
new LobbyComponent($arena);
|
||||
|
||||
//new GameStateFeatureManager($arena, $features);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user