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

[New API] Register a command dynamically

Comments in 'Plugin Development' started by EvolSoft, Jun 5, 2015.

  1. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Hi :),
    How can I register a command when running the plugin? (For example I want to register /hello command when the plugin enables)
    Can anyone show me an example?
    Thanks and best regards,

    EvolSoft
  2. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
  3. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Thank you! :D
    Just another question: can I use the same class for different commands (not aliases)?
    (For example the class HelloCommand should have /hello and /ciao)
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes.

    Example 1: Look at how PluginManager registers the commands at plugin.yml into PluginCommand. It is a doubleplusungood (Newspeak :p) practice to declare dynamic classes, so PocketMine registers plugin.yml commands using the PluginCommand class instead, where PluginCommand returns the values according to the values as passed in its constructor params (from plugin.yml) and registers using them.

    Example 2: Look at how WorldEditArt registers both //pos1 and //po2. (They are of a subclass of pemapmodder\worldeditart\utils\subcommand\Subcommand instead of a pocketmine\command\Command, but pemapmodder\worldeditart\utils\subcommand main classes (Subcommand and SubcommandMap) were actually designed in the same model as Command and CommandMap except that they are in different contexts and different uses.
    Falk likes this.
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Thanks :)
  6. TheDiamondYT
    Offline

    TheDiamondYT New Member

    Joined:
    Dec 20, 2014
    Posts:
    44
    Minecraft User:
    TheDiamondYT7
    You need to import the ConsoleCommandSender class
    PHP:
    $this->getServer()->dispatchCommand(new ConsoleCommamdSender"say Command here");
  7. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You're all the way wrong... What you're doing is dispatching a command creating a "New ConsoleCommandSender" class, and he is asking for "Registering Commands Dynamicallly"... For example, EssentialsPE ;)
    LazerSoft and EvolSoft like this.
  8. LazerSoft
    Offline

    LazerSoft New Member

    Joined:
    Jul 22, 2015
    Posts:
    9
    Whoops. I thought he meant dispatch a command. Idk, must have been reading it somewhere else at the same time.

Share This Page

Advertisement