From 514fe4a18a6124f0dfc29dbe9dd273ea5e294c10 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Sat, 4 Jul 2015 20:59:15 -0400 Subject: [PATCH] Added some stuff. Signed-off-by: Aaron Brock --- .../Mineplex/src/mineplex/plugin/Main.php | 79 +++----------- .../mineplex/plugin/bench/arenas/Arena.php | 10 +- .../plugin/bench/arenas/ArenaEvent.php | 2 +- .../plugin/bench/arenas/MultiGameArena.php | 102 ++++++++++++++++++ .../plugin/bench/arenas/SingleGameArena.php | 3 +- .../bench/arenas/events/ArenaCanJoinEvent.php | 2 +- .../bench/arenas/events/ArenaEndEvent.php | 2 +- .../bench/arenas/events/ArenaJoinEvent.php | 2 +- .../bench/arenas/events/ArenaQuitEvent.php | 2 +- .../bench/arenas/events/ArenaStartEvent.php | 2 +- .../countdown/GameStateCountdown.php | 12 ++- .../bench/game/components/feature/Feature.php | 2 +- .../feature/GameStateFeatureManager.php | 6 +- .../feature/features/NoBlockBreak.php | 36 ++++++- .../feature/features/NoMovement.php | 2 +- .../game/components/gamestate/GameState.php | 2 +- .../plugin/bench/game/factory/GameFactory.php | 18 ++++ .../bench/game/factory/TestGameFactory.php | 20 ++++ .../plugin/bench/game/games/pvp/Pvp.php | 6 +- .../bench/game/games/sg/SurvivalGames.php | 46 ++++++++ 20 files changed, 268 insertions(+), 88 deletions(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/MultiGameArena.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/factory/GameFactory.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/factory/TestGameFactory.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index e9d7f1cd4..fec53f2c5 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -2,24 +2,26 @@ namespace mineplex\plugin; - -use mineplex\plugin\bench\arenas\SingleGameArena; -use mineplex\plugin\core\updater\UpdateEvent; -use mineplex\plugin\bench\game\games\pvp\Pvp; -use mineplex\plugin\packets\StrangePacket; -use mineplex\plugin\util\UtilString; +use mineplex\plugin\bench\arenas\MultiGameArena; +use mineplex\plugin\bench\game\factory\TestGameFactory; use pocketmine\event\Listener; -use pocketmine\event\player\PlayerCommandPreprocessEvent; use pocketmine\event\player\PlayerJoinEvent; +use pocketmine\event\player\PlayerLoginEvent; +use pocketmine\event\player\PlayerQuitEvent; use pocketmine\plugin\PluginBase; +use mineplex\plugin\bench\arenas\Arena; use pocketmine\Server; class Main extends PluginBase implements Listener { + /** @var Arena */ + private $arena; + public function onEnable() { - new SingleGameArena($this, new Pvp()); + $this->arena = new MultiGameArena($this, new TestGameFactory()); + Server::getInstance()->getPluginManager()->registerEvents($this, $this); //$this->getServer()->getScheduler()->scheduleRepeatingTask(new TickTask($this), 1); @@ -27,64 +29,17 @@ class Main extends PluginBase implements Listener //new Updater($this); } - public function onDisable() + public function onLogin(PlayerLoginEvent $event) { + if ($this->arena->canJoin($event->getPlayer())) + retun; + $event->setKickMessage("Unable to join game!"); + $event->setCancelled(); } - public function joinMessage(PlayerJoinEvent $event) + public function onJoin(PlayerJoinEvent $event) { - $name = $event->getPlayer()->getName(); - - $player = Server::getInstance()->getPlayer($name); - - $event->setJoinMessage($player->getName()); - } - - public function onPlayerJoin(PlayerJoinEvent $event) - { - $event->getPlayer()->sendMessage("Welcome to the server " . $event->getPlayer()->getName() . "!"); - - $this->getLogger()->info($event->getPlayer()->getName() . " UID: " . $event->getPlayer()->getUniqueId()); - - if (UtilString::startsWith( $event->getPlayer()->getName(), "chissling")) - { - $event->getPlayer()->setNameTag("// chiss //"); - $event->getPlayer()->setDisplayName("// chiss //"); - } - } - - public function onPlayerCommand(PlayerCommandPreprocessEvent $event) - { - if (UtilString::startsWith($event->getMessage(), "/mineplex")) - { - $event->setCancelled(true); - - $event->getPlayer()->sendMessage("Sending you to: MINEPLEX"); - - $packet = new StrangePacket(); - $packet->address = "69.175.104.154"; - - $event->getPlayer()->directDataPacket($packet); - } - - if (UtilString::startsWith($event->getMessage(), "/ip ")) - { - $event->setCancelled(true); - - $ip = substr($event->getMessage(), 4, strlen($event->getMessage())); - - $event->getPlayer()->sendMessage("Sending you to: " . $ip); - - $packet = new StrangePacket(); - $packet->address = $ip; - - $event->getPlayer()->directDataPacket($packet); - } - } - - public function onTick(UpdateEvent $event) - { - + $this->arena->addPlayer($event->getPlayer()); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/Arena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/Arena.php index dc266e03e..8d7165749 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/Arena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/Arena.php @@ -1,7 +1,7 @@ getPluginManager()->registerEvents($this, $plugin); + $this->gameFactory = $gameFactory; + $this->plugin = $plugin; + $this->startGame(); + } + + public function canJoin(Player $player) + { + $event = new ArenaCanJoinEvent($this, $player); + $this->plugin->getServer()->getPluginManager()->callEvent($event); + return !$event->isCancelled(); + } + + public function addPlayer(Player $player) + { + $this->plugin->getServer()->getPluginManager()->callEvent(new ArenaJoinEvent($this, $player)); + array_push($this->players, $player); + } + + public function removePlayer(Player $player) + { + if (($key = array_search($player, $this->players, true)) !== FALSE) { + unset($this->players[$key]); + } + Server::getInstance()->broadcastMessage("Calling ArenaQuitEvent"); + $this->plugin->getServer()->getPluginManager()->callEvent(new ArenaQuitEvent($this, $player)); + } + + public function onQuit(PlayerQuitEvent $event) + { + $this->removePlayer($event->getPlayer()); + } + + + public function endGame() + { + Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this)); + $this->startGame(); + } + + private function startGame() + { + $this->game = $this->gameFactory->getGame(); + $this->game->start($this); + Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this)); + } + + + public function getPlayers() + { + return $this->players; + } + + public function getCurrentGame() + { + return $this->game; + } + + public function getPlugin() + { + return $this->plugin; + } +} \ No newline at end of file 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 bb6bb0dff..b5fefc275 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/SingleGameArena.php @@ -31,7 +31,6 @@ class SingleGameArena implements Arena, Listener { public function __construct(Plugin $plugin, Game $game) { - print 'SimpleGameArena Created!'; Server::getInstance()->getPluginManager()->registerEvents($this, $plugin); $this->game = $game; $this->plugin = $plugin; @@ -100,7 +99,7 @@ class SingleGameArena implements Arena, Listener { foreach ($this->players as $player) { Server::getInstance()->broadcastMessage((string)$player->getName()); - $player->kick('Game Over...'); + $player->kick('Game Over...', false); } } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaCanJoinEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaCanJoinEvent.php index 371365268..f45b71c7f 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaCanJoinEvent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/arenas/events/ArenaCanJoinEvent.php @@ -1,7 +1,7 @@ count"."\n"; - $this->popup(); - - $this->count--; - if ($this->count <= 0) { $this->gameStateComponent->setGameState($this->setGameState); $data->end(); } + + $this->popup(); + + $this->count--; + + } public function popup() diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/Feature.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/Feature.php index 026352b4b..e5e2d02e1 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/Feature.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/Feature.php @@ -1,7 +1,7 @@ getArena() !== $this->arena) return; - /** @var Feature[] $iterator */ + $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features)); foreach ($iterator as $feature) { 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 2d61edcd6..15344a34e 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 @@ -1,7 +1,7 @@ ids = array_flip($ids); + foreach ($this->ids as $key => $value) + { + print "Key:" . $key; + } + } + print "\n" . "Black: " . (($black) ? 'true' : 'false') . "\n"; + + $this->black = $black; + + print "\n" . "SetBlackList: " . (($this->black) ? 'true' : 'false') . "\n"; + $this->arena = $arena; } @@ -30,7 +56,9 @@ class NoBlockBreak implements Feature, Listener { { if (!in_array($event->getPlayer(), $this->arena->getPlayers())) return; - $event->setCancelled(true); + + if ($this->black == (isset($this->ids[$event->getBlock()->getId()]) || array_key_exists($event->getBlock()->getId(), $this->ids))) + $event->setCancelled(); } public function enable() 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 index ed3a5bf66..e1994b845 100644 --- 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 @@ -1,7 +1,7 @@ array($noBlockBreak), GameState::PRE_GAME => array($noBlockBreak), - GameState::POST_GAME => array($noBlockBreak), + GameState::GAME => array($noBlockBreak), + GameState::POST_GAME => array($noBlockBreak) ); new GameStateFeatureManager($arena, $features); 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 new file mode 100644 index 000000000..21066e32d --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php @@ -0,0 +1,46 @@ + 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, 30, GameState::GAME, GameState::POST_GAME); + + new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); + } +} \ No newline at end of file