SHARE
TWEET

Untitled

a guest Nov 19th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace CompassTeleport;
  4.  
  5. use jojoe77777\FormAPI\FormAPI;
  6. use pocketmine\event\entity\EntityLevelChangeEvent;
  7. use pocketmine\event\Listener;
  8. use pocketmine\event\player\PlayerInteractEvent;
  9. use pocketmine\event\player\PlayerJoinEvent;
  10. use pocketmine\event\player\PlayerRespawnEvent;
  11. use pocketmine\item\Item;
  12. use pocketmine\Player;
  13. use pocketmine\plugin\PluginBase;
  14.  
  15. class Main extends PluginBase implements Listener{
  16.  
  17.     public function onEnable() : void{
  18.         $this->saveDefaultConfig();
  19.         $this->getServer()->getPluginManager()->registerEvents($this, $this);
  20.     }
  21.  
  22.     public function onDisable() : void{
  23.  
  24.     }
  25.  
  26.     public function onInteract(PlayerInteractEvent $event) : void{
  27.         if(($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR or $event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) and in_array($event->getPlayer()->getLevel()->getFolderName(), $this->getConfig()->get("worlds")) and $event->getItem()->getId() === Item::COMPASS){
  28.             $form = $this->getFormAPI()->createSimpleForm(function(Player $player, $sel){
  29.                 if($sel === null) return;
  30.                 $button = $this->getConfig()->get("buttons");
  31.                 $player->teleport($this->getServer()->getLevelByName($button[$sel]["level"])->getSpawnLocation());
  32.             });
  33.             $form->setTitle($this->getConfig()->get("title"));
  34.             $form->setContent($this->getConfig()->get("content"));
  35.             foreach($this->getConfig()->get("buttons") as $button){
  36.                 $button["hasimage"] ? $form->addButton($button["text"], $button["imagetype"] === "url" ? 1 : 0, $button["path"]) : $form->addButton($button["text"]);
  37.             }
  38.             $form->sendToPlayer($event->getPlayer());
  39.         }
  40.     }
  41.  
  42.     public function onJoin(PlayerJoinEvent $event) : void{
  43.         if(in_array($event->getPlayer()->getLevel()->getFolderName(), $this->getConfig()->get("worlds"))){
  44.             $event->getPlayer()->getInventory()->setContents([Item::get(Item::COMPASS, 0, 1)->setCustomName($this->getConfig()->get("item-name"))]);
  45.         }
  46.     }
  47.  
  48.     public function onRespawn(PlayerRespawnEvent $event) : void{
  49.         if(in_array($event->getPlayer()->getLevel()->getFolderName(), $this->getConfig()->get("worlds"))){
  50.             $event->getPlayer()->getInventory()->setContents([Item::get(Item::COMPASS, 0, 1)->setCustomName($this->getConfig()->get("item-name"))]);
  51.         }
  52.     }
  53.  
  54.     public function onLevelChange(EntityLevelChangeEvent $event) : void{
  55.         if(($entity = $event->getEntity()) instanceof Player){
  56.             if(in_array($entity->getLevel()->getFolderName(), $this->getConfig()->get("worlds"))){
  57.                 $entity->getInventory()->setContents([Item::get(Item::COMPASS, 0, 1)->setCustomName($this->getConfig()->get("item-name"))]);
  58.             }
  59.         }
  60.     }
  61.  
  62.     public function getFormAPI() : FormAPI{
  63.         return $this->getServer()->getPluginManager()->getPlugin("FormAPI");
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top