diff --git a/Pocket/plugins/Mineplex/src/Test.php b/Pocket/plugins/Mineplex/src/Test.php index 42337416e..658c1d884 100644 --- a/Pocket/plugins/Mineplex/src/Test.php +++ b/Pocket/plugins/Mineplex/src/Test.php @@ -7,9 +7,6 @@ */ -$a1 = array(); -$a2 = array($a1); - -array_push($a1, $a2); - -print_r($a1); \ No newline at end of file +$array = array(); +array_push($array, $array); +print_r($array); \ 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 03cc4a21e..fb64e78ad 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -15,6 +15,7 @@ use pocketmine\event\player\PlayerDeathEvent; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerLoginEvent; +use pocketmine\event\player\PlayerRespawnEvent; use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\Player; @@ -40,9 +41,10 @@ class Main extends PluginBase implements Listener $this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0)); } + public function onLogin(PlayerLoginEvent $event) { - UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat'); + //UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat'); if ($this->arena->canJoin($event->getPlayer())) return; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php index 1c4fd18c1..bcebb99db 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php @@ -31,6 +31,12 @@ interface Arena */ public function hasPlayer($player); + /** + * @param string $message + * @return void + */ + public function broadcast($message); + /** * @return Plugin */ diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php index 5ae4372c3..2c8df6026 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php @@ -72,6 +72,7 @@ class MultiGameArena implements Arena, Listener public function endGame() { + Server::getInstance()->broadcastMessage("Game Over!"); Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this)); $this->startGame(); } @@ -99,6 +100,14 @@ class MultiGameArena implements Arena, Listener return in_array($player, $this->getPlayers()); } + public function broadcast($message) + { + foreach ($this->getPlayers() as $player) + { + $player->sendMessage($message); + } + } + public function getCurrentGame() { return $this->game; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/GameStateCountdown.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/GameStateCountdown.php index 0ee90f870..4c51f99f8 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/GameStateCountdown.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/GameStateCountdown.php @@ -11,13 +11,15 @@ namespace mineplex\plugin\gameengine\game\components\countdown; use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; +use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent; use mineplex\plugin\gameengine\time\BenchSchedule; use mineplex\plugin\gameengine\time\BenchTask; use mineplex\plugin\gameengine\time\BenchTaskData; + use pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\Server; -use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent; + class GameStateCountdown implements Listener, BenchTask { @@ -69,17 +71,17 @@ class GameStateCountdown implements Listener, BenchTask { public function run(BenchTaskData $data) { - print "Count: $this->count"."\n"; - + //print "§$this->startGameState---"."\n"; + $this->popup(); if ($this->count <= 0) { $this->gameStateComponent->setGameState($this->setGameState); $data->end(); } - - $this->popup(); - - $this->count--; + else + { + $this->count--; + } } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php index 0ccf4200b..9afce41f5 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php @@ -12,22 +12,17 @@ use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent; use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent; +use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\time\BenchSchedule; use mineplex\plugin\gameengine\time\BenchTask; use mineplex\plugin\gameengine\time\BenchTaskData; -use pocketmine\entity\Effect; use pocketmine\event\HandlerList; use pocketmine\event\Listener; -use pocketmine\event\player\PlayerDeathEvent; -use pocketmine\network\protocol\AnimatePacket; -use pocketmine\network\protocol\ContainerSetDataPacket; -use pocketmine\network\protocol\DropItemPacket; use pocketmine\Player; use pocketmine\Server; -use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent; class LobbyCountdown implements Listener, BenchTask { @@ -42,13 +37,11 @@ class LobbyCountdown implements Listener, BenchTask { private $message; - const WAITING_FOR_PLAYERS = "Waiting for players!"; - const POPUP_ID = "popup"; const COUNTDOWN_ID = "count"; - public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent, $startGameState, $setGameState, $count, $minPlayers = 2) + public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2) { $this->arena = $arena; $this->gameStateComponent = $gameStateComponent; @@ -61,9 +54,9 @@ class LobbyCountdown implements Listener, BenchTask { $this->startGameState = $startGameState; $this->setGameState = $setGameState; - $this->message = self::WAITING_FOR_PLAYERS; - Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + + $this->checkCountdown(); } @@ -74,7 +67,7 @@ class LobbyCountdown implements Listener, BenchTask { { $playerCount = (count($this->arena->getPlayers()) + $addOne); - if ($this->gameStateComponent->getGameState() == $this->startGameState && $this->worldComponent->isWorldReady() && $playerCount >= $this->minPlayers) + if ($this->gameStateComponent->getGameState() == $this->startGameState && ($this->worldComponent == null || $this->worldComponent->isWorldReady()) && $playerCount >= $this->minPlayers) { if (!BenchSchedule::isRunningWithId($this, self::COUNTDOWN_ID)) { @@ -104,7 +97,8 @@ class LobbyCountdown implements Listener, BenchTask { { if ($event->getArena() !== $this->arena) return; - $this->checkCountdown(); + if ($this->gameStateComponent->getGameState() == $this->startGameState) + $this->checkCountdown(); } public function onWorldCreation(WorldLoadSuccessEvent $event) @@ -192,6 +186,6 @@ class LobbyCountdown implements Listener, BenchTask { private function popup(Player $player) { - $player->sendTip($this->message); + $player->sendPopup($this->message); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php index 6446a631f..a45be076b 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php @@ -8,11 +8,9 @@ namespace mineplex\plugin\gameengine\game\components\feature; - use mineplex\plugin\gameengine\arenas\Arena; use pocketmine\event\HandlerList; use pocketmine\event\Listener; -use pocketmine\plugin\Plugin; use pocketmine\Server; class ListenerFeature implements Feature, Listener { @@ -39,11 +37,11 @@ class ListenerFeature implements Feature, Listener { } /** - * @return boolean + * @return bool */ public function isEnabled() { - $this->enabled; + return $this->enabled; } /** diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/FreezePlayers.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/FreezePlayers.php new file mode 100644 index 000000000..d27893472 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/FreezePlayers.php @@ -0,0 +1,87 @@ +spectateComponent = $spectateComponent; + } + + function onMove(PlayerMoveEvent $event) + { + + if (!$this->hasPlayer($event->getPlayer())) + return; + + if ($event->getFrom()->getFloorX() != $event->getTo()->getFloorX() || $event->getFrom()->getFloorZ() != $event->getTo()->getFloorZ()) + $event->setCancelled(); + } + + public function enable() + { + parent::enable(); + + $effect = new Effect(Effect::SLOWNESS, "Waiting till game start...", 0, 0, 0, true); + $effect->setVisible(false)->setAmplifier(9)->setDuration(PHP_INT_MAX); + print "Player Count: " . count($this->getPlayers()) . "\n"; + foreach ($this->getPlayers() as $player) + { + print "Adding effect! \n"; + $player->addEffect($effect); + } + } + + public function disable() + { + parent::disable(); + print "Player Count: " . count($this->getPlayers()) . "\n"; + foreach ($this->getPlayers() as $player) + { + print "Adding effect! \n"; + $player->removeEffect(Effect::SLOWNESS); + } + } + + + /** + * @return Player[] + */ + private function getPlayers() + { + if ($this->spectateComponent !== null) + return $this->spectateComponent->getNonSpectators(); + else + return $this->getArena()->getPlayers(); + } + + /** + * @param Player $player + * @return bool + */ + private function hasPlayer(Player $player) + { + if ($this->spectateComponent !== null) + return $this->spectateComponent->isNotSpectating($player); + else + return $this->getArena()->hasPlayer($player); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/JoinSpectate.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/JoinSpectate.php new file mode 100644 index 000000000..07988a691 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/JoinSpectate.php @@ -0,0 +1,50 @@ +spectateComponent = $spectateComponent; + $this->id = rand(0, 99999); + } + + function onJoin(ArenaJoinEvent $event) + { + if ($this->getArena() !== $event->getArena()) + return; + $this->spectateComponent->enableSpectate($event->getPlayer()); + } + public function enable() + { + Server::getInstance()->broadcastMessage("JoinSpectate enable! : $this->id"); + parent::enable(); + print "JoinSpectate enable? " . ($this->isEnabled() ? 'true' : 'false') . "\n"; + } + + public function disable() + { + Server::getInstance()->broadcastMessage("JoinSpectate disable!"); + parent::disable(); + } + +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDamage.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDamage.php new file mode 100644 index 000000000..d43b2cefa --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDamage.php @@ -0,0 +1,31 @@ +getArena()->hasPlayer($event->getEntity())) + return; + //Server::getInstance()->broadcastMessage("Stopped!"); + $event->setCancelled(); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php index 9d9cc03b9..dba569cd0 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php @@ -40,7 +40,9 @@ class GameStateFeatureManager implements Listener { foreach ($features as $key => $value) { + $this->features[$key] = UtilArray::getValuesRecursively($value); + print "$key: " . count($this->features[$key]) . "\n"; } Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); @@ -66,20 +68,55 @@ class GameStateFeatureManager implements Listener { else $theseFeatures = []; + print "\nLast Count: ". count($lastFeatures); + print "\nThese Count: ". count($theseFeatures); + + /** @var Feature[] $toEnable */ $toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures); + print "\nEnable Count: ". count($toEnable); + /** @var Feature[] $toDisable */ $toDisable = UtilArray::arrayDiff($lastFeatures, $theseFeatures); + print "\nDisable Count: ". count($toDisable); + + print "\n"; + + foreach ($toDisable as $feature) + { + if (in_array($feature, $theseFeatures)) + print "An error has happened!!\n"; + else + print "All good ^_^\n"; + } + foreach ($toDisable as $feature) { if ($feature->isEnabled()) + { + print "Disable: " . get_class($feature) . spl_object_hash($feature) . "\n"; $feature->disable(); + } + else + { + print get_class($feature) . "\n" . "Is already disabled!" . "\n"; + } } + foreach ($toEnable as $feature) { if (!$feature->isEnabled()) + { + print "Enable: " . get_class($feature) . spl_object_hash($feature) . "\n"; $feature->enable(); + } + else + { + print get_class($feature) . "\n" . "Is already enabled!" . "\n"; + } + } + } public function onEnd(ArenaEndEvent $event) @@ -87,7 +124,7 @@ class GameStateFeatureManager implements Listener { if ($event->getArena() !== $this->arena) return; - $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features)); + $iterator = UtilArray::getValuesRecursively($this->features); foreach ($iterator as $feature) { if ($feature->isEnabled()) 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 index d9ab860a0..30bd97943 100644 --- 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 @@ -15,6 +15,7 @@ use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\Main; use mineplex\plugin\util\UtilArray; +use mineplex\plugin\util\UtilTeleport; use pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\level\Position; @@ -86,8 +87,8 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { //$pos = $pos->getLevel()->getSpawnLocation(); print_r($pos); - - $player->teleport($pos); + UtilTeleport::teleport($player, $pos); + //$player->teleport($pos); $player->sendMessage("After:"); Main::sendLoc($player); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/victorytype/LMSVictoryType.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/victorytype/LMSVictoryType.php new file mode 100644 index 000000000..621ebbd3f --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/victorytype/LMSVictoryType.php @@ -0,0 +1,183 @@ +arena = $arena; + $this->duringGame = new DuringGame($arena, $spectateComponent, $gameStateComponent, $endPlayersAmount); + + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + + public function gameStateChange(GameStateChangeEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + + if ($event->getToGameState() == GameState::GAME) + { + UtilFeature::enable($this->duringGame); + } + elseif ($event->getFromGameState() == GameState::GAME) + { + UtilFeature::disable($this->duringGame); + } + } + + public function onEnd(ArenaEndEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + UtilFeature::disable($this->duringGame); + HandlerList::unregisterAll($this); + } + + +} + +class DuringGame extends ListenerFeature implements BenchTask { + + /** @var Player[] */ + private $rank = []; + + /** @var Arena */ + private $arena; + + /** @var SpectateComponent */ + private $spectateComponent; + + /** @var GameStateComponent */ + private $gameStateComponent; + + /** @var int */ + private $endPlayersAmount; + + function __construct(Arena $arena, SpectateComponent $spectateComponent, GameStateComponent $gameStateComponent, $endPlayersAmount = 1) + { + parent::__construct($arena); + $this->arena = $arena; + $this->spectateComponent = $spectateComponent; + $this->gameStateComponent = $gameStateComponent; + $this->endPlayersAmount = $endPlayersAmount; + } + + #On LOWEST so I can check if the player is spectating, as the player is removed from the spectating list on LOW + /** + * @priority LOWEST + * @param ArenaQuitEvent $event + */ + public function onLeave(ArenaQuitEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + + if (!$this->spectateComponent->isSpectating($event->getPlayer())) + array_push($this->rank, $event->getPlayer()); + + $this->checkEndGame(); + } + + + public function onSpectate(EnableSpectateEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + + array_push($this->rank, $event->getPlayer()); + + //Meh, don't like doing things this way, but I need it to call sendWinners after the player is added to spectating from spectating. + BenchSchedule::runTaskLater($this, 0); + } + + public function checkEndGame($subtract = false) + { + if ($this->gameStateComponent->getGameState() != GameState::GAME) + { + if ($this->isEnabled()) + $this->disable(); + return; + } + + $count = count($this->spectateComponent->getNonSpectators()) - $subtract; + + if ($count <= $this->endPlayersAmount) + { + $this->gameStateComponent->setGameState(GameState::POST_GAME); + } + } + + private function sendWinners() + { + foreach ($this->spectateComponent->getNonSpectators() as $player) + { + array_push($this->rank, $player); + } + /** @var Player[] $rank */ + $rank = array_reverse($this->rank); + + $counter = 0; + $this->arena->broadcast("----------"); + $this->arena->broadcast(""); + + foreach ($rank as $player) + { + $counter++; + $this->arena->broadcast("$counter. §e" . $player->getName()); + if ($counter >= 3) + break; + } + + $this->arena->broadcast(""); + $this->arena->broadcast("----------"); + } + + public function run(BenchTaskData $task) + { + $this->checkEndGame(); + } + + public function enable() + { + BenchSchedule::runTaskLater($this, 0); + parent::enable(); + } + + public function disable() + { + $this->sendWinners(); + BenchSchedule::cancelTask($this); + parent::disable(); + } +} \ 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 093732b04..e6672eae1 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 @@ -18,6 +18,7 @@ use mineplex\plugin\util\UtilString; use mineplex\plugin\util\UtilFile; use pocketmine\event\HandlerList; use pocketmine\event\Listener; +use pocketmine\event\player\PlayerRespawnEvent; use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\Server; 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 77ed45aa2..b1bdbd1a6 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 @@ -8,11 +8,14 @@ namespace mineplex\plugin\gameengine\game\games\sg; +use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\game\components\countdown\GameStateCountdown; -use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown; use mineplex\plugin\gameengine\game\components\feature\features\DeathSpectate; +use mineplex\plugin\gameengine\game\components\feature\features\FreezePlayers; +use mineplex\plugin\gameengine\game\components\feature\features\JoinSpectate; use mineplex\plugin\gameengine\game\components\feature\features\NoBlockBreak; use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace; +use mineplex\plugin\gameengine\game\components\feature\features\NoDamage; use mineplex\plugin\gameengine\game\components\feature\features\NoDropItem; use mineplex\plugin\gameengine\game\components\feature\features\NoPickUpItem; use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager; @@ -24,52 +27,55 @@ 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; -use mineplex\plugin\gameengine\arenas\Arena; +use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown; use mineplex\plugin\gameengine\game\components\feature\Feature; -use mineplex\plugin\gameengine\time\BenchSchedule; -use mineplex\plugin\gameengine\time\BenchTask; -use mineplex\plugin\gameengine\time\BenchTaskData; -use pocketmine\item\Item; - +use mineplex\plugin\gameengine\game\components\victorytype\LMSVictoryType; class SurvivalGames implements Game { - /** @var Arena */ - private $arena; function start(Arena $arena) { - $this->arena = $arena; - $gameStateComponent = new GameStateComponent($arena); - //$spectateComponent = new GameModeSpectateComponent($arena); + $spectateComponent = new GameModeSpectateComponent($arena); - //Init features - //$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true); + $worldComponent = new WorldComponent($arena); - //$pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true)); + new LobbyComponent($arena); + + //Features start---- + $noDamage = new NoDamage($arena); + $joinSpectate = new JoinSpectate($arena, $spectateComponent); + + $stopEveryThing = array(new NoBlockBreak($arena), new NoBlockPlace($arena),new NoDropItem($arena), new NoPickUpItem($arena)); /** @var Feature[][] $features */ - //$features = array( - // GameState::LOBBY => array($noPickUpItem, $pack) - //); + $features = array( - //new GameStateFeatureManager($arena, $features); + GameState::PRE_GAME => array( $stopEveryThing, $noDamage, $joinSpectate, new FreezePlayers($arena, $spectateComponent)), - //new LobbyComponent($arena); + GameState::GAME => array( $stopEveryThing, $joinSpectate , new DeathSpectate($arena, $spectateComponent)), - $worldComponent = new WorldComponent($arena); + GameState::POST_GAME => array($stopEveryThing, $noDamage, $joinSpectate), - $spawnComponent = new SimpleSpawnComponent($arena, $worldComponent); + ); - new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]); + new GameStateFeatureManager($arena, $features); + //Features end--- - 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, 20, GameState::GAME, GameState::POST_GAME); + new SpawnAt($arena, new SimpleSpawnComponent($arena, $worldComponent), [GameState::PRE_GAME]); - //new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); + new LobbyCountdown( $arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 2); + + //new GameStateCountdown($arena, $gameStateComponent, 5, GameState::LOBBY, GameState::PRE_GAME); + + new GameStateCountdown($arena, $gameStateComponent, 20, GameState::PRE_GAME, GameState::GAME); + + //new GameStateCountdown($arena, $gameStateComponent, 5, GameState::GAME, GameState::POST_GAME); + new LMSVictoryType( $arena, $spectateComponent, $gameStateComponent); + + new GameStateCountdown($arena, $gameStateComponent, 5, GameState::POST_GAME, GameState::RESTARTING); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php index f630a6f37..db867477e 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php @@ -18,7 +18,17 @@ class UtilArray { public static function arrayDiff(array $array, array $subtract) { - return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']); + //THIS IS TEMP FIX LATER!! + $return = []; + foreach ($array as $value) + { + if (!in_array($value, $subtract)) + array_push($return, $value); + } + + return $return; + + //return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']); } @@ -51,4 +61,12 @@ class UtilArray { return $returnArray; } -} \ No newline at end of file +} +/* +$obj1 = new \stdClass(); +$a1=array("a"=>$obj1,"b"=>"green","c"=>"blue"); +$a2=array("d"=>$obj1,"b"=>"black","e"=>"blue"); +$result=UtilArray::arrayDiff($a1,$a2); +print_r($result); +print "hi"; +*/ \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php index c0c4b9909..8fa9cb409 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php @@ -8,23 +8,20 @@ class UtilFile { if (! is_dir($dirPath)) { - throw new InvalidArgumentException("$dirPath must be a directory"); + unlink($dirPath); + return; } + if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } + $files = glob($dirPath . '*', GLOB_MARK); + foreach ($files as $file) { - if (is_dir($file)) - { - self::deleteDir($file); - } - else - { - unlink($file); - } + self::deleteDir($file); } rmdir($dirPath); } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilTeleport.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilTeleport.php new file mode 100644 index 000000000..bc414ac2e --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilTeleport.php @@ -0,0 +1,47 @@ +getPosition(); + + // + // This CRAZY HACK is to remove Tile entities that seem to linger + // whenever you teleport! + // + + if ($current->getLevel() != $position->getLevel()) { + $player->noDamageTicks = 20; + foreach ($current->getLevel()->getTiles() as $tile) { + $pk = new UpdateBlockPacket(); + $pk->x = $tile->x; + $pk->y = $tile->y; + $pk->z = $tile->z; + $pk->block = 0; + $pk->meta = 0; + $player->dataPacket($pk); + } + } + $player->teleport($position); // Start the teleport + return true; + } +} \ No newline at end of file