Last active
December 22, 2023 01:08
-
-
Save SpyryBR/e52d3403a8447a6e0c44f7ba1d17e55f to your computer and use it in GitHub Desktop.
Código para gerar caixa de caracteres.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsciiBox { | |
private int size; | |
private Boolean fix = false; | |
private String inside = " "; | |
private String[] borders = new String[4]; | |
private String[] corners = new String[0]; | |
public String render(String[] content) { | |
Boolean haveCorners = this.corners.length > 0; | |
String verticalBorder = this.borders[0]; | |
String border = Strings.repeat(verticalBorder, haveCorners ? this.size - 2 : this.size); | |
String message = "\n" + (haveCorners ? this.corners[0] + border + this.corners[1] : border); | |
for (String contentItem: content) { | |
message += "\n" + centerString(contentItem); | |
} | |
message += "\n" + (haveCorners ? this.corners[2] + border + this.corners[3] : border); | |
return message; | |
} | |
public AsciiBox border(String border) { | |
this.borders[0] = border; | |
return this; | |
} | |
public AsciiBox borders(String vertical, String horizontal) { | |
this.borders = new String[] { vertical, horizontal }; | |
return this; | |
} | |
public AsciiBox corner(String corner) { | |
this.corners = new String[] { corner, corner, corner, corner }; | |
return this; | |
} | |
public AsciiBox corners(String topLeft, String topRight, String bottomLeft, String bottomRight) { | |
this.corners = new String[] { topLeft, topRight, bottomLeft, bottomRight }; | |
return this; | |
} | |
public AsciiBox size(int size) { | |
this.size = size; | |
return this; | |
} | |
public AsciiBox inside(String inside) { | |
this.inside = inside; | |
return this; | |
} | |
public AsciiBox fixSide(Boolean side) { | |
this.fix = side; | |
return this; | |
} | |
private String centerString(String string) { | |
int stringLenght = ChatColor.stripColor(string).length(); | |
int calc = ((this.size - stringLenght)/2) - 1; | |
String space = Strings.repeat(this.inside, calc); | |
String leftSpace = space; | |
String rightSpace = space; | |
String horizontalBorder = this.borders.length == 2 ? this.borders[1] : this.borders[0]; | |
if((stringLenght % 2) != 0) { | |
if (this.fix) { | |
leftSpace += Strings.repeat(this.inside, 1); | |
} else { | |
rightSpace += Strings.repeat(this.inside, 1); | |
} | |
} | |
return horizontalBorder + leftSpace + "§r" + string + "§r" + rightSpace + horizontalBorder; | |
} | |
} |
tem um erro nesse seu codigo, que coisa de iniciante kk
Fala oque tá errado ué, se quer realmente ajudar dê dicas pro mano ali
é zueira kk o codigo ta legal
'-'
'-'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Não funciona fui fazer e fui banido