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

help /command

Comments in 'Plugin Development' started by 112kutiko, Feb 13, 2016.

  1. 112kutiko
    Offline

    112kutiko New Member

    Joined:
    Dec 27, 2015
    Posts:
    3
    Minecraft User:
    112kutiko
    how to make a command / command <Playername>
    shown that the player ip
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            
    $fcmd $cmd->getName(); # Get command name
            
    if(strtolower($fcmd) === "command"){ # Check if he is executing /command
                
    if(isset($args[0])){ # /command <this is args[0]> <this is args[1]> etc...
                    
    $player $this->plugin->getServer()->getPlayer($args[0]); # The string args[0] will be a Player object.
                    
    if($player instanceof Player){  # Check if it's a valid player.
                        
    $sender->sendMessage($player->getName() . " address is " $player->getAddress());
                    }
                }
            }
        }
    112kutiko likes this.
  3. 112kutiko
    Offline

    112kutiko New Member

    Joined:
    Dec 27, 2015
    Posts:
    3
    Minecraft User:
    112kutiko
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I would rather use
    PHP:
    if(!empty($args[0])){
    :)
    applqpak likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I know the difference. I am using !empty() because it still returns false even when I only have Spaces in the command, while isset() returns true
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But in that case, what about this command?
    Code:
    /cmd  something
    $args[0] is empty but isset. But you may make it impossible to detect the second argument.
    Sometimes, these things are done on purpose
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Yes, but why checking if $args[0] is a player when you already know it's empty?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What we should really be doing is
    PHP:
    $args array_filter($args);

Share This Page

Advertisement