An highly customisable UHC plugin for PocketMine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScenarioManager.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Ad5001\UHC\scenario;
  3. # _ _ _ _ _____
  4. # | | | | | | |/ ____|
  5. # | | | | |__| | |
  6. # | | | | __ | |
  7. # | |__| | | | | |____
  8. # \____/|_| |_|\_____|
  9. # The most customisable UHC plugin for Minecraft PE !
  10. use pocketmine\Server;
  11. use pocketmine\Player;
  12. use pocketmine\level\Level;
  13. use Ad5001\UHC\Main;
  14. use Ad5001\UHC\UHCWorld;
  15. use Ad5001\UHC\UHCGame;
  16. class ScenarioManager {
  17. protected $main;
  18. protected $server;
  19. protected $scenarios;
  20. protected $level;
  21. protected $usedscenarios;
  22. public function __construct(Main $main, UHCWorld $game) {
  23. $this->main = $main;
  24. $this->server = $main->getServer();
  25. $files = array_diff(scandir($main->getDataFolder() . "scenarios"), [".", ".."]);
  26. $this->scenarios = [];
  27. $this->level = $game;
  28. $this->usedscenarios = [];
  29. foreach ($files as $file) {
  30. if(!is_dir($this->main->getDataFolder() . "scenarios/" . $file)) {
  31. require($this->main->getDataFolder() . "scenarios/" . $file);
  32. $classn = $this->main->getClasses(file_get_contents($this->main->getDataFolder() . "scenarios/" . $file));
  33. $this->scenarios[explode("\\", $classn)[count(explode("\\", $classn)) - 1]] = $classn;
  34. @mkdir($this->main->getDataFolder() . "scenarios/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]);
  35. }
  36. }
  37. if(isset($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])) {
  38. if(is_array($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])){
  39. foreach($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"] as $sc) {
  40. $this->addScenario($sc);
  41. }
  42. }
  43. }
  44. }
  45. public function addScenario(string $name) {
  46. if(!isset($this->usedscenarios[$name]) and !$this->level->isStarted()) {
  47. $this->usedscenarios[$name] = new $name($this->server, $this->level);
  48. return true;
  49. }
  50. return false;
  51. }
  52. public function rmScenario(string $name) {
  53. if(isset($this->usedscenarios[$name]) and !$this->level->isStarted()) {
  54. unset($this->usedscenarios[$name]);
  55. $this->levels[$level->getName()]->onGameStop();
  56. return true;
  57. }
  58. return false;
  59. }
  60. public function getLevel() {
  61. return $this->level;
  62. }
  63. public function getScenarios() {
  64. return $this->scenarios;
  65. }
  66. public function getUsedScenarios() {
  67. return $this->usedscenarios;
  68. }
  69. }