From bac505f2cdcfc2750603ccad1c03e81575425ac4 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Sun, 5 Jul 2015 18:49:42 -0400 Subject: [PATCH] Edited some things --- .../Mineplex/src/mineplex/plugin/Main.php | 6 +- .../game/components/lobby/LobbyComponent.php | 58 ++++++++++++++----- .../mineplex/plugin/core/updater/Updater.php | 3 +- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index b7992596c..655d6451e 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -9,6 +9,8 @@ use mineplex\plugin\core\updater\Updater; use pocketmine\event\Listener; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerLoginEvent; +use pocketmine\level\Position; +use pocketmine\math\Vector3; use pocketmine\plugin\PluginBase; use mineplex\plugin\bench\arenas\Arena; use pocketmine\Server; @@ -24,9 +26,7 @@ class Main extends PluginBase implements Listener $this->arena = new MultiGameArena($this, new TestGameFactory()); Server::getInstance()->getPluginManager()->registerEvents($this, $this); - $this->test = new WorldComponent($this->arena); - - //$this->getServer()->getPluginManager()->registerEvents($this, $this); + //$this->test = new WorldComponent($this->arena); new Updater($this); } 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 index 43a3941a4..510ae58eb 100644 --- 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 @@ -11,6 +11,7 @@ namespace mineplex\plugin\bench\game\components\lobby; use mineplex\plugin\bench\arenas\Arena; use mineplex\plugin\bench\arenas\events\ArenaEndEvent; +use mineplex\plugin\bench\arenas\events\ArenaJoinEvent; 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; @@ -21,17 +22,20 @@ 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; +use pocketmine\level\Position; +use pocketmine\Player; +use pocketmine\Server; -class LobbyComponent implements Listener { +class LobbyComponent implements Listener +{ /** @var Arena */ private $arena; /** @var String */ - private $worldName; + public $worldName; private $duringLobbyGameState; @@ -41,7 +45,6 @@ class LobbyComponent implements Listener { */ public function __construct(Arena $arena, $world = null) { - if ($world == null) $world = Server::getInstance()->getDefaultLevel(); @@ -51,7 +54,7 @@ class LobbyComponent implements Listener { $this->worldName = $world->getName(); $this->arena = $arena; - $this->duringLobbyGameState = new DuringLobbyGameState($arena); + $this->duringLobbyGameState = new DuringLobbyGameState($arena, $world); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); } @@ -70,15 +73,11 @@ class LobbyComponent implements Listener { return; if ($event->getToGameState() == GameState::LOBBY) { - if (!$this->duringLobbyGameState->isEnabled()) - { + if (!$this->duringLobbyGameState->isEnabled()) { $this->duringLobbyGameState->enable(); } - } - elseif ($event->getFromGameState() == GameState::LOBBY) - { - if ($this->duringLobbyGameState->isEnabled()) - { + } elseif ($event->getFromGameState() == GameState::LOBBY) { + if ($this->duringLobbyGameState->isEnabled()) { $this->duringLobbyGameState->disable(); } } @@ -96,16 +95,20 @@ class LobbyComponent implements Listener { } } -class DuringLobbyGameState implements Feature, Listener { +class DuringLobbyGameState implements Feature, Listener +{ private $arena; + private $spawn; + /** @var bool */ private $enabled = false; - public function __construct(Arena $arena) + public function __construct(Arena $arena, Level $world) { $this->arena = $arena; + $this->spawn = new Position(0, 103, 0, $world); } @@ -140,6 +143,28 @@ class DuringLobbyGameState implements Feature, Listener { $event->setCancelled(); } + function onJoin(ArenaJoinEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + + $this->sendToSpawn($event->getPlayer()); + } + + function sendToSpawn(Player $player) + { + $player->getInventory()->clearAll(); + $player->removeAllEffects(); + + $player->setHealth($player->getMaxHealth()); + $player->resetFallDistance(); + + $pos = $this->spawn->add(rand(-4, 4), 0, rand(-4, 4)); + + $player->teleport($pos); + } + + function isEnabled() { return $this->enabled; @@ -147,14 +172,15 @@ class DuringLobbyGameState implements Feature, Listener { function enable() { - Server::getInstance()->broadcastMessage("Enabled!"); + foreach ($this->arena->getPlayers() as $player) { + $this->sendToSpawn($player); + } $this->enabled = true; Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin()); } function disable() { - Server::getInstance()->broadcastMessage("Disabled!"); $this->enabled = false; HandlerList::unregisterAll($this); } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php index d843920fc..8090d0bb3 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php @@ -15,6 +15,7 @@ use pocketmine\scheduler\PluginTask; class Updater extends PluginTask { private $plugin; + /** @var UpdateType[] */ private $updateTypes; public function __construct(PluginBase $host) @@ -51,7 +52,7 @@ class Updater extends PluginTask { if ($updateType->canTrigger()) { - $updateTypes[$updateType] = 1; + $updateTypes[$updateType->time] = 1; } } //Call Event