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;
|
2021-06-15 13:19:25 +00:00
|
|
|
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;
|
2021-06-15 13:19:25 +00:00
|
|
|
import me.totalfreedom.tfguilds.TFGuilds;
|
2021-05-22 04:26:48 +00:00
|
|
|
import net.md_5.bungee.api.ChatColor;
|
2021-06-15 13:19:25 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
2020-06-18 22:24:02 +00:00
|
|
|
|
|
|
|
public class GUtil
|
|
|
|
{
|
|
|
|
|
2021-05-22 04:26:48 +00:00
|
|
|
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");
|
2021-06-20 03:51:19 +00:00
|
|
|
private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&([a-fk-or0-9]|#[a-f0-9]{6})", Pattern.CASE_INSENSITIVE);
|
2020-06-20 21:23:53 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
public static String colorize(String string)
|
2020-06-18 22:24:02 +00:00
|
|
|
{
|
2021-05-22 04:26:48 +00:00
|
|
|
if (string != null)
|
2020-06-18 22:24:02 +00:00
|
|
|
{
|
2021-05-22 04:26:48 +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
|
|
|
|
2021-05-22 04:26:48 +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
|
|
|
|
2021-06-15 13:19:25 +00:00
|
|
|
public static String removeColorCodes(String string)
|
|
|
|
{
|
2021-07-28 22:12:32 +00:00
|
|
|
/*String s = null;
|
2021-06-15 13:19:25 +00:00
|
|
|
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(), "");
|
2021-06-15 13:19:25 +00:00
|
|
|
}
|
2021-07-28 22:12:32 +00:00
|
|
|
}*/
|
|
|
|
return ChatColor.stripColor(string);
|
2021-06-15 13:19:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 04:26:48 +00:00
|
|
|
public static boolean containsBlacklistedWord(String string)
|
2020-07-12 03:34:30 +00:00
|
|
|
{
|
2021-05-22 04:26:48 +00:00
|
|
|
for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
|
2020-08-02 01:48:15 +00:00
|
|
|
{
|
2021-05-22 04:26:48 +00:00
|
|
|
if (string.contains(blacklist))
|
2020-08-05 21:42:48 +00:00
|
|
|
{
|
2021-05-22 04:26:48 +00:00
|
|
|
return true;
|
2020-08-05 21:42:48 +00:00
|
|
|
}
|
2020-08-02 01:48:15 +00:00
|
|
|
}
|
2021-05-22 04:26:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-15 13:19:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-05-22 04:26:48 +00:00
|
|
|
public static String formatTime(long time)
|
|
|
|
{
|
|
|
|
Date date = new Date(time);
|
|
|
|
return DATE_FORMAT.format(date);
|
2020-08-02 01:48:15 +00:00
|
|
|
}
|
2021-05-22 04:26:48 +00:00
|
|
|
}
|