Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String center(String s, int maxPixels) {
- int charPixelCount = MinecraftFont.Font.getWidth(ChatColor.stripColor(s));
- charPixelCount += getBoldPixels(s);
- int spaceCount = 0;
- if(charPixelCount < maxPixels) {
- int pixelsLeft = maxPixels-charPixelCount;
- int spacing = (int) Math.ceil(pixelsLeft/3);
- spaceCount = spacing/3;
- }
- if(spaceCount % 2 == 0)
- spaceCount++;
- if(spaceCount > 0) {
- StringBuilder sb = new StringBuilder();
- for(int i = 1; i <= spaceCount; i++)
- sb.append(" ");
- return sb.toString()+s;
- }else {
- return s;
- }
- }
- private int getBoldPixels(String s) {
- int additionalPixels = 0;
- Character previousChar = null;
- boolean isBold = false;
- for(char character : removeColor(colorize(s)).toCharArray()) {
- if(previousChar != null) {
- if(previousChar == '&' && character == 'l' || character == 'L')
- isBold = !isBold;
- if(character != '&' && character != 'ยง')
- if(isBold)
- additionalPixels++;
- }
- previousChar = character;
- }
- return additionalPixels;
- }
Add Comment
Please, Sign In to add comment