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

This code doesn't work.

Comments in 'Plugin Development' started by Hittmana, Feb 8, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    My W.I.P. plugin (TradePro) is not working. Here is the 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\item\Item;
    class 
    MainClass extends PluginBase implements Listener
    {
        public function 
    onEnable()
            {
            
    $this->getLogger()->info("TradePro enabled v0.3.3");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
        public function 
    onDisable()
            {
            
    $this->getLogger()->info("TradePro disabled v0.3.3");
            }
        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)
                                {
                                global 
    $trader;
                                
    $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!");
                                global 
    $item1;
                                
    $item1 $args[1];
                                global 
    $amount1;
                                
    $amount1 $args[2];
                                global 
    $item2;
                                
    $item2 $args[3];
                                global 
    $amount2;
                                
    $amount2 $args[4];
                                return 
    true;
                                }
                                else
                                {
                                    
    $this->getLogger()->info("Must be run ingame!");
                                    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")
                    {
                        
    $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()->removeItem(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()->removeItem(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");
            }    
            }
        }  
      }
    }
    Whenever i use /trade move_it 1 1 1 1 it sends the trade request, but then when I do /tradeaccept move_it
    (move_it is my test name so i am sending and accepting a trade request to myself) it does nothing. Please help! Thanks in advance!
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Did you register it in your plugin.yml?
    applqpak likes this.
  3. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Yeah here is the plugin.ml:
    PHP:
    nameTradePro
    main
    Hittmana\TradePro\MainClass
    version
    0.3.3
    api
    1.4.0
    description
    Test plugin
    commands
    :
      
    trade:
        
    descriptionSend trade request.
        
    permissiontrade.cmd
        usage
    : /trade <player>
      
    tradeaccept:
        
    descriptionAccept trade request
        permission
    tradeaccept.cmd
        usage
    : /tradeaccept <player>
      
    tradedecline:
        
    descriptionDecline trade request
        permission
    tradedecline.cmd
        usage
    : /tradedecline 
  4. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    whats the player AND console feedback when using the broken command?
    (Console feedback meaning errors... and player feedback anything at all including error)
    applqpak likes this.
  5. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    try to request yourself a trade,
    decline it, and see if it sends out output,
    if it doenst, i think that the server is getting confused
    with $sender, i think, since $sender is the one who triggered the command,
  6. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    There is no error in console or player. It simply does... nothing!
  7. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ok i will try this ASAP
  8. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    $this->getLogger()->info
    if im not wrong, this is for console, try usig:
    $sender->sendMessage(TextFormat::BLUE."You can use colors like this!");
  9. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    so what you are doing, is that Console get the message, but its not getting it since the one triggering the command is the player, and gives error if its console
  10. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    $this->getLogger()->info is sending a message to the console to let it know its working.
  11. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I tried both /tradeaccept and /tradedecline both just say Usage:(respective command)
  12. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    ok, try removing Globals, they seem useless for me...
  13. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I have to have them to make the variables global
  14. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    We Should wait for @PEMapModder , he should know what to do, a PHP Ninja
  15. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I know right! He's awesome!
  16. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Should I ask him?
  17. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    yep
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use class properties instead of globals. Otherwise, have fun getting your variables mysteriously nulled.
    minebuilder0110 and Hittmana like this.
  19. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    PHP ninja... :eek:
    Hittmana likes this.
  20. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    I KNEW IT! i knew PEMapModder was a PHP Ninja!
    Hittmana likes this.

Share This Page

Advertisement