Class ErrorUtils

java.lang.Object
ua.mcchickenstudio.opencreative.utils.ErrorUtils

public final class ErrorUtils extends Object

ErrorUtils

This class contains utilities for handling exceptions and logging them in console with friendly look.
  • Constructor Details

    • ErrorUtils

      public ErrorUtils()
  • Method Details

    • cutClassesName

      public static String cutClassesName(@Nullable @Nullable String text)
      Cuts common packages paths from stack trace text.
      Parameters:
      text - stack trace to cut.
      Returns:
      stack trace without package paths, or Error message is not available, if text is null.
    • parseException

      @NotNull public static @NotNull String parseException(@NotNull @NotNull Exception error, boolean colored)
      Parses exception into user-friendly message, that can be printed into console or sent to player.
      Parameters:
      error - exception to parse.
      colored - true - for player, false - for console.
      Returns:
      user-friendly exception.
    • sendPlayerErrorMessage

      public static void sendPlayerErrorMessage(org.bukkit.entity.Player player, String errorMessage)
      Notifies player about error by sending message with error description in chat and sends warning log in console.
      Parameters:
      player - player to send error message.
      errorMessage - message of exception.
    • sendPlayerErrorMessage

      public static void sendPlayerErrorMessage(org.bukkit.entity.Player player, String errorMessage, Exception error)
      Notifies player about error by sending message with error description in chat and sends warning log in console with stack traces to find line, where error has occurred.
      Parameters:
      player - player to send error message.
      errorMessage - description of error.
      error - exception, that has occurred.
    • sendPlanetErrorMessage

      public static void sendPlanetErrorMessage(@NotNull @NotNull Planet planet, @NotNull @NotNull String error)
      Notifies planet players about general error by sending message with error description in chat and sends warning log in console.

      Not related to coding errors.

      Parameters:
      planet - planet to send error message.
      error - description of error.
    • sendPlanetErrorMessage

      public static void sendPlanetErrorMessage(Planet planet, String errorMessage, Exception error)
      Notifies planet players about general error by sending message with error description in chat and sends warning log in console with stack traces to find line, where error has occurred.

      Not related to coding errors.

      Parameters:
      planet - planet to send error message.
      errorMessage - description of error.
      error - exception, that has occurred.
    • sendPlanetLimitWarningMessage

      public static void sendPlanetLimitWarningMessage(@NotNull @NotNull Action action, @NotNull @NotNull String limitID, int count, int limit)
      Notifies planet players about reaching limit, so some operations will be cancelled.
      Parameters:
      action - action, that produced warning.
      limitID - limit name.
      count - count of operations.
      limit - maximum amount of operations.
    • sendPlanetLimitWarningMessage

      public static void sendPlanetLimitWarningMessage(@NotNull @NotNull Planet planet, @NotNull @NotNull String limitID, @Nullable @Nullable String command, int count, int limit)
      Notifies planet players about reaching limit, so some operations will be canceled.
      Parameters:
      planet - planet, where limit was reached.
      limitID - limit name.
      command - command to execute on click.
      count - count of operations.
      limit - maximum amount of operations.
    • sendPlanetCodeWarningMessage

      public static void sendPlanetCodeWarningMessage(@NotNull @NotNull Executor executor, @NotNull @NotNull Action action, @NotNull @NotNull String warningID, @NotNull @NotNull PlaceholderReplacer placeholder)
      Notifies planet players about coding warning, that has happened while executing action in executor.

      Warnings don't stop executing the code, they just send notification, that something can be improved.

      Parameters:
      executor - executor, that executed action.
      action - action, that produced warning.
      warningID - path of warning message.
      placeholder - placeholders to replace.
    • sendPlanetCodeErrorMessage

      public static void sendPlanetCodeErrorMessage(Executor executor, Action action, String errorMessage, Exception error)
      Notifies planet players about coding exception, that has happened while executing action in executor.

      Errors stop executing next actions to prevent happening new errors in same coding line. They tell that something went wrong, and it needs to be fixed.

      Parameters:
      executor - executor, that executed action.
      action - action, that produced error.
      errorMessage - description of error.
      error - exception, that has occurred.
    • notifyBuildModeByCode

      public static void notifyBuildModeByCode(Executor executor, Action action)
    • sendPlanetCodeErrorMessage

      public static void sendPlanetCodeErrorMessage(Executor executor, Action action, org.bukkit.entity.Entity entity, String errorMessage)
      Notifies planet players about coding exception, that has happened while executing action in executor.

      Errors stop executing next actions to prevent happening new errors in same coding line. They tell that something went wrong, and it needs to be fixed.

      Parameters:
      executor - executor, that executed action.
      action - action, that produced error.
      entity - target of action.
      errorMessage - description of error.
    • sendPlanetCodeCriticalErrorMessage

      public static void sendPlanetCodeCriticalErrorMessage(Planet planet, Executor executor, String errorMessage)
      Notifies planet players about coding fatal error, that has happened while executing code.

      Critical errors stop entire code in planet, and change its mode to Build.

      Parameters:
      planet - planet to send error message.
      executor - executor, that executed action.
      errorMessage - description of error.
    • sendPlanetCodeErrorMessage

      public static void sendPlanetCodeErrorMessage(Planet planet, Executor executor, String errorMessage)
      Notifies planet players about coding exception, that has happened while executing action in executor.

      Errors stop executing next actions to prevent happening new errors in same coding line. They tell that something went wrong, and it needs to be fixed.

      Parameters:
      planet - planet to send error message.
      executor - executor, that executed action.
      errorMessage - description of error.
    • sendPlanetCompileErrorMessage

      public static void sendPlanetCompileErrorMessage(Planet planet, org.bukkit.block.Block block, String errorMessage)
      Notifies planet players about coding issue, that has happened while compiling new code from dev planet.
      Parameters:
      planet - planet to send error message.
      block - block, that caused issue.
      errorMessage - description of error.
    • sendPlanetCompileErrorMessage

      public static void sendPlanetCompileErrorMessage(Planet planet, List<org.bukkit.block.Block> unknownBlocks)
      Notifies planet players about unknown coding blocks, that were found while compiling a new code from dev planet.
      Parameters:
      planet - planet to send error message.
      unknownBlocks - list of unknown blocks.
    • sendWarningErrorMessage

      public static void sendWarningErrorMessage(String warning)
      Sends warning log in console about issue with plugin.
      Parameters:
      warning - description of warning.
    • sendWarningMessage

      public static void sendWarningMessage(String errorMessage, Exception error)
      Sends warning log in console with stack traces to find line, that produced not too serious error.
      Parameters:
      errorMessage - description of warning.
      error - exception, that has occurred.
    • sendCriticalErrorMessage

      public static void sendCriticalErrorMessage(String errorMessage)
      Sends error log in console about problem with plugin.
      Parameters:
      errorMessage - description of error.
    • sendCriticalErrorMessage

      public static void sendCriticalErrorMessage(String errorMessage, Exception error)
      Sends error log in console with stack traces to find line, that produced critical error.
      Parameters:
      errorMessage - description of critical error.
      error - exception, that has occurred.
    • sendDebug

      public static void sendDebug(String message)
      Sends debug log in console, only if debug mode is enabled in plugin's settings.
      Parameters:
      message - debug log.
    • sendDebugError

      public static void sendDebugError(String errorMessage, Exception error)
      Sends error log in console with stack traces, only if debug mode is enabled in plugin's settings.

      Used for not serious errors for server owners.

      Parameters:
      errorMessage - description of critical error.
      error - exception, that has occurred.
    • sendCodingDebugNotFoundVariable

      public static void sendCodingDebugNotFoundVariable(Planet planet, String name)
      Sends notification to planet players about not found value while filling arguments in action, only if planet's debug mode is enabled.

      Happens when player forgets to fill items in coding container.

      Parameters:
      planet - planet to send error message.
      name - name of value.
    • sendCodingNotFoundEventValue

      public static void sendCodingNotFoundEventValue(Planet planet, Executor executor, Class<? extends EventValue> clazz)
      Sends notification to planet players about not found event value while executing actions or conditions, that require event value.

      Happens when player uses wrong coding block in event.

      Parameters:
      planet - planet to send message.
      executor - executor, that stores event.
      clazz - class of event value, that was not found.
    • sendCodingDebugLog

      public static void sendCodingDebugLog(Planet planet, String log)
      Sends debug log message to planet players, if planet's debug mode is enabled.

      Used to describe some reasons of events cancellations, actions fails or processes.

      Parameters:
      planet - planet to send log.
      log - debug log.
    • sendCodingDebugVariable

      public static void sendCodingDebugVariable(Planet planet, String name, Object value)
      Sends notification to planet players about found value while filling arguments in action, only if planet's debug mode is enabled.
      Parameters:
      planet - planet to send message.
      name - executor, that stores event.
      value - value.
    • sendCodingDebugExecutor

      public static void sendCodingDebugExecutor(Executor executor)
      Sends notification to planet players about calling executor.
      Parameters:
      executor - executor, that has activated.
    • sendCodingDebugAction

      public static void sendCodingDebugAction(Action action)
      Sends notification to planet players about action information, that will be executed. Only if planet's debug mode is enabled.
      Parameters:
      action - action, that will be executed.