1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Join Inventory

Discussion in 'Development' started by Notjblus, Jun 18, 2019.

  1. Notjblus

    Notjblus Spider Jockey

    Messages:
    28
    GitHub:
    JblusItsMe
    Hey,

    I would like to know how to add an item in an inventory to each join of the server (for example a bousole in slot 5) and make it clickable to execute a command, how to put it in a code below:
    PHP:
    <?php

    namespace DevJblus;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\Utils;
    use 
    pocketmine\plugin\PluginBase as Plugins;
    use 
    DevJblus\Loader;

    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info("§7========== §eJoinServer §7==========");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7> §aEnable plugins by DevJblus");
            
    $this->getServer()->getLogger()->info("§7> §aLoading all package");
            
    $this->getServer()->getLogger()->info("§7> §aOpen server ...");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7================================");
        }
        
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("§7========== §eJoinServer §7==========");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7> §cDisable plugins by DevJblus");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7================================");
        }
        
        public function 
    onPlayerJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $event->setJoinMessage("§7[§a+§7] " $player->getName());
        }

        public function 
    onPlayerQuit(PlayerQuitEvent $event) {
            
    $player $event->getPlayer();
            
    $event->setQuitMessage("§7[§c-§7] " $player->getName());
        }

        public function 
    onPlayerLogin(PlayerLoginEvent $event){
            
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
        }
    }
     
  2. Flow

    Flow Silverfish

    Messages:
    22
    use PlayerJoinEvent to add a item

    $player->getInventory()->setItem(5, Item::get(Item::COMPASS));
     
  3. Flow

    Flow Silverfish

    Messages:
    22
    PHP:
    Notjblus
    Notjblus
    Creeper
    New
    Hey,

    I would like to know how to add an item in an inventory to each join of the server (for example a bousole in slot 5) and make it clickable to execute a command, how to put it in a code below:
    PHP:
    <?php

    namespace DevJblus;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\Utils;
    use 
    pocketmine\plugin\PluginBase as Plugins;
    use 
    DevJblus\Loader;

    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info("§7========== §eJoinServer §7==========");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7> §aEnable plugins by DevJblus");
            
    $this->getServer()->getLogger()->info("§7> §aLoading all package");
            
    $this->getServer()->getLogger()->info("§7> §aOpen server ...");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7================================");
        }
       
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("§7========== §eJoinServer §7==========");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7> §cDisable plugins by DevJblus");
            
    $this->getServer()->getLogger()->info("§7   ");
            
    $this->getServer()->getLogger()->info("§7================================");
        }
       
        public function 
    onPlayerJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $player->getInventory()->setItem(6Item::get(Item::COMPASS))->setCustomName("Boussole");
            
    $event->setJoinMessage("§7[§a+§7] " $player->getName());
        }

        public function 
    onPlayerQuit(PlayerQuitEvent $event) {
            
    $player $event->getPlayer();
            
    $event->setQuitMessage("§7[§c-§7] " $player->getName());
        }

        public function 
    onPlayerLogin(PlayerLoginEvent $event){
            
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
        }
    }

        public function 
    onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        if(
    $p->getInventory()->getItemInHand()->getCustomName() == "Boussole"){
        
    $player->sendMessage("réussi !");
      }
    }
     
  4. Flow

    Flow Silverfish

    Messages:
    22
    Genre tu mets bien l'accolade (j'avais la flemme la.)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.