@@ -30,9 +30,9 @@ public class Player extends Mob {
3030 private int fireRate = 0 ;
3131
3232 // Need to add a class for constants
33- private int fontCharSize = 8 ;
33+ private final int fontCharSize = 8 ;
3434 // "Cache" the division for the username length, no need for 60 divisions per second here.
35- private int nameOffset ;
35+ private int nameOffset = 0 ;
3636
3737 public Player (LevelHandler level , int x , int y , InputHandler input ,
3838 String userName , int shirtCol , int faceCol ) {
@@ -43,8 +43,6 @@ public Player(LevelHandler level, int x, int y, InputHandler input,
4343 this .shirtCol = shirtCol ;
4444 this .colour = Colours .get (-1 , 111 , shirtCol , faceCol );
4545 fireRate = Small .FIRE_RATE ;
46- // Perfectly matches the text over the head
47- nameOffset = (userName .length () / 2 ) * fontCharSize - ((userName .length () & 1 ) == 0 ? fontCharSize / 2 : 0 );
4846 }
4947
5048 public static double getSpeed () {
@@ -224,6 +222,11 @@ public void setUsername(String name) {
224222 public String getSanitisedUsername () {
225223 if (this .getUsername () == null || this .userName .isEmpty ()) {
226224 setUsername (guestPlayerName );
225+
226+ // Perfectly matches the text over the head
227+ int offsetUnit = ((userName .length () & 1 ) == 0 ? fontCharSize / 2 : 0 );
228+ nameOffset = (userName .length () / 2 ) * fontCharSize - offsetUnit ;
229+
227230 return guestPlayerName ;
228231 } else
229232 return this .getUsername ();
0 commit comments