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

[Question]Docs

Comments in 'Plugin Development' started by PluginMastered, Aug 21, 2014.

  1. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    How do devs get functions on the docs ?? Like commandDispatch or setplayergamemode? I need it for my network CrafterRealm
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    You can search them using the search text box on top right, or search manually on the left list.
  3. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    So if i want a player to heal when the run the command heal i would use

    setHealth(20)
  4. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Yes.
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
        switch(
    $cmd->getName()){
            case 
    "heal":
            
    $sender->setHealth(20);
        }
    }
  5. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Just changing your code a little @luca28pet ^-^
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
        switch(
    $cmd->getName()){
            case 
    "heal":
                
    $sender->setHealth(20);
                return 
    true;
            break;
        }
    }
    (Its good practice to always return something at the end of a command and break them as well)
    Dutok likes this.
  6. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    You need to make sure it's a player first.
    PHP:
    public function onCommand(CommandSender $sender,Command $cmd,$label,array $args) {
      if(
    $sender instanceof Player) {
        switch(
    $cmd->getName()) {
          case 
    "heal":
            
    $sender->setHealth(20);
          break;
        }
      } else {
        
    $sender->sendMessage("Command must be used in-game.");
      }
      return 
    true;
    }
    PEMapModder likes this.
  7. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    Thanks for all the help guys ^^.
    LDX likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Break and return together are not good practice.
    LDX likes this.

Share This Page

Advertisement