diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index fec53f2c5..4e8305fa4 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -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(); 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 6564c99fb..8bd247929 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 @@ -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) 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 15344a34e..ed7398b0d 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 @@ -17,13 +17,13 @@ use pocketmine\Server; class NoBlockBreak implements Feature, Listener { - /** @var Arena */ + /** @var Arena */ private $arena; - /** @var int[] */ + /** @var int[] */ private $ids = []; - /** @var bool */ + /** @var bool */ private $black; /** @var bool */ diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php new file mode 100644 index 000000000..044279afd --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php @@ -0,0 +1,161 @@ +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); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php index 21066e32d..1f28552e1 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php @@ -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);