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.

UHCWorld.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. # _ _ _ _ _____
  3. # | | | | | | |/ ____|
  4. # | | | | |__| | |
  5. # | | | | __ | |
  6. # | |__| | | | | |____
  7. # \____/|_| |_|\_____|
  8. # The most customisable UHC plugin for Minecraft PE!
  9. namespace Ad5001\UHC ;
  10. use pocketmine\command\CommandSender;
  11. use pocketmine\command\Command;
  12. use pocketmine\event\Listener;
  13. use pocketmine\Server;
  14. use pocketmine\level\Level;
  15. use pocketmine\plugin\Plugin;
  16. use pocketmine\level\particle\FloatingTextParticle;
  17. use pocketmine\Player;
  18. use pocketmine\utils\TextFormat as C;
  19. use pocketmine\math\Vector3;
  20. use Ad5001\UHC\Main;
  21. use Ad5001\UHC\scenario\ScenarioManager;
  22. class UHCWorld implements Listener {
  23. public function __construct(Plugin $main, Level $level, int $maxplayers, int $radius) {
  24. $this->p = $main;
  25. $this->lvl = $level;
  26. $this->maxplayers = $maxplayers;
  27. $this->players = [];
  28. $this->cfg = $main->getConfig();
  29. $this->radius = $radius;
  30. $main->getServer()->getPluginManager()->registerEvents($this, $main);
  31. $this->scenarioManager = new ScenarioManager($this->p, $this);
  32. }
  33. public function getLevel() {
  34. return $this->lvl;
  35. }
  36. public function isStarted() {
  37. return isset($this->p->UHCManager->getStartedUHCs()[$this->lvl->getName()]);
  38. }
  39. public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
  40. if(!$this->isStarted()) {
  41. $event->setCancelled();
  42. }
  43. }
  44. public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
  45. if(!$this->isStarted()) {
  46. if(!$event->getPlayer()->isCreative()) {
  47. $event->setCancelled();
  48. }
  49. }
  50. }
  51. public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
  52. if(!$this->isStarted()) {
  53. if(!$event->getPlayer()->isCreative()) {
  54. $event->setCancelled();
  55. }
  56. }
  57. }
  58. public function getPlayers() {
  59. return $this->players;
  60. }
  61. public function getName() {
  62. return $this->lvl->getName();
  63. }
  64. public function getMaxPlayers() {
  65. return $this->maxplayers;
  66. }
  67. public function setPlayers(array $players) {
  68. foreach($this->players as $key => $player) {
  69. if(!in_array($player, $this->players)){
  70. $player->sendMessage(Main::PREFIX . C::YELLOW . "You joined the game.");
  71. foreach($this->players as $pl) {
  72. $pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} joined the game.");
  73. $this->getLevel()->addParticle($part = new FloatingTextParticle(new Vector3($this->getLevel()->getSafeSpawn()->x, $this->getLevel()->getSafeSpawn()->y, $this->getLevel()->getSafeSpawn()->z), C::GREEN . "Welcome to the UHC game, {$player->getName()}!\n" . C::GREEN . "Need help? Use /uhc howtoplay.", C::YELLOW . "-=<UHC>=-"), [$player]);
  74. }
  75. }
  76. }
  77. foreach($players as $player) {
  78. if(!in_array($player, $players)){
  79. $player->sendMessage(Main::PREFIX . C::YELLOW . "You left the game.");
  80. foreach($this->players as $pl) {
  81. $pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} left the game.");
  82. }
  83. }
  84. }
  85. $this->players = $players;
  86. return true;
  87. }
  88. }