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.

UHCManager.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Ad5001\UHC;
  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\task\StartGameTask;
  14. class UHCManager {
  15. protected $main;
  16. protected $server;
  17. protected $games;
  18. protected $levels;
  19. protected $startedgames;
  20. public function __construct(Main $main) {
  21. $this->main = $main;
  22. $this->server = $main->getServer();
  23. $this->games = [];
  24. $this->levels = [];
  25. $this->startedgames = [];
  26. }
  27. public function startUHC(Level $level) {
  28. if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) {
  29. $ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20);
  30. $t->setHandler($ft);
  31. $this->startedgames[$level->getName()] = true;
  32. foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) {
  33. $sc->onStart();
  34. }
  35. return true;
  36. }
  37. return false;
  38. }
  39. public function stopUHC(Level $level, Player $player) {
  40. if(isset($this->startedgames[$level->getName()])) {
  41. foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) {
  42. $sc->onStop($player);
  43. }
  44. $started = [];
  45. foreach($this->startedgames as $name => $game) {
  46. if($name !== $level->getName()) {
  47. $started[$name] = $game;
  48. }
  49. }
  50. $this->startedgames = $started;
  51. $this->main->getLogger()->info("Game " . $level->getName() . " stoped");
  52. return true;
  53. }
  54. return false;
  55. }
  56. public function registerLevel(Level $level) {
  57. if(!array_key_exists($level->getName(), $this->levels)) {
  58. $this->levels[$level->getName()] = new UHCWorld($this->main,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]);
  59. }
  60. }
  61. public function getLevels() {
  62. return $this->levels;
  63. }
  64. public function getStartedUHCs() {
  65. return $this->startedgames;
  66. }
  67. public function addStartedUHC(string $name, UHCGame $game) {
  68. $this->startedgames[$name] = $game;
  69. return true;
  70. }
  71. }