Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guerrero61.customtnt.mainutils;
- import guerrero61.customtnt.Main;
- import me.clip.placeholderapi.PlaceholderAPI;
- import net.md_5.bungee.api.ChatColor;
- import org.bukkit.entity.Player;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Formatter {
- private static final Pattern pattern = Pattern.compile("(?<!\\\\)(#[a-fA-F0-9]{6})");
- public static String FText(String text) {
- return FText(text, true, null);
- }
- public static String FText(String text, Player player) {
- return FText(text, true, player);
- }
- public static String FText(String text, boolean noPrefix) {
- return FText(text, noPrefix, null);
- }
- public static String FText(String text, boolean noPrefix, Player player) {
- if(noPrefix) {
- text = org.bukkit.ChatColor.translateAlternateColorCodes('&', text);
- } else {
- text = org.bukkit.ChatColor.translateAlternateColorCodes('&', Main.prefix + text);
- }
- Matcher matcher = pattern.matcher(text);
- while (matcher.find()) {
- String color = text.substring(matcher.start(), matcher.end());
- text = text.replace(color, "" + ChatColor.of(color));
- }
- text = PlaceholderAPI.setPlaceholders(player, text);
- return text;
- }
- public static String Capitalize(String str) {
- if(str == null || str.isEmpty()) {
- return str;
- }
- return str.substring(0, 1).toUpperCase() + str.substring(1);
- }
- public static String RemoveFormat(String text) {
- return RemoveFormat(text, null);
- }
- public static String RemoveFormat(String text, Player player) {
- text = FText(text, true, player);
- Matcher matcher = pattern.matcher(text);
- while (matcher.find()) {
- String color = text.substring(matcher.start(), matcher.end());
- text = text.replace(color, "");
- }
- return text.replaceAll("([&ยง][0-9a-fA-Fk-oK-OrR])", "");
- }
- }
Add Comment
Please, Sign In to add comment