A spheres world generator. A new survival challenge.
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.

sphgenCommand.php 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /***
  3. * ____ _ _ _
  4. * / ___| _ __ | |__ ___ _ __ __ _ | |__ | | ___
  5. * \___ \ | '_ \ | '_ \ / _ \| '__|/ _` || '_ \ | | / _ \
  6. * ___) || |_) || | | || __/| | | (_| || |_) || || __/
  7. * |____/ | .__/ |_| |_| \___||_| \__,_||_.__/ |_| \___|
  8. * |_|
  9. *
  10. * Spheres world generator. A new survival challenge.
  11. * @author Ad5001 <mail@ad5001.eu>
  12. * @copyright (C) 2017 Ad5001
  13. * @license NTOSL (View LICENSE.md)
  14. * @package Spherical
  15. * @version 1.0.0
  16. * @link https://download.ad5001.eu/en/view.php?name=Spherable&src=github
  17. */
  18. declare(strict_types = 1);
  19. namespace Ad5001\Spherable\commands;
  20. use pocketmine\Server;
  21. use pocketmine\Player;
  22. use pocketmine\command\Command;
  23. use pocketmine\command\CommandSender;
  24. use pocketmine\level\Position;
  25. use pocketmine\block\Block;
  26. use pocketmine\math\Vector3;
  27. use pocketmine\entity\Effect;
  28. use Ad5001\Spherable\Main;
  29. use Ad5001\Spherable\generators\spheres\SpheresGenerator;
  30. class sphgenCommand extends Command{
  31. /**
  32. * Constructs the class
  33. *
  34. * @param Main $main
  35. */
  36. public function __construct(Main $main){
  37. $this->main = $main;
  38. parent::__construct("sphgen", "Spheres games base command", "/sphgen <createworld|join|tp> <world name> [player]");
  39. $this->setPermission("sphereable.cmd.join");
  40. $this->setUsage("§4§o[§r§4Usage§o§4]§r§4 /sphgen <createworld|join|tp> <world name>[player]");
  41. }
  42. /**
  43. * When the command is executed
  44. *
  45. * @param CommandSender $sender
  46. * @param string $commandLabel
  47. * @param array $args
  48. * @return bool
  49. */
  50. public function execute(CommandSender $sender, string $commandLabel, array $args): bool {
  51. if(count($args) < 2){
  52. $this->setUsage("§4§o[§r§4Usage§o§4]§r§4 /sphgen <createworld|join|tp> <world name> [player]");
  53. return true;
  54. }
  55. switch($args[0]){
  56. case "createworld":
  57. case "cw":
  58. if(!$sender->hasPermission("sphereable.cmd.createworld")){
  59. $sender->sendMessage("§4§o[§r§4Permission§o§4]§r§4 You don't have the permission to execute this command. If you believe this is an error, please contact the server administrator.");
  60. return true;
  61. }
  62. Server::getInstance()->generateLevel($args[1],
  63. (int) round(rand(0, (int) (round(time() / memory_get_usage(true)) * (int) str_shuffle("127469453645108") / (int) str_shuffle("12746945364"))))
  64. , SpheresGenerator::class , []);
  65. Server::getInstance()->loadLevel($args[1]);
  66. $sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Generating world $args[1]...");
  67. if(Server::getInstance()->getPluginManager()->getPlugin("PSMCore") !== null){
  68. \Ad5001\PSMCore\API::addPlayerAction('Tp to challenge world "' . $args[1] . '"', "sphgen tp {$args[1]} %p");
  69. }
  70. break;
  71. case "join":
  72. case "j":
  73. if(file_exists(Server::getInstance()->getDataPath() . "worlds/{$args[1]}/level.dat")){
  74. if(Server::getInstance()->getLevelByName($args[1]) == null){
  75. Server::getInstance()->loadLevel($args[1]);
  76. }
  77. if(Server::getInstance()->getLevelByName($args[1])->getProvider()->getGenerator() == "spheres"){
  78. $sender->teleport(new Position(264, 256, 264,Server::getInstance()->getLevelByName($args[1])));
  79. $effect = Effect::getEffectByName("resistance");
  80. $effect->setDuration(600);
  81. $effect->setAmplifier(99);
  82. $effect->setVisible(false);
  83. $sender->addEffect($effect);
  84. $sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Teleporting to challenge world $args[1]...");
  85. } else {
  86. $sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
  87. }
  88. } else {
  89. $sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
  90. }
  91. break;
  92. case "tp":
  93. if(!$sender->hasPermission("sphereable.cmd.tp")){
  94. $sender->sendMessage("§4§o[§r§4Permission§o§4]§r§4 You don't have the permission to execute this command. If you believe this is an error, please contact the server administrator.");
  95. return true;
  96. }
  97. if(count($args) < 3){
  98. $sender->sendMessage("§4§o[§r§4Usage§o§4]§r§4 /sphgen $args[0] <world name> <player>");
  99. return true;
  100. }
  101. if(file_exists(Server::getInstance()->getDataPath() . "worlds/{$args[1]}/level.dat")){
  102. if(Server::getInstance()->getLevelByName($args[1]) == null){
  103. Server::getInstance()->loadLevel($args[1]);
  104. }
  105. if(Server::getInstance()->getLevelByName($args[1])->getProvider()->getGenerator() == "spheres"){
  106. if(Server::getInstance()->getPlayer($args[2]) == null) {
  107. $sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Player $args[2] doesn't exists or isn't connected.");
  108. return true;
  109. }
  110. $player = Server::getInstance()->getPlayer($args[2]);
  111. $player->teleport(new Position(264, 256, 264,Server::getInstance()->getLevelByName($args[1])));
  112. $effect = Effect::getEffectByName("resistance");
  113. $effect->setDuration(600);
  114. $effect->setAmplifier(99);
  115. $effect->setVisible(false);
  116. $player->addEffect($effect);
  117. $player->sendMessage("§a§o[§r§aSuccess§o§a]§r§a {$sender->getName()} teleported you to to challenge world $args[1]...");
  118. $sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Teleporting $args[2] to challenge world $args[1]...");
  119. } else {
  120. $sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
  121. }
  122. } else {
  123. $sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
  124. }
  125. break;
  126. }
  127. return true;
  128. }
  129. /**
  130. * Generates custom data for command
  131. *
  132. * @param Player $player
  133. * @return array
  134. */
  135. public function generateCustomCommandData(Player $player): array {
  136. $cmdData = parent::generateCustomCommandData($player);
  137. $cmdData["permission"] = "sphereable.cmd.join";
  138. $cmdData["aliases"] = [];
  139. $cmdData["overloads"]["default"]["input"]["parameters"] = [
  140. 0 => [
  141. "type" => "stringenum",
  142. "name" => "subcmd",
  143. "optional" => false,
  144. "enum_values" => [
  145. "createworld",
  146. "cw",
  147. "join",
  148. "j",
  149. ]
  150. ],
  151. 1 => [
  152. "type" => "string",
  153. "name" => "world",
  154. "optional" => false
  155. ],
  156. 2 => [
  157. "type" => "string",
  158. "name" => "player",
  159. "optional" => true
  160. ]
  161. ];
  162. return $cmdData;
  163. }
  164. }