Class CraftsNetBuilder

java.lang.Object
de.craftsblock.craftsnet.builder.CraftsNetBuilder
Direct Known Subclasses:
AddonContainingBuilder

public class CraftsNetBuilder extends Object
Builder class for configuring the CraftsNet.
Since:
3.0.3-SNAPSHOT
See Also:
  • Constructor Details

    • CraftsNetBuilder

      public CraftsNetBuilder()
      Constructs a new CraftsNetBuilder instance with default configuration settings.
  • Method Details

    • withArgs

      public CraftsNetBuilder withArgs(String[] args)
      Configures the builder using a set of command-line arguments.

      Parses the provided arguments and applies corresponding settings to the builder. If a specific argument is not recognized, an exception is thrown.

      Parameters:
      args - An array of command-line arguments to parse.
      Returns:
      The current instance of CraftsNetBuilder for chaining.
      Throws:
      RuntimeException - If there is an error accessing the underlying argument parser's data.
    • setArg

      protected void setArg(String arg, String value)
      Applies a single argument and its value to the builder.

      Recognizes a predefined set of argument names and updates the corresponding settings. If the argument is not recognized, an IllegalStateException is thrown.

      Parameters:
      arg - The argument name, case-insensitive.
      value - The argument value, used for arguments requiring additional data.
      Throws:
      IllegalStateException - If the argument name is not recognized.
    • addCodeSource

      public CraftsNetBuilder addCodeSource(CodeSource codeSource)
      Adds a CodeSource to the code sources list.
      Parameters:
      codeSource - The CodeSource that should be added.
      Returns:
      The CraftsNetBuilder instance.
    • removeCodeSource

      public CraftsNetBuilder removeCodeSource(CodeSource codeSource)
      Removes a CodeSource from the code sources list.
      Parameters:
      codeSource - The CodeSource that should be removed.
      Returns:
      The CraftsNetBuilder instance.
    • withWebServer

      public CraftsNetBuilder withWebServer(int port)
      Specifies the port for the web server.
      Parameters:
      port - The port number for the web server.
      Returns:
      The CraftsNetBuilder instance.
    • withWebServer

      public CraftsNetBuilder withWebServer(ActivateType type)
      Specifies the port for the web server.
      Parameters:
      type - The activation type for the web server.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.0.5-SNAPSHOT
    • withWebServer

      public CraftsNetBuilder withWebServer(ActivateType type, int port)
      Specifies the activation type and port for the web server.
      Parameters:
      type - The activation type for the web server.
      port - The port number for the web server.
      Returns:
      The CraftsNetBuilder instance.
    • withWebSocketServer

      public CraftsNetBuilder withWebSocketServer(int port)
      Specifies the port for the WebSocket server.
      Parameters:
      port - The port number for the WebSocket server.
      Returns:
      The CraftsNetBuilder instance.
    • withWebSocketServer

      public CraftsNetBuilder withWebSocketServer(ActivateType type)
      Specifies the activation type and port for the WebSocket server.
      Parameters:
      type - The activation type for the WebSocket server.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.0.5-SNAPSHOT
    • withWebSocketServer

      public CraftsNetBuilder withWebSocketServer(ActivateType type, int port)
      Specifies the activation type and port for the WebSocket server.
      Parameters:
      type - The activation type for the WebSocket server.
      port - The port number for the WebSocket server.
      Returns:
      The CraftsNetBuilder instance.
    • withAddonSystem

      public CraftsNetBuilder withAddonSystem(ActivateType type)
      Specifies the activation type for the addon system.
      Parameters:
      type - The activation type for the addon system.
      Returns:
      The CraftsNetBuilder instance.
    • withCommandSystem

      public CraftsNetBuilder withCommandSystem(ActivateType type)
      Specifies the activation type for the command system.
      Parameters:
      type - The activation type for the command system.
      Returns:
      The CraftsNetBuilder instance.
    • withSessionCache

      public CraftsNetBuilder withSessionCache(int size)
      Specifies the size of the session cache.
      Parameters:
      size - The size of the session cache.
      Returns:
      The CraftsNetBuilder instance.
    • withFileLogger

      public CraftsNetBuilder withFileLogger(ActivateType type)
      Specifies the activation type for the file logger.
      Parameters:
      type - The activation type for the file logger.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.0.5-SNAPSHOT
    • withApplyResponseEncoding

      public CraftsNetBuilder withApplyResponseEncoding(boolean allowed)
      Specifies whether from the client requested response encodings should be applied or not.
      Parameters:
      allowed - true if the requested response encoding should be applied, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.3.3-SNAPSHOT
    • withTempFilesOnNormalFileSystem

      public CraftsNetBuilder withTempFilesOnNormalFileSystem(boolean tempFilesOnNormalFileSystem)
      Configures whether temporary files should be placed on the normal file system. When set to true, the application will store temporary files in the local file system instead of using the system's default temporary file location.
      Parameters:
      tempFilesOnNormalFileSystem - true to place temporary files in the normal file system, false otherwise.
      Returns:
      the current CraftsNetBuilder instance for method chaining.
    • withSkipDefaultRoute

      public CraftsNetBuilder withSkipDefaultRoute(boolean skip)
      Specifies whether the registration of the default route (if no other route was registered) should be skipped on startup.
      Parameters:
      skip - true if the version check should be skipped, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.3.3-SNAPSHOT
    • withSkipVersionCheck

      public CraftsNetBuilder withSkipVersionCheck(boolean skip)
      Specifies whether the version check should be skipped on startup.
      Parameters:
      skip - true if the version check should be skipped, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
    • withCustomLogger

      public CraftsNetBuilder withCustomLogger(Logger logger)
      Sets a custom logger which will be used by CraftsNet. It can be null when the default logger should be used.
      Parameters:
      logger - The instance of the custom logger.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.0.5-SNAPSHOT
    • withLogger

      public CraftsNetBuilder withLogger(ActivateType type)
      Specifies the activation type for the logger.
      Parameters:
      type - The activation type for the logger.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.0.5-SNAPSHOT
    • withDebug

      public CraftsNetBuilder withDebug(boolean enabled)
      Specifies whether debug mode should be enabled.
      Parameters:
      enabled - true if debug mode should be enabled, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
    • withIpsInLog

      public CraftsNetBuilder withIpsInLog(boolean enabled)
      Specifies whether ips should be blurred in the log output.
      Parameters:
      enabled - true if ips should be readable in the log, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
      Since:
      3.4.0-SNAPSHOT
    • withSSL

      public CraftsNetBuilder withSSL(boolean enabled)
      Specifies whether SSL should be enabled.
      Parameters:
      enabled - true if SSL should be enabled, false otherwise.
      Returns:
      The CraftsNetBuilder instance.
    • withLogRotate

      public CraftsNetBuilder withLogRotate(@org.jetbrains.annotations.Range(from=0L, to=9223372036854775807L) long logRotate)
      Sets the log rotation size threshold for this builder.
      Parameters:
      logRotate - the log rotation size threshold, in bytes. A value of 0 disables log rotation. Must be non-negative.
      Returns:
      this CraftsNetBuilder instance, enabling method chaining.
    • withoutLogRotate

      public CraftsNetBuilder withoutLogRotate()
      Disables log rotation by setting the log rotation size threshold to 0.
      Returns:
      this CraftsNetBuilder instance, enabling method chaining.
    • getCodeSources

      public Collection<CodeSource> getCodeSources()
      Retrieves the list of CodeSource that should be taken into account.
      Returns:
      The list containing CodeSource.
    • getWebServerPort

      public int getWebServerPort()
      Retrieves the port number configured for the web server.
      Returns:
      The port number for the web server.
    • getWebServer

      public ActivateType getWebServer()
      Retrieves the activation type configured for the web server.
      Returns:
      The activation type for the web server.
    • isWebServer

      public boolean isWebServer(ActivateType type)
      Checks if the web server is configured with the specified activation type.
      Parameters:
      type - The activation type to check.
      Returns:
      true if the web server is configured with the specified activation type, false otherwise.
    • getWebSocketServerPort

      public int getWebSocketServerPort()
      Retrieves the port number configured for the WebSocket server.
      Returns:
      The port number for the WebSocket server.
    • getWebSocketServer

      public ActivateType getWebSocketServer()
      Retrieves the activation type configured for the WebSocket server.
      Returns:
      The activation type for the WebSocket server.
    • isWebSocketServer

      public boolean isWebSocketServer(ActivateType type)
      Checks if the WebSocket server is configured with the specified activation type.
      Parameters:
      type - The activation type to check.
      Returns:
      true if the WebSocket server is configured with the specified activation type, false otherwise.
    • getAddonSystem

      public ActivateType getAddonSystem()
      Retrieves the activation type configured for the addon system.
      Returns:
      The activation type for the addon system.
    • isAddonSystem

      public boolean isAddonSystem(ActivateType type)
      Checks if the addon system is configured with the specified activation type.
      Parameters:
      type - The activation type to check.
      Returns:
      true if the addon system is configured with the specified activation type, false otherwise.
    • getCommandSystem

      public ActivateType getCommandSystem()
      Retrieves the activation type configured for the command system.
      Returns:
      The activation type for the command system.
    • isCommandSystem

      public boolean isCommandSystem(ActivateType type)
      Checks if the command system is configured with the specified activation type.
      Parameters:
      type - The activation type to check.
      Returns:
      true if the command system is configured with the specified activation type, false otherwise.
    • getSessionCacheSize

      public int getSessionCacheSize()
      Retrieves the session cache size configured.
      Returns:
      The session cache size.
    • isFileLogger

      public boolean isFileLogger(ActivateType type)
      Checks if the file logger is configured with the specified activation type.
      Parameters:
      type - The activation type to check.
      Returns:
      true if the file logger is configured with the specified activation type, false otherwise.
      Since:
      3.0.5-SNAPSHOT
    • responseEncodingAllowed

      public boolean responseEncodingAllowed()
      Determines whether from the client requested response encoding should be applied or not.
      Returns:
      true if the request encoding should be applied, false otherwise.
      Since:
      3.3.3-SNAPSHOT
    • shouldPlaceTempFilesOnNormalFileSystem

      public boolean shouldPlaceTempFilesOnNormalFileSystem()
      Determines whether temporary files should be placed in the normal file system.
      Returns:
      true if temporary files are placed on the normal file system, false otherwise.
    • shouldSkipDefaultRoute

      public boolean shouldSkipDefaultRoute()
      Determines whether the registration of the default route (if no other route was registered) should be skipped on startup.
      Returns:
      true if the registration of the default rout should be skipped, false otherwise.
      Since:
      3.3.3-SNAPSHOT
    • shouldSkipVersionCheck

      public boolean shouldSkipVersionCheck()
      Determines whether the version check should be skipped on startup.
      Returns:
      true if the version check should be skipped, false otherwise.
    • getCustomLogger

      public Logger getCustomLogger()
      Retrieves the custom logger which should be used by CraftsNet.
      Returns:
      The logger instance.
      Since:
      3.0.5
    • isDebug

      public boolean isDebug()
      Checks if debug mode is enabled.
      Returns:
      true if debug mode is enabled, false otherwise.
    • shouldHideIps

      public boolean shouldHideIps()
      Checks if ips should be hidden in the log output.
      Returns:
      true if ips should be hidden, false otherwise.
      Since:
      3.4.0-SNAPSHOT
    • isSSL

      public boolean isSSL()
      Checks if SSL is enabled.
      Returns:
      true if SSL is enabled, false otherwise.
    • getLogRotate

      public long getLogRotate()
      Retrieves the log rotation size threshold.
      Returns:
      the log rotation size threshold in bytes, or 0 if log rotation is disabled.
    • isLogRotate

      public boolean isLogRotate()
      Checks if log rotation is disabled.
      Returns:
      true if log rotation is disabled (i.e., the threshold is 0), false otherwise.
    • build

      public CraftsNet build() throws IOException
      Builds and starts the CraftsNet framework with the configured settings.
      Returns:
      The constructed CraftsNet instance.
      Throws:
      IOException - If an I/O error occurs during the startup process.