GuerreroCraft61

Untitled

Sep 9th, 2020 (edited)
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package guerrero61.customtnt.mainutils;
  2.  
  3. import guerrero61.customtnt.Main;
  4. import me.clip.placeholderapi.PlaceholderAPI;
  5. import net.md_5.bungee.api.ChatColor;
  6. import org.bukkit.entity.Player;
  7.  
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. public class Formatter {
  12.  
  13.     private static final Pattern pattern = Pattern.compile("(?<!\\\\)(#[a-fA-F0-9]{6})");
  14.  
  15.     public static String FText(String text) {
  16.         return FText(text, true, null);
  17.     }
  18.  
  19.     public static String FText(String text, Player player) {
  20.         return FText(text, true, player);
  21.     }
  22.  
  23.     public static String FText(String text, boolean noPrefix) {
  24.         return FText(text, noPrefix, null);
  25.     }
  26.  
  27.     public static String FText(String text, boolean noPrefix, Player player) {
  28.         if(noPrefix) {
  29.             text = org.bukkit.ChatColor.translateAlternateColorCodes('&', text);
  30.         } else {
  31.             text = org.bukkit.ChatColor.translateAlternateColorCodes('&', Main.prefix + text);
  32.         }
  33.         Matcher matcher = pattern.matcher(text);
  34.         while (matcher.find()) {
  35.             String color = text.substring(matcher.start(), matcher.end());
  36.             text = text.replace(color, "" + ChatColor.of(color));
  37.         }
  38.         text = PlaceholderAPI.setPlaceholders(player, text);
  39.         return text;
  40.     }
  41.  
  42.     public static String Capitalize(String str) {
  43.         if(str == null || str.isEmpty()) {
  44.             return str;
  45.         }
  46.         return str.substring(0, 1).toUpperCase() + str.substring(1);
  47.     }
  48.  
  49.     public static String RemoveFormat(String text) {
  50.         return RemoveFormat(text, null);
  51.     }
  52.  
  53.     public static String RemoveFormat(String text, Player player) {
  54.         text = FText(text, true, player);
  55.  
  56.         Matcher matcher = pattern.matcher(text);
  57.         while (matcher.find()) {
  58.             String color = text.substring(matcher.start(), matcher.end());
  59.             text = text.replace(color, "");
  60.         }
  61.  
  62.         return text.replaceAll("([&ยง][0-9a-fA-Fk-oK-OrR])", "");
  63.     }
  64. }
Add Comment
Please, Sign In to add comment