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

Solved Spaces between words

Comments in 'Plugin Development' started by FlamingGenius, Sep 27, 2015.

  1. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I promise last question and i can code the rest of the project without any help :D

    Whenever you use for example if i typed
    /broadcast Hello world
    It would show up as
    [Broadcast]HelloWorld

    How do i put space between the words?

    PHP:
    <?php

    namespace FlamingGenius\MessageSystem;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;


    class 
    main extends PluginBase{

     public function 
    onEnable(){
      
    $this->saveDefaultConfig();

     }

     public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
      
    $cmd $command->getName();
      
    $msg " ";
      foreach(
    $args as $arg){
       
    $msg $msg $arg;
      }
      if(
    strtolower($cmd) == "broadcast"){
       
    $this->getServer()->broadcastMessage("§4[Broadcast]§f" " " $msg);
      }
      elseif(
    strtolower($cmd) == "bgod"){
       
    $this->getServer()->broadcastMessage("§b[GOD]§4" " " $msg);
      }
      elseif(
    strtolower($cmd) == "bhero"){
      }
      elseif(
    strtolower($cmd) == "announce"){
      }
      elseif(
    strtolower($cmd) == "server"){
      }
      elseif(
    strtolower($cmd) == "console"){
      }
     }



    }

    ?>
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You can easily use array_shift()
  3. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Not exactly what im looking for
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $msg $msg " " .$arg;
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Do like @CraftYourBukkit and add this.
    PHP:
    $msg .= $msg " " $arg;//dot equals to add extra words/sentences
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    $msg implode(" ",$args);
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Thats gonna confuse him though. :confused:
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is the simplest method :)
  9. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Just to explain if you don't know how.
    PHP:
    if(strtolower($cmd) === "broadcast"){
    $this->getServer()->broadcastMessage("[Broadcast] " .  implode(" "$args));//joins all args words with a space
    }
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you understand what the code you received does, token by token, you would have no difficulty fixing it.
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Please actually LEARN PHP. You are just trying to make a plugin without sufficient knowledge of PHP. You are just copying the code people give you right now. Learn here: PHP.net
    Last edited: Sep 27, 2015
  12. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Lol.... why are you so rude to newcomers?
  13. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Excuse me!? I wrote every bit of this by hand and didnt copy anything i did not fully Understand and even then i wrote the code out because it helps your remember what your doing thank you very much i understand 100% everything that is currently in my code so if YOU do not know what you are talking aboUt as u tell other keep your mouth shut and dont post :)
  14. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Okay. Explain what it does.
  15. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    PHP:
    //opening php tag
    <?php
    //namespace declaration because my main is inside of src\FlamingGenius\MessageSystem but putting src is not needed
    namespace FlamingGenius\MessageSystem;
    /*These are pocketmine dependencies i need mor my project
    i need the first 2 because they are for running commands
    which is the core purpose of my plugin
    and i need the config for later use with 
    customization, plugin base is required all
    plugins MUST extend pluginbase
    i have the server bc i started using 
    Server::getInstance() but realized it was
    a bad practice i just never removed it*/
    use pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;

    //This declares A class called main and tells tht it extends pluginbase
    class main extends PluginBase{
    /*This declares a function called onEnabled which
    is predefined function which executes the code
    when the plugin is enabled there are more like this like
    onLoad(),onDisable()..*/
     
    public function onEnable(){
     
    //This saves the config in the resource file when the plugin is enabled
      
    $this->saveDefaultConfig();

     }

    /*This declares an onCommand function
    */
     
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
     
    /*Instead Of having to type $command->getName(); over
     amd over i just typed this code so all
     i have to do is type $cmd bc it stores
     the name in a shorter version*/
      
    $cmd $command->getName();
      
    /*This declares a variable called $msg
      and the default value is a string with nothing
      in it*/
      
    $msg " ";
      
    /*here $args is being declared as $arg and $msg is being combined with are or "assigned to it*/
      
    foreach($args as $arg){
       
    $msg $msg $arg;
      }
      
    /*Here i am declaring all my commands
      if<-If a condition is true do blah blah blah
      strtolower<-Make everything lower case im saying in english
      if broadcast is equal to broadcast then broadcast a message stored in
      $msg*/
      
    if(strtolower($cmd) == "broadcast"){
       
    $this->getServer()->broadcastMessage("§4[Broadcast]§f" " " $msg);
      }
      elseif(
    strtolower($cmd) == "bgod"){
       
    $this->getServer()->broadcastMessage("§b[GOD]§4" " " $msg);
      }
      
    /*elseif is like saying if and can be used over and
      over no matter how much you want its not
      very good practice and i know i should use a switch
      statement but idk i like these better*/
      
    elseif(strtolower($cmd) == "bhero"){
      }
      elseif(
    strtolower($cmd) == "announce"){
      }
      elseif(
    strtolower($cmd) == "server"){
      }
      elseif(
    strtolower($cmd) == "console"){
      }
     }



    }
    //this is a closing brace if u didnt know

    ?> // closing tag
  16. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    The closing tag(?>) isn't necessary. But on the other hand, you do understand.
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Dude dont tell them the truth, or else you will be hated like i will be right after this post.
  18. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Other then telling me to learn PHP your post wasnt the truth because i have not copied anything :)
  19. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Or have you? Dun dun duuuunnn...
    Primus likes this.
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Did you got answer on your queston? So be quite : Ignore us!;
    PHP:
    else/if shorthand[php](condition) ? /* true */ /*false */;

Share This Page

Advertisement