package com.lifeknight.relaymcbungeemain.utilities; import com.lifeknight.relaymcbungeemain.Main; import com.lifeknight.relaymcbungeemain.player.SmartPlayer; import com.lifeknight.relayutils.RelayUtils; import com.lifeknight.relayutils.basic.Miscellaneous; import com.lifeknight.relayutils.basic.Text; import com.lifeknight.relayutils.game.MainGame; import com.lifeknight.relayutils.player.Group; import com.lifeknight.relayutils.player.Nick; import com.lifeknight.relayutils.utilities.ComponentBuilder; import java.io.File; import java.util.*; import java.util.regex.Pattern; public class PlayerUtilities { public static final int HALF_LINE_LENGTH = ComponentBuilder.DEFAULT_LINE_LENGTH / 2 - 5; public static List nouns = new ArrayList<>(); public static List adjectives = new ArrayList<>(); public static List firstNames = new ArrayList<>(); public static List lastNames = new ArrayList<>(); public static void startup() { try { nouns = getListFromFile("nouns.txt"); adjectives = getListFromFile("adjectives.txt"); firstNames = getListFromFile("first_names.txt"); lastNames = getListFromFile("last_names.txt"); } catch (Exception exception) { Main.error("An error occurred while gathering the resources for nicks: %s", exception.getMessage()); } } public static Nick generateRandomNick() { String firstName = Miscellaneous.getRandomEntry(adjectives); String lastName = Miscellaneous.getRandomEntry(nouns); if (Miscellaneous.getRandomTrueOrFalse()) { if (firstName != null) firstName = Text.capitalizeFirstLetter(firstName); if (lastName != null) lastName = Text.capitalizeFirstLetter(lastName); } String name = firstName + lastName + Miscellaneous.getRandomIntBetweenRange(13, 950); if (name.length() > 16) { name = name.substring(0, 16); } UUID randomUUID = Miscellaneous.getRandomEntry(SmartPlayer.getUUIDs()); String texturesOwner = SmartPlayer.getSmartPlayer(randomUUID).getName(); String[] textures = RelayUtils.getTextureFromUUID(randomUUID); Group group = Group.DEFAULT; return new Nick(name, texturesOwner, textures, group); } public static MainGame getHubServer(String name) { for (MainGame value : MainGame.values()) { if (value.getComparableName().equals(Text.toComparable(name))) { return value; } } switch (name.toLowerCase()) { case "mh": case "m": return MainGame.MANHUNT; case "duel": case "d": return MainGame.DUELS; } if ("main".equalsIgnoreCase(name)) { return null; } throw new UnsupportedOperationException(); } public static void onDatabaseOpen() { } public static void onDatabaseShutDown() { } public static Map getUUIDToNameMapFromUUIDs(List uuids) { Map uuidToNameMap = new HashMap<>(); for (UUID uuid : uuids) { uuidToNameMap.put(uuid, SmartPlayer.getSmartPlayer(uuid).getName()); } return uuidToNameMap; } public static boolean containsWebsiteOrData(String message) { String comparable = Text.toComparable(message); if (Text.containsAny(comparable, Miscellaneous.getList(".com", ".xyz", ".net", ".io", ".org", ".gg"), true, false)) return true; if (Text.containsAny(comparable, Miscellaneous.getList(",com", ",xyz", ",net", ",io", ",org", ",gg"), true, false)) return true; if (Text.containsAny(comparable, Miscellaneous.getList("-com", "-xyz", "-net", "-io", "-org", "-gg"), true, false)) return true; if (Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$").matcher(message).find()) return true; if (Pattern.compile("^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$").matcher(message).find()) return true; return false; } public static List getListFromFile(String fileName) throws Exception { List strings = new ArrayList<>(); try { File file = new File(fileName); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { strings.add(scanner.nextLine().toLowerCase()); } return strings; } catch (Exception var5) { throw new Exception(var5); } } public static final Map EMOJI_MAP = new HashMap<>(); static { String emojis = "star:★," + "peace:☮," + "sigma:Σ," + "flower:✿," + "smirk:ツ," + "tm:™," + "c:©," + "pickaxe:⛏" ; for (String s : Text.separateCSV(emojis)) { String[] split = s.split(Pattern.quote(":")); EMOJI_MAP.put(":" + split[0] + ":", split[1].charAt(0)); } } public static String processEmojis(String message) { String result = message; for (String s : EMOJI_MAP.keySet()) { result = result.replace(s, String.valueOf(EMOJI_MAP.get(s))); } return result; } }