Fixing/adding some things.
Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
parent
73ffc97cc9
commit
00b5c6f3d4
@ -1,17 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* User: TheMineBench
|
||||
* Date: 7/1/2015
|
||||
* Time: 1:25 PM
|
||||
*/
|
||||
|
||||
$array = array('1','2','3','4','5');
|
||||
|
||||
foreach ($array as $key => $moo)
|
||||
function myfunction($a,$b)
|
||||
{
|
||||
if ($moo == '2')
|
||||
unset ($array[$key]);
|
||||
if ($a===$b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ($a>$b)?1:-1;
|
||||
}
|
||||
|
||||
print_r($array);
|
||||
$a1=array(new stdClass(),"b"=>"green","c"=>"blue");
|
||||
$a2=array("a"=>"blue","b"=>"black","e"=>"blue");
|
||||
|
||||
$result=array_udiff($a1,$a2,"myfunction");
|
||||
print_r($result);
|
@ -48,9 +48,6 @@ class GameStateCountdown implements Listener, BenchTask {
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
Server::getInstance()->broadcastMessage("ToGameState:".(string)$event->getToGameState());
|
||||
Server::getInstance()->broadcastMessage("StartGameState: $this->startGameState");
|
||||
|
||||
if ($event->getToGameState() == $this->startGameState)
|
||||
{
|
||||
BenchSchedule::runTaskTimer($this, 1000, 1000);
|
||||
@ -83,7 +80,6 @@ class GameStateCountdown implements Listener, BenchTask {
|
||||
$this->gameStateComponent->setGameState($this->setGameState);
|
||||
$data->end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function popup()
|
||||
|
@ -44,22 +44,97 @@ class GameStateFeatureManager implements Listener {
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
$lastFeatures = $this->features[$event->getFromGameState()];
|
||||
$theseFeatures = $this->features[$event->getToGameState()];
|
||||
/** @var Feature[] $lastFeatures */
|
||||
|
||||
$toEnable = array_diff($theseFeatures, $lastFeatures);
|
||||
$toDisable = array_diff($lastFeatures, $theseFeatures);
|
||||
if (isset($this->features[$event->getFromGameState()]) || array_key_exists($event->getFromGameState(), $this->features))
|
||||
$lastFeatures = $this->features[$event->getFromGameState()];
|
||||
else
|
||||
$lastFeatures = [];
|
||||
|
||||
|
||||
/** @var Feature[] $theseFeatures */
|
||||
|
||||
if (isset($this->features[$event->getToGameState()]) || array_key_exists($event->getToGameState(), $this->features))
|
||||
$theseFeatures = $this->features[$event->getToGameState()];
|
||||
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) {
|
||||
//$feature->
|
||||
if (!$feature->isEnabled())
|
||||
$feature->enable();
|
||||
}
|
||||
|
||||
foreach ($toDisable as $feature) {
|
||||
if ($feature->isEnabled())
|
||||
$feature->disable();
|
||||
}
|
||||
}
|
||||
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
/** @var Feature[] $iterator */
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features));
|
||||
|
||||
foreach ($iterator as $feature) {
|
||||
if ($feature->isEnabled())
|
||||
$feature->disable();
|
||||
}
|
||||
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
function comp($a,$b)
|
||||
{
|
||||
if ($a===$b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ($a>$b)?1:-1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,15 +35,18 @@ class NoBlockBreak implements Feature, Listener {
|
||||
|
||||
public function enable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Enabled!");
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:20 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\bench\game\components\feature\features;
|
||||
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\game\components\feature\Feature;
|
||||
use pocketmine\entity\Effect;
|
||||
use pocketmine\event\block\BlockBreakEvent;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class NoMovement implements Feature, Listener {
|
||||
|
||||
private $arena;
|
||||
private $enabled = false;
|
||||
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
}
|
||||
|
||||
public function onBlockBreak(BlockBreakEvent $event)
|
||||
{
|
||||
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
$event->setCancelled(true);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
}
|
@ -37,12 +37,16 @@ class GameStateComponent implements Listener {
|
||||
$this->setGameState(GameState::LOBBY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @priority LOW
|
||||
* @param ArenaEndEvent $event
|
||||
*/
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
HandlerList::unregisterAll($this);
|
||||
$this->setGameState(GameState::RESTARTING);
|
||||
$this->localSetState(GameState::RESTARTING);
|
||||
}
|
||||
|
||||
|
||||
@ -64,13 +68,19 @@ class GameStateComponent implements Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->localSetState($gameState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function localSetState($gameState)
|
||||
{
|
||||
|
||||
$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()
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* User: TheMineBench
|
||||
* Date: 6/30/2015
|
||||
* Time: 9:18 PM
|
||||
*/
|
||||
@ -9,11 +9,13 @@ namespace mineplex\plugin\bench\game\games\pvp;
|
||||
|
||||
use mineplex\plugin\bench\game\components\countdown\GameStateCountdown;
|
||||
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 pocketmine\event\Listener;
|
||||
use mineplex\plugin\bench\game\Game;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\game\components\feature\Feature;
|
||||
|
||||
class Pvp implements Game, Listener {
|
||||
|
||||
@ -21,16 +23,24 @@ class Pvp implements Game, Listener {
|
||||
{
|
||||
$gameStateComponent = new GameStateComponent($arena);
|
||||
|
||||
array(
|
||||
$noBlockBreak = new NoBlockBreak($arena);
|
||||
|
||||
/** @var Feature[][] $features */
|
||||
$features = array(
|
||||
GameState::LOBBY => array($noBlockBreak),
|
||||
GameState::PRE_GAME => array($noBlockBreak),
|
||||
GameState::POST_GAME => array($noBlockBreak),
|
||||
);
|
||||
|
||||
new GameStateFeatureManager($arena, $features);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
|
||||
|
||||
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::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, 30, GameState::GAME, GameState::POST_GAME);
|
||||
|
||||
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
|
||||
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user