diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php new file mode 100644 index 000000000..5ef9eadfb --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php @@ -0,0 +1,110 @@ +arena = $arena; + $this->worldComponent = $worldComponent; + $this->gameMode = $gameMode; + + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onWorld(WorldLoadSuccessEvent $event) + { + print "WorldLoadSuccessEvent!"; + if ($event->getArena() !== $this->arena) + return; + $this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams()); + + foreach ($this->spawns as $key => $value) + { + if (!($value instanceof Position)) + unset($this->spawns[$key]); + } + + print (count($this->spawns) . " spawns Loaded\n"); + + //Just testing to make sure it is a location. + $pos = $this->spawns[array_rand($this->spawns)]; + + print "\nX: " . $pos->getX(); + print "\nY: " . $pos->getY(); + print "\nZ: " . $pos->getZ(); + print "\nLevel: " . $pos->getLevel()->getName(); + + } + + /** + * @param Player $player + * @return Position + */ + function respawn(Player $player) + { + if (count($this->spawns) < 1) + { + print "no spawns!"; + + return; + } + + $player->getInventory()->clearAll(); + $player->removeAllEffects(); + $player->resetFallDistance(); + $player->setGamemode($this->gameMode); + $player->setHealth($player->getMaxHealth()); + + $pos = $this->spawns[array_rand($this->spawns)]; + + print "\nX: " . $pos->getX(); + print "\nY: " . $pos->getY(); + print "\nZ: " . $pos->getZ(); + print "\nLevel: " . $pos->getLevel()->getName(); + + $player->teleport($pos); + return $pos; + } + + function respawnAll() { + foreach ($this->arena->getPlayers() as $player) + { + $this->respawn($player); + } + } + + function onEnd(ArenaEndEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + HandlerList::unregisterAll($this); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php new file mode 100644 index 000000000..e0906aa60 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php @@ -0,0 +1,50 @@ +arena = $arena; + $this->spawnComponent = $spawnComponent; + $this->gameStates = $gameStates; + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onStateChange(GameStateChangeEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + if (in_array($event->getToGameState(), $this->gameStates)) { + $this->spawnComponent->respawnAll(); + print "called! \n"; + } + } + + public function onEnd(ArenaEndEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + HandlerList::unregisterAll($this); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php index 5b70af098..145be17e6 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php @@ -19,4 +19,6 @@ interface SpawnComponent { */ function respawn(Player $player); + function respawnAll(); + } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 6a5395a26..92a2ba152 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -9,11 +9,14 @@ namespace mineplex\plugin\gameengine\game\components\world; 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\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilString; use mineplex\plugin\util\UtilFile; +use pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\level\Position; use pocketmine\math\Vector3; @@ -48,30 +51,14 @@ class WorldComponent implements Listener $this->gameId = $this->getNewGameId(); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); - - $this->loadWorld("Super Smash Mobs"); } -// This is just some wierd testiong. Ignore it :P -// public function onJoin(PlayerJoinEvent $event) -// { -// $this->player = $event->getPlayer(); -// } -// -// public function onEvent(UpdateEvent $event) -// { -// if (is_null($this->player)) -// return; -// -// if ($event->isTiming(UpdateType::S8)) -// { -// $this->player->teleport($this->posTest); -// -// print("Teleporting " . $this->player->getName() . " to...\n"); -// -// $this->player = null; -// } -// } + public function onStart(ArenaStartEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + $this->loadWorld("Super Smash Mobs"); + } private function unloadWorld() { @@ -309,5 +296,12 @@ class WorldComponent implements Listener { return $this->ready; } + + public function onEnd(ArenaEndEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + HandlerList::unregisterAll($this); + } } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php index 4832c2dca..5f84070d7 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php @@ -19,6 +19,8 @@ use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeature use mineplex\plugin\gameengine\game\components\gamestate\GameState; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; use mineplex\plugin\gameengine\game\components\lobby\LobbyComponent; +use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent; +use mineplex\plugin\gameengine\game\components\spawn\SpawnAt; use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\Game; @@ -35,7 +37,6 @@ class SurvivalGames implements Game { $spectateComponent = new GameModeSpectateComponent($arena); //Init features - $noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true); $pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true)); @@ -45,21 +46,23 @@ class SurvivalGames implements Game { GameState::LOBBY => array($noPickUpItem, $pack) ); - new GameStateFeatureManager($arena, $features); - //new LobbyComponent($arena); + new LobbyComponent($arena); - /* $worldComponent = new WorldComponent($arena); - new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 50, 1); + $spawnComponent = new SimpleSpawnComponent($arena, $worldComponent); + + new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]); + + new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1); new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME); - new GameStateCountdown($arena, $gameStateComponent, 60, GameState::GAME, GameState::POST_GAME); + new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME); new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); - */ + } } \ No newline at end of file