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

Solved Changing help command In pm Src

Comments in 'Plugin Development' started by rinkuno, Jul 26, 2016.

  1. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    This repeats the message 10 or 7 times help!!!

    PHP:
    <?php

    /*
    *
    *  ____            _        _   __  __ _                  __  __ ____
    * |  _ \ ___   ___| | _____| |_|  \/  (_)_ __   ___      |  \/  |  _ \
    * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
    * |  __/ (_) | (__|   <  __/ |_| |  | | | | | |  __/_____| |  | |  __/
    * |_|   \___/ \___|_|\_\___|\__|_|  |_|_|_| |_|\___|     |_|  |_|_|
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU Lesser General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * @author PocketMine Team
    * @link http://www.pocketmine.net/
    *
    *
    */

    namespace pocketmine\command\defaults;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\event\TranslationContainer;
    use 
    pocketmine\utils\TextFormat;

    class 
    HelpCommand extends VanillaCommand{

        public function 
    __construct($name){
            
    parent::__construct(
                
    $name,
                
    "%pocketmine.command.help.description",
                
    "%commands.help.usage",
                [
    "?"]
            );
            
    $this->setPermission("pocketmine.command.help");
        }

        public function 
    execute(CommandSender $sender$currentAlias, array $args){
            if(!
    $this->testPermission($sender)){
                return 
    true;
            }

            if(
    count($args) === 0){
                
    $command "";
                
    $pageNumber 1;
            }elseif(
    is_numeric($args[count($args) - 1])){
                
    $pageNumber = (int) array_pop($args);
                if(
    $pageNumber <= 0){
                    
    $pageNumber 1;
                }
                
    $command implode(" "$args);
            }else{
                
    $command implode(" "$args);
                
    $pageNumber 1;
            }

            if(
    $sender instanceof ConsoleCommandSender){
                
    $pageHeight PHP_INT_MAX;
            }else{
                
    $pageHeight 5;
            }

            if(
    $command === ""){
                
    /** @var Command[][] $commands */
                
    $commands = [];
                foreach(
    $sender->getServer()->getCommandMap()->getCommands() as $command){
                    if(
    $command->testPermissionSilent($sender)){
                        
    $commands[$command->getName()] = $command;
                    }
                }
                
    ksort($commandsSORT_NATURAL SORT_FLAG_CASE);
                
    $commands array_chunk($commands$pageHeight);
                
    $pageNumber = (int) min(count($commands), $pageNumber);
                if(
    $pageNumber 1){
                    
    $pageNumber 1;
                }
                
    $sender->sendMessage(new TranslationContainer("commands.help.header", [$pageNumbercount($commands)]));
                if(isset(
    $commands[$pageNumber 1])){
                    foreach(
    $commands[$pageNumber 1] as $command){
        
    $sender->sendMessage(TextFormat::RED "=========+[CMD]+==========");
            
    $sender->sendMessage(TextFormat::AQUA "- /Rankup");
            
    $sender->sendMessage(TextFormat::RED "=========+[CMD]+==========");
                    }
                }

                return 
    true;
            }else{
                if((
    $cmd $sender->getServer()->getCommandMap()->getCommand(strtolower($command))) instanceof Command){
                    if(
    $cmd->testPermissionSilent($sender)){
                        
    $message TextFormat::YELLOW "--------- " TextFormat::WHITE " Help: /" $cmd->getName() . TextFormat::YELLOW " ---------\n";
                        
    $message .= TextFormat::GOLD "Description: " TextFormat::WHITE $cmd->getDescription() . "\n";
                        
    $message .= TextFormat::GOLD "Usage: " TextFormat::WHITE implode("\n" TextFormat::WHITEexplode("\n"$cmd->getUsage())) . "\n";
                        
    $sender->sendMessage($message);

                        return 
    true;
                    }
                }
                
    $sender->sendMessage(TextFormat::RED "No help for " strtolower($command));

                return 
    true;
            }
        }

    }
  2. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    $sender-sendMessage(TextFormat::RED . "=========+[CMD]+==========");
    $sender-sendMessage(TextFormat::AQUA . "- /Rankup");
    $sender-sendMessage(TextFormat::RED . "=========+[CMD]+==========");

    Can it be that instead of a command list
  3. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    You are using foreach(), that will send each page number that you have the messages.
    And by the way you should remove ksort() and some other functions
    Last edited: Jul 26, 2016
    rinkuno likes this.
  4. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    How can I remove

    --- Showing help page 1 of 1 (/help <page>) ---
  5. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Remove
    PHP:
    $sender->sendMessage(new TranslationContainer("commands.help.header", [$pageNumbercount($commands)]));
    rinkuno likes this.
  6. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Thanks survingo
    Survingo likes this.
  7. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    I wonder if this is plugin development...
    Primus and Survingo like this.
  8. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    PHP:
    //For example modding /kick
    $cmd "kick";
    $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel("$cmd_disabled"); /** Prepares for unregister */
    $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap()); /** Unregisters from command map */
    $this->getServer()->getCommandMap()->register($cmd, new ModdedKickCmdClass($this));/** Now you can register the command with an other executor class */
  9. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    "$cmd_disabled" will be parsed as a variable $cmd_disabled casted to string. You should write $cmd . "_disabled", or simply "$cmd-disabled".
    Survingo likes this.
  10. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    I had made a clean /help modifying plugin some weeks ago, where you can set unlimited pages via the config. You might wanna have a look at that.
    It's better you do it through a plugin... like this!

    PHP:
    public function onHelp(PlayerCommandPreprocessEvent $e){
    //$this->help = new Config($this->getDataFolder()."help.yml", Config::YAML);
    $cmd explode(" "strtolower($e->getMessage()));
    $p $e->getPlayer();
    if(
    $cmd[0] === "/help" or $cmd[0] === "/?"){
    // insert code here
    $e->setCancelled();
    }
    }
    You need to cancel the event so that the server doesn't send player the original vanilla command, help.
  11. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Using PlayerCommandPreprocessEvent is bad practic.
    Why cancelling it indirectly if you're able to do it directly?

Share This Page

Advertisement