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.

111 lines
3.6 KiB

  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;
  20. use pocketmine\command\CommandSender;
  21. use pocketmine\command\Command;
  22. use pocketmine\event\Listener;
  23. use pocketmine\plugin\PluginBase;
  24. use pocketmine\level\generator\Generator;
  25. use pocketmine\Server;
  26. use pocketmine\Player;
  27. use pocketmine\level\Position;
  28. use pocketmine\entity\Effect;
  29. use Ad5001\Spherable\generators\spheres\SpheresGenerator;
  30. use Ad5001\Spherable\commands\sphgenCommand;
  31. class Main extends PluginBase implements Listener{
  32. public $playersResist = [];
  33. /**
  34. * When the plugin enables
  35. *
  36. * @return void
  37. */
  38. public function onEnable(){
  39. Generator::addGenerator(SpheresGenerator::class, "spheres");
  40. $this->getServer()->getCommandMap()->register("sphgen", new sphgenCommand($this));
  41. $this->getServer()->getPluginManager()->registerEvents($this, $this);
  42. }
  43. /**
  44. */
  45. public function onEntityLevelChange(\pocketmine\event\entity\EntityLevelChangeEvent $event){
  46. if($event->getTarget()->getProvider()->getGenerator() == "spheres" && $event->getEntity() instanceof Player){
  47. $event->getEntity()->setSpawn(new Position(264, 255, 264, $event->getTarget()));
  48. }
  49. }
  50. /**
  51. */
  52. public function onRespawn(\pocketmine\event\player\PlayerRespawnEvent $event){
  53. if($event->getPlayer()->getLevel()->getProvider()->getGenerator() == "spheres"){
  54. $this->playersResist[$event->getPlayer()->getName()] = time();
  55. $event->getPlayer()->sendMessage("You are resistant for 30 seconds. Profit to go back to your last death point.");
  56. }
  57. }
  58. /**
  59. */
  60. public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event){
  61. if($event->getEntity()->getLevel()->getProvider()->getGenerator() == "spheres" &&
  62. $event->getEntity() instanceof Player &&
  63. isset($this->playersResist[$event->getEntity()->getName()]) &&
  64. $this->playersResist[$event->getEntity()->getName()] > time() - 30){
  65. $event->setCancelled();
  66. }
  67. }
  68. /**
  69. */
  70. public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event){
  71. if($event->getBlock()->getLevel()->getProvider()->getGenerator() == "spheres"){
  72. if($event->getBlock()->getId() == 56){
  73. $diamonds_count = 1;
  74. foreach($event->getPlayer()->getInventory()->getContents() as $item){
  75. $diamonds_count += $item->getCount();
  76. }
  77. if($diamonds_count % 64 == 0 && $this->getServer()->getPluginManager()->getPlugin("PSMCore") !== null){
  78. \Ad5001\PSMCore\API::displayNotification("Diamonds !", $event->getPlayer()->getName() . " has mined " . ($diamonds_count / 64) . " stacks of diamond!", [], "none");
  79. }
  80. }
  81. }
  82. }
  83. /**
  84. */
  85. public function onJoin(\pocketmine\event\player\PlayerJoinEvent $event){
  86. if($event->getPlayer()->getLevel()->getProvider()->getGenerator() == "spheres"){
  87. $event->getPlayer()->setSpawn(new Position(264, 255, 264, $event->getPlayer()->getLevel()));
  88. }
  89. }
  90. }