Added minimum hex value for nick colors
This commit is contained in:
parent
4b930e62c3
commit
3e29fc7d17
|
|
@ -249,6 +249,47 @@ public class Utility {
|
||||||
: Utility.parseMiniMessage(stringBuilder.toString());
|
: Utility.parseMiniMessage(stringBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkNickBrightEnough(String nickname) {
|
||||||
|
if (!nickname.matches(".*" + stringRegen + ".*")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile(stringRegen);
|
||||||
|
Matcher matcher = pattern.matcher(nickname);
|
||||||
|
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexColor = matcher.group();
|
||||||
|
if (!checkHexHighEnough(hexColor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean checkHexHighEnough(String hexColor) {
|
||||||
|
// Remove the leading "#" if present
|
||||||
|
if (hexColor.startsWith("{")) {
|
||||||
|
hexColor = hexColor.substring(1);
|
||||||
|
}
|
||||||
|
if (hexColor.startsWith("#")) {
|
||||||
|
hexColor = hexColor.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the color parts
|
||||||
|
String redPart = hexColor.substring(0, 2);
|
||||||
|
String greenPart = hexColor.substring(2, 4);
|
||||||
|
String bluePart = hexColor.substring(4, 6);
|
||||||
|
|
||||||
|
// Convert the color parts to integers
|
||||||
|
int red = Integer.parseInt(redPart, 16);
|
||||||
|
int green = Integer.parseInt(greenPart, 16);
|
||||||
|
int blue = Integer.parseInt(bluePart, 16);
|
||||||
|
|
||||||
|
// Check if any part is over 30 in hexadecimal
|
||||||
|
return red > 0x30 || green > 0x30 || blue > 0x30;
|
||||||
|
}
|
||||||
|
|
||||||
public static String formatText(String message) {
|
public static String formatText(String message) {
|
||||||
/*
|
/*
|
||||||
.match(pattern)
|
.match(pattern)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.Nick;
|
import com.alttd.chat.objects.Nick;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
|
@ -147,42 +148,48 @@ public class NickUtilities
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean validNick(Player sender, OfflinePlayer target, String nickName) {
|
public static boolean validNick(Player sender, OfflinePlayer target, String nickName) {
|
||||||
if (noBlockedCodes(nickName)) {
|
if (!noBlockedCodes(nickName)) {
|
||||||
|
|
||||||
String cleanNick = NickUtilities.removeAllColors(nickName);
|
|
||||||
|
|
||||||
if (cleanNick.length() >= 3 && cleanNick.length() <= 16) {
|
|
||||||
|
|
||||||
if (cleanNick.matches("[a-zA-Z0-9_]*") && nickName.length()<=192) {//192 is if someone puts {#xxxxxx<>} in front of every letter
|
|
||||||
|
|
||||||
if (!cleanNick.equalsIgnoreCase(target.getName())){
|
|
||||||
for (Nick nick : Nicknames.getInstance().NickCache.values()){
|
|
||||||
if (!nick.getUuid().equals(target.getUniqueId())
|
|
||||||
&& ((nick.getCurrentNickNoColor() != null && nick.getCurrentNickNoColor().equalsIgnoreCase(cleanNick))
|
|
||||||
|| (nick.getNewNickNoColor() != null && nick.getNewNickNoColor().equalsIgnoreCase(cleanNick)))){
|
|
||||||
UUID uuid = nick.getUuid();
|
|
||||||
UUID uniqueId = target.getUniqueId();
|
|
||||||
if (uniqueId.equals(uuid)){
|
|
||||||
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
|
|
||||||
}
|
|
||||||
sender.sendMiniMessage(Config.NICK_TAKEN, null);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMiniMessage(Config.NICK_INVALID_CHARACTERS, null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMiniMessage(Config.NICK_INVALID_LENGTH, null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMiniMessage(Config.NICK_BLOCKED_COLOR_CODES, null);
|
sender.sendMiniMessage(Config.NICK_BLOCKED_COLOR_CODES, null);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if (!Utility.checkNickBrightEnough(nickName)) {
|
||||||
|
sender.sendMiniMessage("<red>At least one color must be brighter than 30 for each color</red>", null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String cleanNick = NickUtilities.removeAllColors(nickName);
|
||||||
|
|
||||||
|
if (cleanNick.length() < 3 || cleanNick.length() > 16) {
|
||||||
|
sender.sendMiniMessage(Config.NICK_INVALID_LENGTH, null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cleanNick.matches("[a-zA-Z0-9_]*") || nickName.length() > 192) { //192 is if someone puts {#xxxxxx<>} in front of every letter
|
||||||
|
sender.sendMiniMessage(Config.NICK_INVALID_CHARACTERS, null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cleanNick.equalsIgnoreCase(target.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Nick nick : Nicknames.getInstance().NickCache.values()){
|
||||||
|
if (!nick.getUuid().equals(target.getUniqueId())
|
||||||
|
&& ((nick.getCurrentNickNoColor() != null && nick.getCurrentNickNoColor().equalsIgnoreCase(cleanNick))
|
||||||
|
|| (nick.getNewNickNoColor() != null && nick.getNewNickNoColor().equalsIgnoreCase(cleanNick)))){
|
||||||
|
UUID uuid = nick.getUuid();
|
||||||
|
UUID uniqueId = target.getUniqueId();
|
||||||
|
if (uniqueId.equals(uuid)){
|
||||||
|
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
|
||||||
|
}
|
||||||
|
sender.sendMiniMessage(Config.NICK_TAKEN, null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean noBlockedCodes(final String getNick) {
|
public static boolean noBlockedCodes(final String getNick) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user