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

How to block color codes for Non-OPs

Comments in 'Plugin Development' started by CraftYourBukkit, May 14, 2015.

  1. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How can I somehow block Color Codes? I tried to send the message always in §e(yellow) but color codes are still working.
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Replace § with null before send the message
    CraftYourBukkit likes this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How do I do that?
    PHP:
    str_replace("§"null);
    ?
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    PHP:
    $message str_replace("§"""$message);
    CraftYourBukkit likes this.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Thanks! :)
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You are welcome :)
  7. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    436
    Plugins:
    14
    Minecraft User:
    shoghicp
    That leaves the formatting code there. Use TextFormat::clear() with remove format to true
  8. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    It depends, if you want a certain player to NOT SEE COLORS, use the method suggested by @shoghicp, but if you want to disallow players to SEND COLORED messages, then use the one that @EvolSoft told ;)
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    EvolSoft's Method was the one I wanted but thanks tho:)
  10. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    You can also do this:
    PHP:
    $msg str_replace("§""§r"$msg);
    XD
    EvolSoft likes this.
  11. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    436
    Plugins:
    14
    Minecraft User:
    shoghicp
    Also players can't send colored messages, they need to be explicitly allowed by a plugin to do so (check remove format on Player)
    TigerHix and hoyinm14mc like this.
  12. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    436
    Plugins:
    14
    Minecraft User:
    shoghicp
    That is wrong.

    The methods have changed for 1.5

    setRemoveFormat() to true will disable players SENDING colors, and it defaults to true. You have to set this to false so players can talk/put signs with colors directly.

Share This Page

Advertisement