diff --git a/Pocket/plugins/Mineplex/src/Test.php b/Pocket/plugins/Mineplex/src/Test.php index 1a14d662a..7775713b2 100644 --- a/Pocket/plugins/Mineplex/src/Test.php +++ b/Pocket/plugins/Mineplex/src/Test.php @@ -1,17 +1,23 @@ $moo) +function myfunction($a,$b) { - if ($moo == '2') - unset ($array[$key]); + if ($a===$b) + { + return 0; + } + return ($a>$b)?1:-1; } -print_r($array); \ No newline at end of file +$a1=array(new stdClass(),"b"=>"green","c"=>"blue"); +$a2=array("a"=>"blue","b"=>"black","e"=>"blue"); + +$result=array_udiff($a1,$a2,"myfunction"); +print_r($result); \ No newline at end of file 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 @@ getArena() !== $this->arena) return; - Server::getInstance()->broadcastMessage("ToGameState:".(string)$event->getToGameState()); - Server::getInstance()->broadcastMessage("StartGameState: $this->startGameState"); - if ($event->getToGameState() == $this->startGameState) { BenchSchedule::runTaskTimer($this, 1000, 1000); @@ -74,16 +71,17 @@ class GameStateCountdown implements Listener, BenchTask { { print "Count: $this->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; - $lastFeatures = $this->features[$event->getFromGameState()]; - $theseFeatures = $this->features[$event->getToGameState()]; + /** @var Feature[] $lastFeatures */ - $toEnable = array_diff($theseFeatures, $lastFeatures); - $toDisable = array_diff($lastFeatures, $theseFeatures); + if (isset($this->features[$event->getFromGameState()]) || array_key_exists($event->getFromGameState(), $this->features)) + $lastFeatures = $this->features[$event->getFromGameState()]; + else + $lastFeatures = []; + + + /** @var Feature[] $theseFeatures */ + + if (isset($this->features[$event->getToGameState()]) || array_key_exists($event->getToGameState(), $this->features)) + $theseFeatures = $this->features[$event->getToGameState()]; + 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) { - //$feature-> + if (!$feature->isEnabled()) + $feature->enable(); } + foreach ($toDisable as $feature) { + if ($feature->isEnabled()) + $feature->disable(); + } } public function onEnd(ArenaEndEvent $event) { if ($event->getArena() !== $this->arena) return; + + + $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features)); + + foreach ($iterator as $feature) { + if ($feature->isEnabled()) + $feature->disable(); + } + HandlerList::unregisterAll($this); } -} \ No newline at end of file + + function comp($a,$b) + { + if ($a===$b) + { + return 0; + } + return ($a>$b)?1:-1; + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 e69533750..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,20 +56,25 @@ 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() { + Server::getInstance()->broadcastMessage("Enabled!"); $this->enabled = true; Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin()); } public function disable() { + Server::getInstance()->broadcastMessage("Disabled!"); $this->enabled = false; HandlerList::unregisterAll($this); } + public function isEnabled() { return $this->enabled; 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 new file mode 100644 index 000000000..e1994b845 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoMovement.php @@ -0,0 +1,63 @@ +arena = $arena; + } + + public function onBlockBreak(BlockBreakEvent $event) + { + if (!in_array($event->getPlayer(), $this->arena->getPlayers())) + return; + + + + $event->setCancelled(true); + + + + } + + + + public function enable() + { + $this->enabled = true; + Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin()); + } + + public function disable() + { + Server::getInstance()->broadcastMessage("Disabled!"); + $this->enabled = false; + HandlerList::unregisterAll($this); + } + + public function isEnabled() + { + return $this->enabled; + } +} \ 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 index 46413d66d..92d72f974 100644 --- 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 @@ -1,7 +1,7 @@ setGameState(GameState::LOBBY); } + /** + * @priority LOW + * @param ArenaEndEvent $event + */ public function onEnd(ArenaEndEvent $event) { if ($event->getArena() !== $this->arena) return; HandlerList::unregisterAll($this); - $this->setGameState(GameState::RESTARTING); + $this->localSetState(GameState::RESTARTING); } @@ -64,13 +68,19 @@ class GameStateComponent implements Listener { return true; } + $this->localSetState($gameState); + + return true; + } + + private function localSetState($gameState) + { + $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() diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/factory/GameFactory.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/factory/GameFactory.php new file mode 100644 index 000000000..2b2b97455 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/factory/GameFactory.php @@ -0,0 +1,18 @@ + array($noBlockBreak), + GameState::PRE_GAME => array($noBlockBreak), + GameState::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, 10, GameState::PRE_GAME, GameState::GAME); - //new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME); + new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME); - //new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); + new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); } } \ 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 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