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

ClearChat

Comments in 'Plugin Development' started by iDirtPlayzMC, Dec 18, 2015.

  1. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    <php?
    namespace 
    ClearChat;

    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;

    class 
    main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getLogger->info("§aClearChat §7| §aEnabled");
            
    $this->getServer ()->getPluginManager ()->registerEvents ($this$this);
        }
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    $cmd->getName()) {
                
    $player $event->getPlayer();
                case 
    "cc":
                if(
    $player->hasPermission("clearchat.use")){
                    
    $this->getServer->sendBroadcast("
    ########################################\n
    #                                      #\n
    #                                      #\n
    #                                      #\n
    #                                      #\n
    #                                      #\n
    #                                      #\n
    #            Cleared Chat              #\n
    ########################################
                    "
    )
                }
            }
        }
    }
    would this work?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
  3. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    If so can you fix it for me ? I have no clue what im doing here XD
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    do you wanted to be sent to the player or EVERYONE?
  5. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Everyone
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    str_repeat($this->getServer()->broadcastMessage("\n"), 20);
  7. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    :O thanks¬
  8. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    this CommandSender $sender, Command $cmd, $label, array $arg is not an event right?
  9. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Or in alternative use a for cicle :D
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
    switch($command->getName())
      {
      case 
    "clearchat":
      
    $Count_CC 0;
      
    $this->getServer()->broadcastMessage("###########################\n");
      while(
    $Count_CC <= 7)
      {
    $this->getServer()->broadcastMessage("#                                      #\n");
      
    $Count_CC++;
      }  
      
    $this->getServer()->broadcastMessage("###########################\n");
      
    $Count_CC 0;  
      return 
    true;  
      }
    That works for me!
    PocketKiller likes this.
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    nice
  12. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Too many lines for this code... There are better way :)
  13. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    PHP:
    switch($command->getName())
      {
      case 
    "clearchat":
      
    $this->getServer()->broadcastMessage("###########################\n");
      for(
    int $i 1<= (how many space you want); i++)
      {
    $this->getServer()->broadcastMessage("#                                      #\n");
      } 
      
    $this->getServer()->broadcastMessage("###########################\n");
      return 
    true
      }

  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I am new to php, and never programmed "efficent", even my c++ programms liked to hang around in loops for minutes :D
    iDirtPlayzMC likes this.
  15. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    No problem man, you're welcom! :D
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Facepalm... You pass a repeated value to broadcastMessage(), not to repeat the return value of broadcastMessage (void)!
    Vaivez66 likes this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Putting a literal line break already makes a new line. Adding a new line plus \n will make two line breaks. So if you either make them all in one line of code, or if you remove the \n, it will work as expected. Otherwise, you will make an empty line in between.
    However, it appears that PocketMine/MCPE ignores messages with no content (PocketMine automatically splits messages at the line breaks), so it won't have an issue. But you shouldn't put two anyway.
    Also, note that if your PHP file is encoded in CRLF (usually true if you're on Windows), a symbol like ¶ will appear at the end of lines if you use line breaks directly due to obvious reasons (PHP takes your string literals as-is)

Share This Page

Advertisement