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

Solved Need help registering command with php instead of plugin.yml

Comments in 'Plugin Development' started by GlaciercreepsMC, Jul 30, 2015.

  1. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    First I'd like to say hello all! It's been quite a while since I've been here. :) Anyway, to the point:

    I'm trying to register a couple of commands in my plugin's onEnable() method, with this function I made:
    PHP:
    private function registerCommand($cmd$usage$desc$perm$permMsgCommandExecutor $executor){
            
    $command = new PluginCommand($cmd);
            
    $command->setUsage($usage);
            
    $command->setDescription($desc);
            
    $command->setPermission($perm);
            
    $command->setPermissionMessage($permMsg);
            
    $command->setExecutor($executor);
            
    $this->getServer()->getCommandMap()->register($fallbackPrefix$command);
        }
    I get the $command parameter, but I don't know what a fallback prefix is.
    So I have 3 questions:
    1. What is it, and what do I supply for it?
    2. Also, how can I make the command op by default from there? I assumed setPermissionMessage() was for that, but I realize it's probably equivalent to setting 'description' in plugin.yml
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Permission message is equivalent to 'permission-message' in plugin.yml.

    To answer your question 1:
    Fallback prefix is a method for players to use your command if another plugin also registered that command. The fallback prefix of PocketMine commands is "pocketmine". Say, if there is a plugin that registers a command "gc" (same to /gc in PocketMine as for garbage collection debug command) with the fallback prefix as "myplugin" (fallback prefixes are usually the plugin name), it is undefined which command would be executed if a player uses /gc, but /pocketmine:gc would become that for garbage collection and /myplugin:gc will be the plugin one.

    For 2:
    You have to register permission $perm. If you want to register it in plugin.yml, do it the normal way with "default" attribute as "op". If you want to register it dynamically, take a look at SimpleWarp.
    GlaciercreepsMC likes this.
  3. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Well said! Makes perfect sense. :) Also I figured out the permission part, I had to use this code and then use $cmd->setPermission() afterwards:
    PHP:
    $perm = new Permission($permName);
    $perm->setDescription($permDesc);
    $perm->setDefault($permDefault);
    edit: indentation

Share This Page

Advertisement