TFGuilds/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java

86 lines
2.5 KiB
Java
Raw Normal View History

2020-06-18 22:24:02 +00:00
package me.totalfreedom.tfguilds.util;
2020-06-22 17:51:32 +00:00
import java.text.SimpleDateFormat;
import java.util.ArrayList;
2020-07-16 22:46:57 +00:00
import java.util.Arrays;
2020-06-22 17:51:32 +00:00
import java.util.Date;
2020-07-16 22:46:57 +00:00
import java.util.List;
2020-07-12 03:34:30 +00:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.totalfreedom.tfguilds.TFGuilds;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
2020-06-18 22:24:02 +00:00
public class GUtil
{
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE d MMM yyyy HH:mm:ss");
private static final List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&([a-fk-or0-9]|#[a-f0-9]{6})", Pattern.CASE_INSENSITIVE);
2020-07-13 00:40:11 +00:00
public static String colorize(String string)
2020-06-18 22:24:02 +00:00
{
if (string != null)
2020-06-18 22:24:02 +00:00
{
Matcher matcher = Pattern.compile("&#[a-f0-9A-F]{6}").matcher(string);
while (matcher.find())
{
String code = matcher.group().replace("&", "");
string = string.replace("&" + code, ChatColor.of(code) + "");
}
2020-06-18 22:24:02 +00:00
string = ChatColor.translateAlternateColorCodes('&', string);
}
2020-07-13 00:40:11 +00:00
return string;
2020-06-18 22:24:02 +00:00
}
2020-07-12 03:34:30 +00:00
public static String removeColorCodes(String string)
{
/*String s = null;
if (string != null)
{
Matcher matcher = CHAT_COLOR_FORMAT.matcher(string);
while (matcher.find())
{
2021-06-15 13:33:22 +00:00
s = string.replaceAll(matcher.group(), "");
}
}*/
return ChatColor.stripColor(string);
}
public static boolean containsBlacklistedWord(String string)
2020-07-12 03:34:30 +00:00
{
for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
2020-08-02 01:48:15 +00:00
{
if (string.contains(blacklist))
2020-08-05 21:42:48 +00:00
{
return true;
2020-08-05 21:42:48 +00:00
}
2020-08-02 01:48:15 +00:00
}
return false;
}
public static List<String> getPlayerNames()
{
List<String> names = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers())
{
if (!TFGuilds.getPlugin().getTfmBridge().isVanished(player))
{
names.add(player.getName());
}
}
return names;
}
public static String formatTime(long time)
{
Date date = new Date(time);
return DATE_FORMAT.format(date);
2020-08-02 01:48:15 +00:00
}
}