refactor: split god classes, fix OCP/ISP/SRP, migrate commands to BaseCommand hierarchy
This commit is contained in:
parent
793924c9ba
commit
90c3cac5cf
244 changed files with 1677 additions and 1570 deletions
|
|
@ -2,6 +2,7 @@ package com.loki.lochat.integrations;
|
|||
|
||||
import com.loki.lochat.integrations.discord.DiscordConfig;
|
||||
import com.loki.lochat.integrations.discord.DiscordMessageService;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
|
@ -40,7 +41,9 @@ public class DiscordIntegration {
|
|||
}
|
||||
|
||||
public void sendChatMessage(Player player, String message, boolean isGlobal) {
|
||||
if (!enabled || !config.isChatEnabled()) return;
|
||||
if (!enabled || !config.isChatEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.isGlobalOnly() && !isGlobal) {
|
||||
return;
|
||||
|
|
@ -50,22 +53,30 @@ public class DiscordIntegration {
|
|||
}
|
||||
|
||||
public void sendPlayerJoin(Player player) {
|
||||
if (!enabled || !config.isEventEnabled("join")) return;
|
||||
if (!enabled || !config.isEventEnabled("join")) {
|
||||
return;
|
||||
}
|
||||
messageService.sendPlayerJoin(player);
|
||||
}
|
||||
|
||||
public void sendPlayerQuit(Player player) {
|
||||
if (!enabled || !config.isEventEnabled("quit")) return;
|
||||
if (!enabled || !config.isEventEnabled("quit")) {
|
||||
return;
|
||||
}
|
||||
messageService.sendPlayerQuit(player);
|
||||
}
|
||||
|
||||
public void sendPlayerDeath(Player player, String deathMessage) {
|
||||
if (!enabled || !config.isEventEnabled("death")) return;
|
||||
if (!enabled || !config.isEventEnabled("death")) {
|
||||
return;
|
||||
}
|
||||
messageService.sendPlayerDeath(player, deathMessage);
|
||||
}
|
||||
|
||||
public void sendTestMessage(String message, String senderName) {
|
||||
if (!enabled) return;
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
messageService.sendTestMessage(message, senderName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loki.lochat.integrations;
|
|||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -78,10 +79,18 @@ public class DiscordWebhook {
|
|||
private JsonObject buildEmbed(String title, String description, String color,
|
||||
String thumbnailUrl, JsonArray fields) {
|
||||
JsonObject embed = new JsonObject();
|
||||
if (title != null) embed.addProperty("title", title);
|
||||
if (description != null) embed.addProperty("description", description);
|
||||
if (color != null) embed.addProperty("color", Integer.parseInt(color, 16));
|
||||
if (fields != null) embed.add("fields", fields);
|
||||
if (title != null) {
|
||||
embed.addProperty("title", title);
|
||||
}
|
||||
if (description != null) {
|
||||
embed.addProperty("description", description);
|
||||
}
|
||||
if (color != null) {
|
||||
embed.addProperty("color", Integer.parseInt(color, 16));
|
||||
}
|
||||
if (fields != null) {
|
||||
embed.add("fields", fields);
|
||||
}
|
||||
if (thumbnailUrl != null) {
|
||||
JsonObject thumb = new JsonObject();
|
||||
thumb.addProperty("url", thumbnailUrl);
|
||||
|
|
@ -106,13 +115,19 @@ public class DiscordWebhook {
|
|||
return CompletableFuture.supplyAsync(() -> {
|
||||
for (int attempt = 1; attempt <= retryAttempts; attempt++) {
|
||||
try {
|
||||
if (sendWebhookSync(json.toString())) return true;
|
||||
if (sendWebhookSync(json.toString())) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Discord webhook attempt " + attempt + " failed: " + e.getMessage());
|
||||
}
|
||||
if (attempt < retryAttempts) {
|
||||
try { Thread.sleep(retryDelay); }
|
||||
catch (InterruptedException e) { Thread.currentThread().interrupt(); break; }
|
||||
try {
|
||||
Thread.sleep(retryDelay);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLogger().severe("Failed to send Discord webhook after " + retryAttempts + " attempts");
|
||||
|
|
@ -134,8 +149,13 @@ public class DiscordWebhook {
|
|||
os.write(jsonPayload.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 204) return true;
|
||||
if (code == 429) { plugin.getLogger().warning("Discord webhook rate limited (429)"); return false; }
|
||||
if (code == 204) {
|
||||
return true;
|
||||
}
|
||||
if (code == 429) {
|
||||
plugin.getLogger().warning("Discord webhook rate limited (429)");
|
||||
return false;
|
||||
}
|
||||
plugin.getLogger().warning("Discord webhook returned code: " + code);
|
||||
return false;
|
||||
} finally {
|
||||
|
|
@ -144,12 +164,22 @@ public class DiscordWebhook {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
if (webhookUrl == null || webhookUrl.trim().isEmpty()) return false;
|
||||
if (webhookUrl == null || webhookUrl.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String url = webhookUrl.trim();
|
||||
if (!url.startsWith("https://discord.com/api/webhooks/") &&
|
||||
!url.startsWith("https://discordapp.com/api/webhooks/")) return false;
|
||||
if (url.length() < 50) return false;
|
||||
try { URI.create(url); } catch (IllegalArgumentException e) { return false; }
|
||||
!url.startsWith("https://discordapp.com/api/webhooks/")) {
|
||||
return false;
|
||||
}
|
||||
if (url.length() < 50) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
URI.create(url);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loki.lochat.integrations;
|
|||
|
||||
import com.loki.lochat.LoChat;
|
||||
import com.loki.lochat.api.service.MuteService;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.loki.lochat.LoChat;
|
|||
import com.loki.lochat.api.service.ChatService;
|
||||
import com.loki.lochat.api.service.MessagingService;
|
||||
import com.loki.lochat.gradient.GradientModule;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -14,6 +14,8 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
|
||||
private final LoChat plugin;
|
||||
|
|
@ -48,7 +50,9 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (player == null) return "";
|
||||
if (player == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
GradientModule gradient = plugin.getGradientModule();
|
||||
|
|
@ -58,7 +62,9 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
case "global_enabled" -> String.valueOf(!chatService.isGlobalChatDisabled(uuid));
|
||||
case "last_pm" -> {
|
||||
Optional<UUID> lastOpt = messagingService.getLastConversation(uuid);
|
||||
if (lastOpt.isEmpty()) yield "";
|
||||
if (lastOpt.isEmpty()) {
|
||||
yield "";
|
||||
}
|
||||
var lastPlayer = Bukkit.getOfflinePlayer(lastOpt.get());
|
||||
yield lastPlayer.getName() != null ? lastPlayer.getName() : "";
|
||||
}
|
||||
|
|
@ -68,7 +74,9 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
// Используем TAB формат §x§R§R§G§G§B§B для совместимости с TAB плагином
|
||||
case "gradient_full", "full" -> {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield player.getName() != null ? player.getName() : "";
|
||||
if (onlinePlayer == null) {
|
||||
yield player.getName() != null ? player.getName() : "";
|
||||
}
|
||||
|
||||
// Если gradient модуль выключен — берём только LuckPerms префикс + ник
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
|
|
@ -80,7 +88,9 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
}
|
||||
case "gradient_name", "name" -> {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield player.getName() != null ? player.getName() : "";
|
||||
if (onlinePlayer == null) {
|
||||
yield player.getName() != null ? player.getName() : "";
|
||||
}
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
yield player.getName();
|
||||
|
|
@ -89,16 +99,24 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
}
|
||||
case "gradient_prefix", "prefix" -> {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield "";
|
||||
if (onlinePlayer == null) {
|
||||
yield "";
|
||||
}
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) yield "";
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
yield "";
|
||||
}
|
||||
yield gradient.getPrefix(onlinePlayer);
|
||||
}
|
||||
case "lp_prefix" -> {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield "";
|
||||
if (onlinePlayer == null) {
|
||||
yield "";
|
||||
}
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) yield "";
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
yield "";
|
||||
}
|
||||
yield gradient.getLuckPermsPrefix(onlinePlayer);
|
||||
}
|
||||
default -> null;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.loki.lochat.integrations;
|
||||
|
||||
import com.loki.lochat.LoChat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
|
@ -57,7 +58,9 @@ public class SkinsRestorerHook {
|
|||
* @return URL текстуры или null
|
||||
*/
|
||||
public String getPlayerSkinTexture(Player player) {
|
||||
if (!enabled) return null;
|
||||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Object property = getSkinDataMethod.invoke(skinsAPI, player.getName());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loki.lochat.integrations.discord;
|
|||
|
||||
import com.loki.lochat.integrations.DiscordWebhook;
|
||||
import com.loki.lochat.utils.platform.FoliaUtil;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
|
@ -140,7 +141,9 @@ public class DiscordMessageService {
|
|||
}
|
||||
|
||||
private String sanitizeMessage(String message) {
|
||||
if (message == null) return "";
|
||||
if (message == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
message = COLOR_CODE_PATTERN.matcher(message).replaceAll("");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue