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

Solved PlayerInteractEvent

Discussion in 'Development' started by Mystic30, Oct 12, 2017.

  1. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    Hello, i want to add a command to an item that when they "tap" on ground, the "test" command will execute. Here is my code, it doesnt work
    PHP:
    public function onInteraction(PlayerInteractEvent $event){
                                if(
    $event->getItem()->getId()==347){
                                            
    $command "test";
                            
    $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command);
                                }
        }
     
  2. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Don't just say "it doesnt work", tell us some info and errors so we can understand the problem more,
    Did you register events listener by
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    Is there more code, maybe the problem is with that code, who knows
     
  3. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    I tried to add the code to MSpawns on command hub so when the player did /hub, they will be given clock and when they interact to it, the UI will popup.
     
  4. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Did you register the events listener? Are you sure the "test" command works?

    your code seems fine to me, i really don't know whats the problem
     
  5. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
  6. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    PHP:
    <?php

    /*
     * MSpawns (v1.5) by EvolSoft
     * Developer: EvolSoft (Flavius12)
     * Website: http://www.evolsoft.tk
     * Date: 27/12/2014 01:26 PM (UTC)
     * Copyright & License: (C) 2014-2017 EvolSoft
     * Licensed under MIT (https://github.com/EvolSoft/MSpawns/blob/master/LICENSE)
     */

    namespace MSpawns\Commands;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\permission\Permission;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\player\PlayerInteractEvent;

    use 
    MSpawns\Main;

    class 
    Hub extends PluginBase implements CommandExecutor{
      
        public function 
    __construct(Main $plugin){
            
    $this->plugin $plugin;
        }
      
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool{
            switch(
    strtolower($cmd->getName())){
                    case 
    "hub":
                        if(
    $sender instanceof Player){
                            if(
    $sender->hasPermission("mspawns.hub")){
                                
    $this->plugin->teleportToHub($sender);
                                        
    $sender->getInventory()->setItem(0Item::get(34701));
                                return 
    true;
                            }
                            else{
                                
    $sender->sendMessage($this->plugin->translateColors("&""&cYou don't have permissions to use this command"));
                                return 
    true;
                            }
                        }else{
                            
    $sender->sendMessage($this->plugin->translateColors("&"Main::pREFIX "&cYou can only perform this command as a player"));
                            return 
    true;
                        }
                        break;
                }
            return 
    true;
        }
      
    }
        function 
    onInteraction(PlayerInteractEvent $event){
                                if(
    $event->getItem()->getId()==347){
                                            
    $command "test";
                            
    $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command);
                                }
        }
     
  7. Aviv

    Aviv Baby Zombie

    Messages:
    156
    there is no "test" command...
    if there is, please show
     
  8. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    Its the MSpawns codes, i just added the PlayerInteractionEvent
     
  9. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    and the "test" command to execute UI
     
  10. Aviv

    Aviv Baby Zombie

    Messages:
    156
    How did you handle the test command?
    Did you register the command from the plugin.yml?
     
  11. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    Wait wait,, ill explain, I made an UI (Custom UI) and there is a command to popup the UI and that is "test", now ,i want players to have a clock (Server selector) so when they "/hub" and when they tap the ground using the clock, the clock will execute a command to popup the UI
     
  12. Aviv

    Aviv Baby Zombie

    Messages:
    156
    I already know that, please answear my questions
     
  13. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    This?
    PHP:
    permissions:
        
    cui.command:
        default: 
    true
     
  14. Aviv

    Aviv Baby Zombie

    Messages:
    156
    and
    PHP:
    commands:
      
    test:
        
    permissioncui.command
     
  15. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    Here?
    PHP:
    commands:
      
    test:
        
    permissioncui.command
      permissions
    :
        
    cui.command:
        default: 
    true
     
  16. Aviv

    Aviv Baby Zombie

    Messages:
    156
    in the plugin yml
    PHP:
    commands:
      
    test:
        
    permissioncui.command
    permissions
    :
      
    cui.command:
        default: 
    true
    Now lets stop spamming... ask questions that are important
     
  17. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    yes,,its on my plugin.yml , but it doesnt work,,and when i try "/cui test" in a non-op player, they have no permission even ive already add a perm to them
     
  18. Aviv

    Aviv Baby Zombie

    Messages:
    156
    WAS IT /CUI TEST THE WHOLE TIME?
    dude I suggest you think about the problem before making a thread, and start explaining deeper, because i wont help you next time
    PHP:
    $command "cui test";
    $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command);
    If that doesn't work i will stop helping you until you explain EVERYTHING (errors, code, etc..)
     
    Last edited: Oct 12, 2017
    jasonwynn10 and Mystic30 like this.
  19. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    the "test" command i show you is just an example or TEST, its not the real command.. the real command is "cui test". now, my thread is about the "PlayerInteractEvent" that the clock is not executing the command even the code is
    PHP:
    public function onInteraction(PlayerInteractEvent $event){
                                if(
    $event->getItem()->getId()==347){
                                            
    $command "cui test";
                            
    $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command);
                                }
        }
    but when i tap on ground using the clock, its not working..
     
  20. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    i know its very confusing,
     
    armagadon159753 likes this.
  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.