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

Override /help

Comments in 'Plugin Development' started by Andrey Nazarchuk, May 14, 2015.

?

Am I Asking Too Many Questions?

  1. Yes! Please go read the API :|

    20.0%
  2. Yep... But that is what this forum topic is for.

    30.0%
  3. I Like Questions!

    50.0%
  4. I'll Help you with your plugin directly instead! :D

    0 vote(s)
    0.0%
  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello again!
    I tried to override /help using this: https://forums.pocketmine.net/threads/overriding-default-commands.8216/#post-85858
    But it did not work, can someone please tell me what I did wrong?
    Here is my code:
    Code:
    case "help":
                if($sender->hasPermission("myserver.command.help") or $sender->hasPermission("myserver.command") or $sender->hasPermission("myserver")){
                    $command = explode(" ", strtolower($event->getMessage()));
                    if($command[0] === "/help"){
                    $event->setCancelled(true);
                    if($command[1] === "page-here"){
                    $sender->sendMessage...(lots of messages
                      }
                return true;
                }
                else{ $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
    }
                    }
    
    Why wont it work?
    Thanks again!:oops::oops::oops:
    p.s. Please read the poll
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You need to work with some "CommandInternals" to be able to override an existing command :p
    Andrey Nazarchuk likes this.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    How do I do that?
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You may need to use "Command Classes" instead of the onCommand function... Then, chck out this:
    64FF00, Falk, RekkuzaRage and 3 others like this.
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Like this?

    Code:
    $commandMap = $this->getServer()->getCommandMap();
    $commandToOverride = $commandMap->getCommand("help");
    $commandToOverride->setLabel("help_disabled"); //This prepares the command for the next step, setting up the Command->nextLabel
    $commandToOverride->unregister($commandMap); //This changes the current label
    //Now, we can register our command.
    $command = new MyHelpCommand($this);
    $commandMap->register("help", $command);
    //And the aliases
    $commandMap->register("help", $command, "help");
    $commandMap->register("help", $command, "help");
    
    And then I can override /help?
    iksaku likes this.
  6. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I believe that the last two lines ($commandMap->register("help", $command, "help");
    should be the subcommands, like /help 1 or /help 2
    so it would be $commandMap->register("help", $command, "1");
    or something like that.
    Andrey Nazarchuk likes this.
  7. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Like this?
    Code:
    $commandMap = $this->getServer()->getCommandMap();
    $commandToOverride = $commandMap->getCommand("help");
    $commandToOverride->setLabel("help_disabled"); //This prepares the command for the next step, setting up the Command->nextLabel
    $commandToOverride->unregister($commandMap); //This changes the current label
    //Now, we can register our command.
    $command = new MyHelpCommand($this);
    $commandMap->register("help", $command);
    //And the aliases
    $commandMap->register("help", $command, "1");
    $commandMap->register("help", $command, "2");
    
    Are you sure this will work?
    HotFireyDeath likes this.
  8. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    It should. @iksaku is this right?
    Andrey Nazarchuk likes this.
  9. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    OK check this:
    Code:
            case "help":
                if($sender->hasPermission("matrixpe.command.help") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    $commandMap = $this->getServer()->getCommandMap();
                    $commandToOverride = $commandMap->getCommand("help");
                    $commandToOverride->setLabel("help_disabled"); 
                    $commandToOverride->unregister($commandMap); 
                    $command = new MyHelpCommand($this);
                    $commandMap->register("help", $command);
                    $command = explode(" ", strtolower($event->getMessage()));
                            $event->setCancelled(true);
                                $sender->sendMessage("§6=-=-=-=-= §f§lSky§4§lWars §6=-=-=-=-=");
                                $sender->sendMessage("§e/leave §8§l-- §r§bLeaves the match.");
                                $sender->sendMessage("§e/stat §8§l-- §r§bSee your statistics.");
                                $sender->sendMessage("§e/help §8§l-- §r§bShows the help§7[This Page].");
                                    if($sender->hasPermission("matrixpe.") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe.build")){
                                        $sender->sendMessage("§4/ss §8§l-- §r§bSets a Player Spawn.");
                                        $sender->sendMessage("§4/sl §8§l-- §r§bSets Lobby Spawn.");
                                        $sender->sendMessage("§4/spec §8§l-- §r§bSets spectator spawn.");
                                        $sender->sendMessage("§4/sw §8§l-- §r§bShows Info screen.");
                                    }
                                    return true;
                                }
                            }
                else{ $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
    
  10. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    No. You have to reregister the commands in onEnable.
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Ok, Thanks for the help guys!
  12. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Now this :( :
    Code:
    20:44:29 [CRITICAL] ClassNotFoundException: "Class SkyWarsPE\MyHelpCommand not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144
    
  13. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    You have to create the command class. Look at EssentialsPE's code. http://github.com/LegendOfMCPE/EssentialsPE
    iksaku likes this.
  14. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  15. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
  16. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    One last noob question, what do I replace:
    essentialspe with?
    Code:
    $this->getServer()->getCommandMap()->registerAll("essentialspe", [
    
  17. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    Your plugin name perhaps?
    Andrey Nazarchuk likes this.
  18. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Can't you remove the pocketmine.command.help permission from the player?
    PEMapModder likes this.
  19. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Does it work now? Is "/help" overridden?
    Jon likes this.
  20. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    @LDX suggestion is very good, but if you want a simpler way to understand how the "Command Internals" work, then look at:
    If you're going to create your own command class, be sure to:
    1. Extend the "Command" class: https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/command/Command.php
    2. Implement the "PluginIdentifiableCommand" interface: https://github.com/PocketMine/Pocke...ketmine/command/PluginIdentifiableCommand.php
    Please see the way that EssentialsPE handle this type of command classes, we created a "Base Class" with all the required functions, and then each "command class" just extends it:

Share This Page

Advertisement