fix color

This commit is contained in:
loki5512344 2026-03-13 15:51:47 +01:00
parent 6b6605a2b0
commit 5088e3ad1c
20 changed files with 623 additions and 423 deletions

View file

@ -59,6 +59,12 @@ public class DiscordIntegration {
int retryAttempts = config.getInt("performance.retry_attempts", 3);
long retryDelay = config.getLong("performance.retry_delay", 1000);
// Логируем информацию о URL для отладки
plugin.getLogger().info("Discord webhook URL length: " + webhookUrl.length());
if (webhookUrl.length() > 0) {
plugin.getLogger().info("Discord webhook URL starts with: " + webhookUrl.substring(0, Math.min(50, webhookUrl.length())));
}
webhook = new DiscordWebhook(plugin, webhookUrl, username, avatarUrl, timeout, retryAttempts, retryDelay);
if (!webhook.isValid()) {

View file

@ -28,7 +28,7 @@ public class DiscordWebhook {
public DiscordWebhook(JavaPlugin plugin, String webhookUrl, String username, String avatarUrl,
int timeout, int retryAttempts, long retryDelay) {
this.plugin = plugin;
this.webhookUrl = webhookUrl;
this.webhookUrl = webhookUrl != null ? webhookUrl.trim() : null; // Убираем пробелы
this.username = username;
this.avatarUrl = avatarUrl;
this.timeout = timeout * 1000; // конвертируем в миллисекунды
@ -142,7 +142,8 @@ public class DiscordWebhook {
* Синхронная отправка в вебхук
*/
private boolean sendWebhookSync(String jsonPayload) throws IOException {
URL url = URI.create(webhookUrl).toURL();
String cleanUrl = webhookUrl.trim();
URL url = URI.create(cleanUrl).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
@ -180,8 +181,32 @@ public class DiscordWebhook {
* Проверить валидность вебхука
*/
public boolean isValid() {
return webhookUrl != null &&
webhookUrl.startsWith("https://discord.com/api/webhooks/") &&
webhookUrl.length() > 50; // Минимальная длина валидного URL
if (webhookUrl == null || webhookUrl.trim().isEmpty()) {
plugin.getLogger().warning("Discord webhook URL is null or empty");
return false;
}
String cleanUrl = webhookUrl.trim();
if (!cleanUrl.startsWith("https://discord.com/api/webhooks/") &&
!cleanUrl.startsWith("https://discordapp.com/api/webhooks/")) {
plugin.getLogger().warning("Discord webhook URL has invalid format: " + cleanUrl);
return false;
}
if (cleanUrl.length() < 50) {
plugin.getLogger().warning("Discord webhook URL is too short: " + cleanUrl);
return false;
}
// Проверяем на недопустимые символы
try {
URI.create(cleanUrl);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("Discord webhook URL contains illegal characters: " + e.getMessage());
return false;
}
return true;
}
}