mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 22:05:11 +00:00
Fix modifiers
This commit is contained in:
parent
8257382ca1
commit
7bc6b00af0
94 changed files with 189 additions and 96 deletions
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class Constants {
|
||||
public final class Constants {
|
||||
|
||||
public static final boolean IS_MINECRAFT_ENV = EnvironmentUtils.isMinecraftEnvironment();
|
||||
|
||||
|
|
@ -33,4 +33,7 @@ public class Constants {
|
|||
|
||||
// For DMCC Client use
|
||||
public static final AtomicBoolean OVERWRITE_MINECRAFT_SOURCE_MESSAGES = new AtomicBoolean(false);
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,14 @@ import static com.xujiayao.discord_mc_chat.Constants.VERSION;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DMCC {
|
||||
public final class DMCC {
|
||||
|
||||
private static ServerDMCC serverInstance;
|
||||
private static ClientDMCC clientInstance;
|
||||
|
||||
private DMCC() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DMCC. Blocks until initialization is complete.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ClientDMCC {
|
||||
public final class ClientDMCC {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ClientHandler extends SimpleChannelInboundHandler<Packet> {
|
||||
public final class ClientHandler extends SimpleChannelInboundHandler<Packet> {
|
||||
|
||||
private static final int CONSOLE_COMMAND_TIMEOUT_SECONDS = 10;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class NettyClient {
|
||||
public final class NettyClient {
|
||||
|
||||
private static final int MAX_RECONNECT_DELAY = 512;
|
||||
private final String host;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class CommandAutoCompleter {
|
||||
public final class CommandAutoCompleter {
|
||||
|
||||
private CommandAutoCompleter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates auto-complete suggestions based on the current input and sender's OP level.
|
||||
|
|
|
|||
|
|
@ -30,11 +30,14 @@ import java.util.concurrent.Executors;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class CommandManager {
|
||||
public final class CommandManager {
|
||||
|
||||
private static final Map<String, Command> COMMANDS = new ConcurrentHashMap<>();
|
||||
private static ExecutorService commandExecutor;
|
||||
|
||||
private CommandManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize and register built-in commands based on the current operating mode.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConsoleCommand implements Command {
|
||||
public final class ConsoleCommand implements Command {
|
||||
|
||||
private static final int CONSOLE_TIMEOUT_SECONDS = 30;
|
||||
private static final int LOCAL_COMMAND_TIMEOUT_SECONDS = 10;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecuteCommand implements Command {
|
||||
public final class ExecuteCommand implements Command {
|
||||
|
||||
private static final int EXECUTE_TIMEOUT_SECONDS = 30;
|
||||
private static final Map<String, CompletableFuture<ExecuteResponsePacket>> pendingRequests = new ConcurrentHashMap<>();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import static com.xujiayao.discord_mc_chat.Constants.IS_MINECRAFT_ENV;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class HelpCommand implements Command {
|
||||
public final class HelpCommand implements Command {
|
||||
|
||||
private static String padRight(String text, int width) {
|
||||
if (text.length() >= width) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class InfoCommand implements Command {
|
||||
public final class InfoCommand implements Command {
|
||||
|
||||
private static final int INFO_REQUEST_TIMEOUT_SECONDS = 3;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import com.xujiayao.discord_mc_chat.utils.i18n.I18nManager;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LinkCommand implements Command {
|
||||
public final class LinkCommand implements Command {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LinksCommand implements Command {
|
||||
public final class LinksCommand implements Command {
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.withZone(ZoneId.systemDefault());
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.xujiayao.discord_mc_chat.utils.i18n.I18nManager;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LogCommand implements Command {
|
||||
public final class LogCommand implements Command {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.xujiayao.discord_mc_chat.utils.i18n.I18nManager;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ReloadCommand implements Command {
|
||||
public final class ReloadCommand implements Command {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import static com.xujiayao.discord_mc_chat.standalone.StandaloneDMCC.SHUTDOWN_TH
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ShutdownCommand implements Command {
|
||||
public final class ShutdownCommand implements Command {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.stream.Stream;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class StatsCommand implements Command {
|
||||
public final class StatsCommand implements Command {
|
||||
|
||||
private static StatsProvider provider;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import com.xujiayao.discord_mc_chat.utils.i18n.I18nManager;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class UnlinkCommand implements Command {
|
||||
public final class UnlinkCommand implements Command {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class WhitelistCommand implements Command {
|
||||
public final class WhitelistCommand implements Command {
|
||||
|
||||
private static final int WHITELIST_COMMAND_TIMEOUT_SECONDS = 10;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.util.function.Supplier;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class NetworkManager {
|
||||
public final class NetworkManager {
|
||||
|
||||
private static final AtomicReference<ClientDMCC> clientInstance = new AtomicReference<>();
|
||||
|
||||
|
|
@ -43,6 +43,9 @@ public class NetworkManager {
|
|||
private static final Map<String, List<String>> consoleAutoCompleteCache = new ConcurrentHashMap<>();
|
||||
private static final Object consoleAutoCompleteLock = new Object();
|
||||
|
||||
private NetworkManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the client instance for network operations.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class AuthResponsePacket extends Packet {
|
||||
public final class AuthResponsePacket extends Packet {
|
||||
public String hash;
|
||||
|
||||
public AuthResponsePacket(String hash) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ChallengePacket extends Packet {
|
||||
public final class ChallengePacket extends Packet {
|
||||
public String salt;
|
||||
|
||||
public ChallengePacket(String salt) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DisconnectPacket extends Packet {
|
||||
public final class DisconnectPacket extends Packet {
|
||||
public String key;
|
||||
public Object[] args;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class HandshakePacket extends Packet {
|
||||
public final class HandshakePacket extends Packet {
|
||||
public String serverName;
|
||||
public String dmccVersion;
|
||||
public String minecraftVersion;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LoginSuccessPacket extends Packet {
|
||||
public final class LoginSuccessPacket extends Packet {
|
||||
public String language;
|
||||
public boolean overwriteMinecraftSourceMessages;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConsoleAutoCompleteRequestPacket extends Packet {
|
||||
public final class ConsoleAutoCompleteRequestPacket extends Packet {
|
||||
public String input;
|
||||
public int opLevel;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConsoleAutoCompleteResponsePacket extends Packet {
|
||||
public final class ConsoleAutoCompleteResponsePacket extends Packet {
|
||||
public String serverName;
|
||||
public List<String> suggestions;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConsoleRequestPacket extends Packet {
|
||||
public final class ConsoleRequestPacket extends Packet {
|
||||
public String requestId;
|
||||
public int opLevel;
|
||||
public String commandLine;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConsoleResponsePacket extends Packet {
|
||||
public final class ConsoleResponsePacket extends Packet {
|
||||
public String requestId;
|
||||
public String response;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecuteAutoCompleteRequestPacket extends Packet {
|
||||
public final class ExecuteAutoCompleteRequestPacket extends Packet {
|
||||
public String input;
|
||||
public int opLevel;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecuteAutoCompleteResponsePacket extends Packet {
|
||||
public final class ExecuteAutoCompleteResponsePacket extends Packet {
|
||||
public String serverName;
|
||||
public List<String> suggestions;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecuteRequestPacket extends Packet {
|
||||
public final class ExecuteRequestPacket extends Packet {
|
||||
public String requestId;
|
||||
public int opLevel;
|
||||
public String command;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecuteResponsePacket extends Packet {
|
||||
public final class ExecuteResponsePacket extends Packet {
|
||||
public String requestId;
|
||||
public String response;
|
||||
public byte[] fileData;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class InfoRequestPacket extends Packet {
|
||||
public final class InfoRequestPacket extends Packet {
|
||||
public long sentAtMillis;
|
||||
|
||||
public InfoRequestPacket(long sentAtMillis) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class InfoResponsePacket extends Packet {
|
||||
public final class InfoResponsePacket extends Packet {
|
||||
public String serverName;
|
||||
|
||||
public long connectionLatencyMillis;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LinkRequestPacket extends Packet {
|
||||
public final class LinkRequestPacket extends Packet {
|
||||
public String minecraftUuid;
|
||||
public String playerName;
|
||||
public boolean joinCheck;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LinkResponsePacket extends Packet {
|
||||
public final class LinkResponsePacket extends Packet {
|
||||
public String minecraftUuid;
|
||||
public String code;
|
||||
public boolean alreadyLinked;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class OpSyncPacket extends Packet {
|
||||
public final class OpSyncPacket extends Packet {
|
||||
public Map<String, Integer> opLevels;
|
||||
|
||||
public OpSyncPacket(Map<String, Integer> opLevels) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class UnlinkRequestPacket extends Packet {
|
||||
public final class UnlinkRequestPacket extends Packet {
|
||||
public String minecraftUuid;
|
||||
public String playerName;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class UnlinkResponsePacket extends Packet {
|
||||
public final class UnlinkResponsePacket extends Packet {
|
||||
public String minecraftUuid;
|
||||
public boolean success;
|
||||
public String discordName;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DiscordEventPacket extends Packet {
|
||||
public final class DiscordEventPacket extends Packet {
|
||||
|
||||
/**
|
||||
* The type of Discord event.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MinecraftEventPacket extends Packet {
|
||||
public final class MinecraftEventPacket extends Packet {
|
||||
public MessageType type;
|
||||
public Map<String, String> placeholders;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class TextSegment implements Serializable {
|
||||
public final class TextSegment implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class KeepAlivePacket extends Packet {
|
||||
public final class KeepAlivePacket extends Packet {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LatencyPingPacket extends Packet {
|
||||
public final class LatencyPingPacket extends Packet {
|
||||
public long sentAtMillis;
|
||||
|
||||
public LatencyPingPacket(long sentAtMillis) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.xujiayao.discord_mc_chat.network.packets.Packet;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LatencyPongPacket extends Packet {
|
||||
public final class LatencyPongPacket extends Packet {
|
||||
public long sentAtMillis;
|
||||
|
||||
public LatencyPongPacket(long sentAtMillis) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class NettyServer {
|
||||
public final class NettyServer {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ServerDMCC {
|
||||
public final class ServerDMCC {
|
||||
|
||||
private final String host;
|
||||
private final String sharedSecret;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ServerHandler extends SimpleChannelInboundHandler<Packet> {
|
||||
public final class ServerHandler extends SimpleChannelInboundHandler<Packet> {
|
||||
|
||||
private final NettyServer server;
|
||||
private String expectedNonce;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DiscordEventHandler extends ListenerAdapter {
|
||||
public final class DiscordEventHandler extends ListenerAdapter {
|
||||
|
||||
private static final int AUTOCOMPLETE_TIMEOUT_SECONDS = 5;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,13 +47,16 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DiscordManager {
|
||||
public final class DiscordManager {
|
||||
|
||||
private static final Map<String, String> DISCORD_NAME_CACHE = new ConcurrentHashMap<>();
|
||||
private static JDA jda;
|
||||
private static ScheduledExecutorService statusUpdateExecutor;
|
||||
private static ScheduledFuture<?> presenceUpdateTask;
|
||||
|
||||
private DiscordManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Discord bot.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class JdaCommandSender implements CommandSender, LinkCommand.DiscordUserContextProvider {
|
||||
public final class JdaCommandSender implements CommandSender, LinkCommand.DiscordUserContextProvider {
|
||||
|
||||
private final SlashCommandInteractionEvent event;
|
||||
private final int opLevel;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ import java.util.List;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class OpLevelResolver {
|
||||
public final class OpLevelResolver {
|
||||
|
||||
private OpLevelResolver() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the top-level OP level for a Discord user (used by standalone/single_server).
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LinkedAccountManager {
|
||||
public final class LinkedAccountManager {
|
||||
|
||||
private static final Path LINKS_FILE = Paths.get("./config/discord_mc_chat/account_linking/links.json");
|
||||
|
||||
|
|
@ -40,6 +40,9 @@ public class LinkedAccountManager {
|
|||
// Discord name resolver, set by the server module to avoid circular dependencies
|
||||
private static Function<String, String> discordNameResolver;
|
||||
|
||||
private LinkedAccountManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a function that resolves Discord user ID to username.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,11 +33,14 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class OpSyncManager {
|
||||
public final class OpSyncManager {
|
||||
|
||||
private static final ExecutorService SYNC_EXECUTOR =
|
||||
Executors.newSingleThreadExecutor(ExecutorServiceUtils.newThreadFactory("DMCC-OpSync"));
|
||||
|
||||
private OpSyncManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a full OP level sync for all linked accounts.
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class VerificationCodeManager {
|
||||
public final class VerificationCodeManager {
|
||||
|
||||
private static final int CODE_LENGTH = 6;
|
||||
private static final long CODE_EXPIRY_MILLIS = 5 * 60 * 1000L; // 5 minutes
|
||||
|
|
@ -31,6 +31,9 @@ public class VerificationCodeManager {
|
|||
// Minecraft UUID -> Code (for fast lookup by player UUID)
|
||||
private static final Map<String, String> UUID_TO_CODE = new ConcurrentHashMap<>();
|
||||
|
||||
private VerificationCodeManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates or refreshes a verification code for a Minecraft player.
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import java.util.regex.Pattern;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class DiscordMessageParser {
|
||||
public final class DiscordMessageParser {
|
||||
|
||||
// Discord Markdown patterns
|
||||
private static final Pattern CODE_BLOCK_PATTERN = Pattern.compile("```(\\w*)\\n?([\\s\\S]*?)```");
|
||||
|
|
@ -102,6 +102,9 @@ public class DiscordMessageParser {
|
|||
private static final String EMBED_LABEL_PREFIX = "<embed title=[";
|
||||
private static final String LABEL_SUFFIX = "]>";
|
||||
|
||||
private DiscordMessageParser() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the main message line segments for a Discord chat message.
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -5,5 +5,8 @@ package com.xujiayao.discord_mc_chat.server.message;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MinecraftMessageParser {
|
||||
public final class MinecraftMessageParser {
|
||||
|
||||
private MinecraftMessageParser() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.xujiayao.discord_mc_chat.utils.logging.impl.LoggerImpl;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class StandaloneDMCC {
|
||||
public final class StandaloneDMCC {
|
||||
|
||||
public static final Thread SHUTDOWN_THREAD = new Thread(() -> {
|
||||
DMCC.shutdown();
|
||||
|
|
@ -17,6 +17,9 @@ public class StandaloneDMCC {
|
|||
LoggerImpl.shutdown();
|
||||
}, "DMCC-ShutdownHook");
|
||||
|
||||
private StandaloneDMCC() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Standalone DMCC.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class TerminalManager {
|
||||
public final class TerminalManager {
|
||||
|
||||
private static final Path LOG_CACHE_DIR = Paths.get("./config/discord_mc_chat/cache/log");
|
||||
|
||||
private TerminalManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes and starts the terminal.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ import static com.xujiayao.discord_mc_chat.Constants.YAML_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class EnvironmentUtils {
|
||||
public final class EnvironmentUtils {
|
||||
|
||||
private EnvironmentUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if running in a Minecraft environment.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ExecutorServiceUtils {
|
||||
public final class ExecutorServiceUtils {
|
||||
|
||||
private ExecutorServiceUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ThreadFactory that ensures all created threads inherit the current Mod ClassLoader.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ import static com.xujiayao.discord_mc_chat.Constants.OK_HTTP_CLIENT;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class HttpUtils {
|
||||
public final class HttpUtils {
|
||||
|
||||
private HttpUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a GET request to the specified URL and returns the response body as a string.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ import static com.xujiayao.discord_mc_chat.Constants.YAML_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class JsonUtils {
|
||||
public final class JsonUtils {
|
||||
|
||||
private JsonUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JSON String to a Map of String to String.
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LogFileUtils {
|
||||
public final class LogFileUtils {
|
||||
|
||||
private static final String LOGS_DIR = "./logs";
|
||||
|
||||
private LogFileUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists available log files in the given directory.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,11 +17,14 @@ import static com.xujiayao.discord_mc_chat.Constants.JSON_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MojangUtils {
|
||||
public final class MojangUtils {
|
||||
|
||||
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
private static final Map<String, String> NAME_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private MojangUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a Minecraft player name from a UUID string, with an optional fallback name
|
||||
* for offline-mode UUIDs.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ package com.xujiayao.discord_mc_chat.utils;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class StringUtils {
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special characters in strings.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class YamlUtils {
|
||||
public final class YamlUtils {
|
||||
|
||||
private static final List<String> REQUIRED_MODIFIED_KEYS = List.of(
|
||||
"discord.bot.token",
|
||||
|
|
@ -23,6 +23,9 @@ public class YamlUtils {
|
|||
"multi_server.connection.shared_secret"
|
||||
);
|
||||
|
||||
private YamlUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the loaded config against the template with optional check for modification.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,11 +23,14 @@ import static com.xujiayao.discord_mc_chat.Constants.YAML_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ConfigManager {
|
||||
public final class ConfigManager {
|
||||
|
||||
private static final Path CONFIG_FILE_PATH = Paths.get("./config/discord_mc_chat/config.yml");
|
||||
private static JsonNode config;
|
||||
|
||||
private ConfigManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the configuration file based on the determined operating mode.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -21,13 +21,16 @@ import static com.xujiayao.discord_mc_chat.Constants.YAML_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ModeManager {
|
||||
public final class ModeManager {
|
||||
|
||||
private static final Path MODE_FILE_PATH = Paths.get("./config/discord_mc_chat/mode.yml");
|
||||
private static final String MODE_TEMPLATE_PATH = "/config/mode.yml";
|
||||
|
||||
private static String mode = "";
|
||||
|
||||
private ModeManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and validates the mode from mode.yml. If the file does not exist,
|
||||
* it creates a default one and returns false to halt initialization.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ import java.util.concurrent.CompletableFuture;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class CoreEvents {
|
||||
public final class CoreEvents {
|
||||
|
||||
private CoreEvents() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Posted when a Minecraft command needs to be executed on the local Minecraft server.
|
||||
|
|
|
|||
|
|
@ -10,10 +10,13 @@ import java.util.function.Consumer;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class EventManager {
|
||||
public final class EventManager {
|
||||
|
||||
private static final ConcurrentHashMap<Class<?>, List<Consumer<?>>> handlers = new ConcurrentHashMap<>();
|
||||
|
||||
private EventManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler for a specific event type.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,13 +25,16 @@ import static com.xujiayao.discord_mc_chat.Constants.YAML_MAPPER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class I18nManager {
|
||||
public final class I18nManager {
|
||||
|
||||
private static final Map<String, String> DMCC_TRANSLATIONS = new HashMap<>();
|
||||
private static final Path CUSTOM_MESSAGES_DIR = Paths.get("./config/discord_mc_chat/custom_messages");
|
||||
private static String language = detectLanguage();
|
||||
private static JsonNode customMessages;
|
||||
|
||||
private I18nManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently selected language code.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class Logger {
|
||||
public final class Logger {
|
||||
|
||||
private final org.slf4j.Logger logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import java.util.concurrent.ConcurrentMap;
|
|||
* @author Ceki Gülcü
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LoggerFactory implements ILoggerFactory {
|
||||
public final class LoggerFactory implements ILoggerFactory {
|
||||
|
||||
ConcurrentMap<String, Logger> loggerMap;
|
||||
private final ConcurrentMap<String, Logger> loggerMap;
|
||||
|
||||
public LoggerFactory() {
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
|
|
@ -45,7 +45,7 @@ public class LoggerFactory implements ILoggerFactory {
|
|||
* @param name The name of the logger to create
|
||||
* @return The newly created logger
|
||||
*/
|
||||
protected Logger createLogger(String name) {
|
||||
private Logger createLogger(String name) {
|
||||
return new LoggerImpl(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class LoggerImpl implements Logger {
|
||||
public final class LoggerImpl implements Logger {
|
||||
|
||||
private static volatile PrintWriter fileWriter;
|
||||
private static boolean fileWriterInitialized = false;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import org.slf4j.spi.SLF4JServiceProvider;
|
|||
* @author Ceki Gülcü
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class ServiceProvider implements SLF4JServiceProvider {
|
||||
public final class ServiceProvider implements SLF4JServiceProvider {
|
||||
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ package com.xujiayao.discord_mc_chat.minecraft;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class FabricDMCC {
|
||||
public final class FabricDMCC {
|
||||
// TODO Fabric support will be added in the future.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import net.neoforged.fml.common.Mod;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mod("discord_mc_chat")
|
||||
public class NeoForgeDMCC {
|
||||
public final class NeoForgeDMCC {
|
||||
|
||||
/**
|
||||
* Start NeoForge DMCC.
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ import static net.minecraft.commands.Commands.literal;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MinecraftCommands {
|
||||
public final class MinecraftCommands {
|
||||
|
||||
private MinecraftCommands() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers /dmcc commands.
|
||||
|
|
|
|||
|
|
@ -72,11 +72,14 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MinecraftEventHandler {
|
||||
public final class MinecraftEventHandler {
|
||||
|
||||
private static final String DEFAULT_MENTION_STYLE = "title";
|
||||
private static MinecraftServer serverInstance;
|
||||
|
||||
private MinecraftEventHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Minecraft event handlers.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ import net.minecraft.world.level.GameType;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class MinecraftEvents {
|
||||
public final class MinecraftEvents {
|
||||
|
||||
private MinecraftEvents() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Posted when the server is started.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(Commands.class)
|
||||
public class MixinCommands {
|
||||
public final class MixinCommands {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(EmoteCommands.class)
|
||||
public class MixinEmoteCommands {
|
||||
public final class MixinEmoteCommands {
|
||||
|
||||
@Inject(method = "lambda$register$0", at = @At("HEAD"), cancellable = true)
|
||||
private static void lambda$register$0(CommandContext<CommandSourceStack> commandContext, PlayerChatMessage playerChatMessage, CallbackInfo ci) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(GameModeCommand.class)
|
||||
public class MixinGameModeCommand {
|
||||
public final class MixinGameModeCommand {
|
||||
|
||||
@Inject(method = "setGameMode(Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/GameType;)Z", at = @At("HEAD"))
|
||||
private static void setGameMode(CommandSourceStack commandSourceStack, ServerPlayer player, GameType gameType, CallbackInfoReturnable<Boolean> cir) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MixinMinecraftServer {
|
||||
public final class MixinMinecraftServer {
|
||||
|
||||
@Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||
private void serverStarted(CallbackInfo ci) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import java.util.regex.Pattern;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(MsgCommand.class)
|
||||
public class MixinMsgCommand {
|
||||
public final class MixinMsgCommand {
|
||||
|
||||
@Unique
|
||||
private static final Pattern MSG_PATTERN = Pattern.compile("^(?:msg|tell|w) @a .*");
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(PlayerList.class)
|
||||
public class MixinPlayerList {
|
||||
public final class MixinPlayerList {
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("RETURN"))
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(ReloadableServerResources.class)
|
||||
public class MixinReloadableServerResources {
|
||||
public final class MixinReloadableServerResources {
|
||||
|
||||
@Inject(method = "lambda$loadResources$2", at = @At("RETURN"))
|
||||
private static void loadResources(ReloadableServerResources reloadableserverresources, Void p_214306_, CallbackInfoReturnable<ReloadableServerResources> cir) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(SayCommand.class)
|
||||
public class MixinSayCommand {
|
||||
public final class MixinSayCommand {
|
||||
|
||||
@Inject(method = "lambda$register$0", at = @At("HEAD"), cancellable = true)
|
||||
private static void lambda$register$0(CommandContext<CommandSourceStack> commandContext, PlayerChatMessage playerChatMessage, CallbackInfo ci) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class MixinServerGamePacketListenerImpl {
|
||||
public final class MixinServerGamePacketListenerImpl {
|
||||
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer {
|
||||
public final class MixinServerPlayer {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void die(DamageSource damageSource, CallbackInfo ci) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
|||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(TellRawCommand.class)
|
||||
public class MixinTellRawCommand {
|
||||
public final class MixinTellRawCommand {
|
||||
|
||||
@Unique
|
||||
private static final Pattern TELLRAW_PATTERN = Pattern.compile("^tellraw @a .*");
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
|||
*
|
||||
* @author Xujiayao
|
||||
*/
|
||||
public class TranslationManager {
|
||||
public final class TranslationManager {
|
||||
|
||||
private static final Map<String, String> TRANSLATIONS = new HashMap<>();
|
||||
private static final Path CACHE_DIR = Paths.get("./config/discord_mc_chat/cache/lang");
|
||||
|
|
@ -42,6 +42,9 @@ public class TranslationManager {
|
|||
private static String currentLoadedLanguage = "";
|
||||
private static MinecraftServer server;
|
||||
|
||||
private TranslationManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Minecraft server instance.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue