Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get this to work?

Comments in 'Plugin Development' started by Hittmana, Jan 28, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Have been working all night on a new plugin and it doesn't seem to work. Whenever i do /trade Hittmana and then do /tradeaccept it doesn't work. /trade Hittmana works but not /tradeaccept . Here is the error:

    2016-01-27 [19:16:45] [Server thread/CRITICAL]: Unhandled exception executing command 'tradeaccept' in tradeaccept: Undefined variable: traderequest
    2016-01-27 [19:16:45] [Server thread/NOTICE]: UndefinedVariableException: "Undefined variable: traderequest" (E_NOTICE) in "/tradeProv0.2.3.phar/src/Hittmana/TradePro/MainClass" at line 42

    Can someone help me with this?

    Attached Files:

  2. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    im using my ipad, so correct me if im wrong.

    idea, not fact: you didnt end the line
    " if ($traderequest == 1)" with a ;
  3. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    you don't end if statements with ; do you?
  4. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    now that i think about it... nahh. (am i that tired?!?) ill check it again
  5. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    my app doesnt show plugin.yml. can you show it here please?
  6. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Well... apparently code checkers dont like you saying ":("(at the end)

    sooo what ive done, is fixed some eye-sours of typos. (If you dont like it, ignore this :3.

    PHP:
    <?php
    namespace Hittmana\TradePro;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\TranslationContainer;
    use 
    pocketmine\utils\TextFormat;
    class 
    MainClass extends PluginBase implements Listener 
    {
        public function 
    onEnable()
        {
            
    $this->getLogger()->info("Test enabled");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onDisable()
        {
            
    $this->getLogger()->info("Test disabled");
        }
    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
        if(
    $sender instanceof Player) {
             
    $name $sender->getName();
             if (
    $command->getName() == "trade"
             {
                
    $this->getLogger()->info("IT WORKS!!" $name "USED IT!!!!");
                
    $recipient $this->getServer()->getPlayer($args[0]);
                 if(
    $recipient instanceof Player){
                
    $trader $sender->getName();
                
    $recipient->sendMessage($trader " wants to trade with you!");  
                
    $sender->sendMessage("You sent a trade request " $recipient ". Lets hope they say YES!");
                
    $traderequest 1;
                return 
    true;
                }
                else {
                    
    $sender->sendMessage("Player not found");}
        }
             if (
    $command->getName() == "tradeaccept"){
       if (
    $traderequest == 1){
       
    $sender->sendMessage("You accepted trade request from " $trader);
       
    $originaltrader $this->getServer()->getPlayer($args[0]);
       
    $originaltrader->sendMessage($sender "accepted!");
       }
          else  { 
       
    $sender->sendMessage("You dont have a trade request silly XD");
          }
          }
          } 
        else
        {
        
    $this->getLogger()->info("Command must be run in-game" );
    /**ingame does mean player**/
        
    return false;
       }
          }
    }
  7. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Very interesting I will keep this in mind and thanks!
  8. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Still need it?
  9. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Still getting this error:
    2016-01-27 [21:40:31] [Server thread/CRITICAL]: Unhandled exception executing command 'tradeaccept' in tradeaccept: Undefined variable: traderequest
    2016-01-27 [21:40:31] [Server thread/NOTICE]: UndefinedVariableException: "Undefined variable: traderequest" (E_NOTICE) in "/tradeProv0.2.4.phar/src/Hittmana/TradePro/MainClass" at line 39
  10. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    ive just realised how tired i was last night, so i believe some of my posts are now void.
  11. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I already tried that i had:
    $traderequest = 1;
    and it didn't work, it said it was undefined.
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    <?php
    namespace Hittmana\TradePro;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\TranslationContainer;
    use 
    pocketmine\utils\TextFormat;
    class 
    MainClass extends PluginBase implements Listener 
    {
        public 
    $traderequests = [];

        public function 
    onEnable()
        {
            
    $this->getLogger()->info("Test enabled");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onDisable()
        {
            
    $this->getLogger()->info("Test disabled");
        }
    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
        if(
    $sender instanceof Player) {
             
    $name $sender->getName();
             if (
    $command->getName() == "trade"
             {
                
    $this->getLogger()->info("IT WORKS!!" $name "USED IT!!!!");
                
    $recipient $this->getServer()->getPlayer($args[0]);
                 if(
    $recipient instanceof Player){
                
    $trader $sender->getName();
                
    $recipient->sendMessage($trader " wants to trade with you!");  
                
    $sender->sendMessage("You sent a trade request to"  $recipient->getName() . ". Lets hope they say YES!");
                
    $this->traderequests[$recipient->getName()]= $sender;
                return 
    true;
                }
                else {
                    
    $sender->sendMessage("Player not found");}
        }
             if (
    $command->getName() == "tradeaccept"){
       if (isset(
    $this->traderequests[$sender->getName()]) and ($trader $this->traderequests[$sender->getName()]) instanceof Player){
       
    $sender->sendMessage("You accepted trade request from " $trader->getName());
       
    $trader->sendMessage($sender->getName() . "accepted!");
        unset(
    $this->traderequests[$sender->getName());
       }
          else  { 
       
    $sender->sendMessage("You dont have a trade request silly XD");
          }
          }
          } 
        else
        {
        
    $this->getLogger()->info("Command must be run in-game" );
    /**ingame does mean player**/
        
    return false;
       }
          }
    }
    Try this, you can't use non global variables across functions which means you can't use them the next time the functions called. All I've done is add the requests to a global array, you should compare the changes so you understand.
  13. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ok thanks!
  14. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    PHP:
    if(($recipient instanceof Player){
       
    $trader $recipient->getName(); <------ remove $sender   
                    $recipient
    ->sendMessage($trader " wants to trade with you!"); 
                
    $sender->sendMessage("You sent a trade request " $recipient ". Lets hope he says YES!");
    //blah blah blah .... Your code
  15. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    First off, your passing a player object as a string, second off, why do we need to unset $sender?

    edit
    You've also got an un-closed bracket in the first if statment.
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Invalid argument exception foreach on CommandExecutor, expected array.
    Ritch likes this.
  17. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Oh :/ sorry
  18. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Please think before posting, please.
    TheDeibo likes this.
  19. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ok so the giving and taking of items doesn't work. Here is error:

    2016-01-28 [20:24:51] [Server thread/CRITICAL]: Unhandled exception executing command 'tradeaccept Hittmana' in tradeaccept: Class Hittmana\TradePro\Item not found
    2016-01-28 [20:24:51] [Server thread/CRITICAL]: ClassNotFoundException: "Class Hittmana\TradePro\Item not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144

    Here is code:
    PHP:
    <?php
    namespace Hittmana\TradePro;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\TranslationContainer;
    use 
    pocketmine\utils\TextFormat;
    class 
    MainClass extends PluginBase implements Listener
    {
        public function 
    onEnable()
            {
            
    $this->getLogger()->info("TradePro enabled v0.3.0");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
        public function 
    onDisable()
            {
            
    $this->getLogger()->info("TradePro disabled v0.3.0");
            }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
            {
            if(
    $sender instanceof Player)
            {
                
    $name $sender->getName();
                    if (
    $command->getName() == "trade")
                    {
                        
    $this->getLogger()->info("[TradePro]" "IT WORKS!!" $name "USED IT!!!!");
                        
    $recipient $this->getServer()->getPlayer($args[0]);
                        if(
    $recipient instanceof Player)
                            {
                                
    $trader $sender->getName();
                                
    $recipient->sendMessage("[TradePro]" $trader " wants to trade with you!"); 
                                
    $sender->sendMessage("[TradePro]" "You sent a trade request " $recipient ". Lets hope they say YES!");
                                
    $item1 $args[1];
                                
    $amount1 $args[2];
                                
    $item2 $args[3];
                                
    $amount2 $args[4];
                                return 
    true;
                            }
                            else
                            {
                                
    $sender->sendMessage("Player not found");
                                return 
    false;
                            
    // /trade 0<player> 1<item youll trade> 2<amount youll trade> 3<what you want> 4<amount you want>
                            
    }
                    }
                if (
    $command->getName() == "tradeaccept")
                    {
                        
    $trader $this->getServer()->getPlayer($args[0]);
                        
    $sender->sendMessage("[TradePro]" "You accepted trade request from " $trader);
                        
    $trader->sendMessage("[TradePro]" $sender " accepted!");
                        
    $player $sender;
                        
    $player->getInventory()->setItem(0Item::get($item1,0,$amount1));
                        
    $this->getServer()->getPlayer($trader)->getInventory()->remove(Item::get($item10$amount1));
                        
    $trader->sendMessage("[TradePro]" "You traded " $item1 "x" $amount1 "with " $player); 
                        
    $player->sendMessage("[TradePro]" "You traded " $item2 "x" $amount2 "with " $trader);
                        
    $trader->getInventory()->setItem(0Item::get($item2,0,$amount2));
                        
    $this->getServer()->getPlayer($player)->getInventory()->remove(Item::get($item20$amount2));
                    }
                if (
    $command->getName() == "tradedecline")
                    {
                        
    $sender->sendMessage("[TradePro]" "You declined the trade request from " $trader);
                        
    $trader->sendMessage("[TradePro]" $sender " declined your trade request");
            }
            else
            {
                
    $this->getLogger()->info("[TradePro]" "Command must be run in-game" );
            
    /**ingame does mean player**/
                
    return false;
            }    
            }
        }
    }
    Thanks in advance!
  20. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    PHP:
    use pocketmine\item\Item;
    Hittmana likes this.

Share This Page

Advertisement