From 00b5c6f3d46ed5a1128d2ef26eefb16bbaf54975 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Sat, 4 Jul 2015 03:01:56 -0400 Subject: [PATCH] Fixing/adding some things. Signed-off-by: Aaron Brock --- Pocket/plugins/Mineplex/src/Test.php | 18 ++-- .../countdown/GameStateCountdown.php | 4 - .../feature/GameStateFeatureManager.php | 87 +++++++++++++++++-- .../feature/features/NoBlockBreak.php | 3 + .../feature/features/NoMovement.php | 63 ++++++++++++++ .../gamestate/GameStateComponent.php | 16 +++- .../plugin/bench/game/games/pvp/Pvp.php | 20 +++-- 7 files changed, 187 insertions(+), 24 deletions(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoMovement.php diff --git a/Pocket/plugins/Mineplex/src/Test.php b/Pocket/plugins/Mineplex/src/Test.php index 1a14d662a..7775713b2 100644 --- a/Pocket/plugins/Mineplex/src/Test.php +++ b/Pocket/plugins/Mineplex/src/Test.php @@ -1,17 +1,23 @@ $moo) +function myfunction($a,$b) { - if ($moo == '2') - unset ($array[$key]); + if ($a===$b) + { + return 0; + } + return ($a>$b)?1:-1; } -print_r($array); \ No newline at end of file +$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); \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/countdown/GameStateCountdown.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/countdown/GameStateCountdown.php index ff0565c7f..3ad507c14 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/countdown/GameStateCountdown.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/countdown/GameStateCountdown.php @@ -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() diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php index 6273e2d69..ac5fd8a68 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php @@ -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); } -} \ No newline at end of file + + function comp($a,$b) + { + if ($a===$b) + { + return 0; + } + return ($a>$b)?1:-1; + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php index e69533750..2d61edcd6 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php @@ -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; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoMovement.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoMovement.php new file mode 100644 index 000000000..ed3a5bf66 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoMovement.php @@ -0,0 +1,63 @@ +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; + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameStateComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameStateComponent.php index 00f9c8036..ea79c9141 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameStateComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameStateComponent.php @@ -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() diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/pvp/Pvp.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/pvp/Pvp.php index 4b1d25002..1b7837765 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/pvp/Pvp.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/pvp/Pvp.php @@ -1,7 +1,7 @@ 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); } } \ No newline at end of file