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

Solved Execute Command as Console From Plugin..

Comments in 'Plugin Development' started by DC4CODE, Apr 7, 2016.

  1. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Hey Guys i am editing a plugin and in that plugin i need to execute this command
    'wreset restore sw1'
  2. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    P.S i tried this:


    $command = "lagg clearall";$this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command))


    but it returns a syntax error
  3. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Try this, you just had a couple of things out of place, it should be:
    PHP:
    $command "wreset restore sw1";
    $this->getServer()->dispatchCommand(new ConsoleCommandSender($command));
  4. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    I am testing a build right now i'll update you with the results
  5. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    So far so good




    • Classpath
      • Inspection result: Passed
      • Info
        • Main class scanned: GamesLoad\SurvivalGames\Main
        • Main class file found at src/GamesLoad/SurvivalGames/Main.php
    • Bad practice
      • Inspection result: Passed
    • Syntax errors
      • Inspection result: Passed
      • Info
        • 1 good PHP file(s) and 0 bad PHP file(s) found.
        • Checked with PHP 7.0.4
  6. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Didnt execute the command...
  7. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Hmmm, I'll look into it
  8. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Can I see your 'use' statements? You should have
    PHP:
    use pocketmine\command\ConsoleCommandSender;
  9. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    I alerady have that..
  10. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Hmmm, can you send me the whole section that's meant to be running the command, I'm not sure why it's not working, you do have the wreset command on the server don't you?
  11. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    here is the section of the plugin Im working on

    PHP:
    else
                                {
                                    
    $aop count($levelArena->getPlayers());
                                    if(
    $aop==1)
                                    {
                                        foreach(
    $playersArena as $pl)
                                        {
                                            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $plpl)
                                            {
                                                
    $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml"Config::YAML);
                                                
    $lang = new Config($this->plugin->getDataFolder() . "/lang.yml"Config::YAML);
                                                
    $toUse $lang->get($playerlang->get($plpl->getName()));
                                                
    $plpl->sendMessage($this->prefix $pl->getName() . " " $toUse["won"]);
                                                
    $command "wreset restore sw1";
                                                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender($command));
                                            }
  12. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Use Statements:


    PHP:
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\tile\Chest;
    use 
    pocketmine\inventory\ChestInventory;
  13. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Is that in your Main class?
  14. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Yup
  15. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
  16. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Change to your first method.
    Server::dispatchCommand() requires 2 argument
    How many time i have to say that that method would never work...
    Primus likes this.
  17. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    can you add me on skype by any chance?
    add
    dylan_c4
    and i'll give it a go
  18. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Just post the problem here... Change it to $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command); then report the error message...
  19. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Ok i just tried that and there isn't any error message the command just doesn't execute and i am sure i have that command because i can run it just fine myself.
  20. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Weird... I assume that the dispatchCommand would never be called...

Share This Page

Advertisement