From 88241fa4d50e28f17e0ca2e1701070dd61865695 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Wed, 1 Jul 2015 18:36:05 -0400 Subject: [PATCH] Added some stuff and things Signed-off-by: Aaron Brock --- .../plugin/bench/arenas/SingleGameArena.php | 2 + .../bench/arenas/events/ArenaStartEvent.php | 20 +++++ .../countdown/GameStateCountdown.php | 52 ++++++++++++ .../game/components/gamestate/GameState.php | 21 +++++ .../gamestate/GameStateComponent.php | 84 +++++++++++++++++++ .../bench/game/components/gamestate/Test.php | 15 ++++ .../gamestate/events/GameStateChangeEvent.php | 36 ++++++++ 7 files changed, 230 insertions(+) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaStartEvent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/countdown/GameStateCountdown.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameState.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameStateComponent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/Test.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/events/GameStateChangeEvent.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php index f6c7fcf2e..294f0a97d 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php @@ -18,6 +18,7 @@ use mineplex\plugin\bench\game\Game; use mineplex\plugin\bench\arenas\events\ArenaCanJoinEvent; use mineplex\plugin\bench\arenas\events\ArenaJoinEvent; use mineplex\plugin\bench\arenas\events\ArenaQuitEvent; +use mineplex\plugin\bench\arenas\events\ArenaStartEvent; class SingleGameArena implements Arena, Listener { //I really have no idea if there is a better way to store players... but this is what I'm using for now. @@ -35,6 +36,7 @@ class SingleGameArena implements Arena, Listener { $this->game = $game; $this->plugin = $plugin; $this->getCurrentGame()->start($this); + Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this)); } public function canJoin(Player $player) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaStartEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaStartEvent.php new file mode 100644 index 000000000..2fd03a23b --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaStartEvent.php @@ -0,0 +1,20 @@ +getPlugin()); + $this->gameStateComponent = $gameStateComponent; + + $this->startCount = $count; + $this->count = $count; + + $this + } + + public function onGameStateChange(GameStateChangeEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + + + } + + + public function onRun($currentTick) + { + $this->plugin->getServer()->getPluginManager()->callEvent(new TickEvent($currentTick)); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameState.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameState.php new file mode 100644 index 000000000..d72fbcbc8 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/GameState.php @@ -0,0 +1,21 @@ +arena = $arena; + $this->gameState = GameState::RESTARTING; + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onStart(ArenaStartEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + $this->setGameState(GameState::LOBBY); + } + + public function onEnd(ArenaEndEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + HandlerList::unregisterAll($this); + $this->setGameState(GameState::RESTARTING); + } + + + public function setGameState($gameState) + { + + if ($gameState < GameState::LOBBY) + $gameState = GameState::LOBBY; + + if ($gameState > GameState::RESTARTING) + $gameState = GameState::RESTARTING; + + if ($gameState == $this->gameState) + return false; + + if ($gameState == GameState::RESTARTING) + { + $this->arena->endGame(); + return true; + } + + $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() + { + return $this->gameState; + } + +} + +//$john = new GameStateComponent(); +//echo $john->getGameState(); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/Test.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/Test.php new file mode 100644 index 000000000..eb777d4a3 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/Test.php @@ -0,0 +1,15 @@ +getGameState(); \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/events/GameStateChangeEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/events/GameStateChangeEvent.php new file mode 100644 index 000000000..02e9be208 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/gamestate/events/GameStateChangeEvent.php @@ -0,0 +1,36 @@ +fromGameState = $fromGameState; + $this->toGameState = $toGameState; + } + + public function getFromGameState() + { + return $this->fromGameState; + } + + public function getToGameState() + { + return $this->toGameState; + } + +} \ No newline at end of file