esdion 發表於 2026-2-9 22:13

操作

package l1j.server.server.utils;

import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_SystemMessage;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* WHO功能統一錯誤處理器
* 處理WHO相關功能的各種錯誤情況
*/
public class WhoErrorHandler {

        private static final Logger _log = Logger.getLogger(WhoErrorHandler.class.getName());
       
        // 錯誤類型枚舉
        public enum ErrorType {
                PLAYER_NOT_FOUND,
                PERMISSION_DENIED,
                NETWORK_ERROR,
                DATABASE_ERROR,
                VALIDATION_ERROR,
                TIMEOUT_ERROR,
                UNKNOWN_ERROR
        }

        /**
       * 處理錯誤並發送適當的訊息給玩家
       */
        public static void handleError(L1PcInstance pc, Exception e, String operation) {
                if (pc == null) {
                        _log.log(Level.WARNING, "WHO操作失敗(玩家為null): " + operation, e);
                        return;
                }

                _log.log(Level.WARNING, "WHO功能執行失敗: " + operation + " - 玩家: " + pc.getName(), e);
               
                ErrorType errorType = classifyError(e);
                String message = getErrorMessage(errorType);
               
                pc.sendPackets(new S_SystemMessage(message));
        }

        /**
       * 處理特定錯誤類型
       */
        public static void handleError(L1PcInstance pc, ErrorType errorType, String details) {
                if (pc == null) {
                        _log.log(Level.WARNING, "WHO操作失敗(玩家為null): " + details);
                        return;
                }

                _log.log(Level.WARNING, "WHO操作失敗: " + errorType + " - " + details + " - 玩家: " + pc.getName());
               
                String message = getErrorMessage(errorType);
                if (details != null && !details.isEmpty()) {
                        message += " (" + details + ")";
                }
               
                pc.sendPackets(new S_SystemMessage(message));
        }

        /**
       * 處理玩家未找到的錯誤
       */
        public static void handlePlayerNotFound(L1PcInstance pc, String targetName) {
                if (pc == null) return;
               
                _log.log(Level.INFO, "玩家未找到: " + targetName + " - 查詢者: " + pc.getName());
                pc.sendPackets(new S_SystemMessage("找不到玩家: " + targetName));
        }

        /**
       * 處理權限不足的錯誤
       */
        public static void handlePermissionDenied(L1PcInstance pc, String action) {
                if (pc == null) return;

頁: [1]
查看完整版本: 操作