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

Center a Player name

Comments in 'Plugin Development' started by CrazedMiner, Jul 1, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm working on a plugin called HealthStatus which has multiple ways of showing a players health and has has support for custom amounts of health but when I use \n in the players name the players name is no longer centered but the HealthStatus is.
    If anybody could tell me how to fix this issue it would be greatly appreciated!

    Pictures:
    [​IMG]
    [​IMG]
    LDX likes this.
  2. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Actually I played with it a bit more and found out that nothing centers when you set the players name.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This snippet adds spaces before short lines.
    PHP:
    $name "CrazedMiner \nIs\nNot so nooby";

    $lines explode("\", $name);
    $maxLength=0;
    foreach(
    $lines as $line) {
      
    $maxLength = max($maxLength, strlen($line)) ;

    foreach(
    $lines as &$line) {
      
    $delta = ($maxLength -  strlen($line));
      
    $line = str_repeat(" ",  $delta / 2);
    }
    $name = implode("\n",  $lines);
    Note that this method doesn't work well because I assumed that all characters have the same width while it isn't true.
    CrazedMiner likes this.

Share This Page

Advertisement