Class BridgeServiceHelper

java.lang.Object
eu.cloudnetservice.modules.bridge.BridgeServiceHelper

@Singleton public final class BridgeServiceHelper extends Object
The bridge service helper is designed to facilitate working with individual states of services. In addition, these properties are stored here:
Since:
4.0
  • Field Details

    • maxPlayers

      private final AtomicInteger maxPlayers
    • motd

      private final AtomicReference<String> motd
    • extra

      private final AtomicReference<String> extra
    • state

      private final AtomicReference<String> state
    • taskProvider

      private final eu.cloudnetservice.driver.provider.ServiceTaskProvider taskProvider
    • serviceFactory

      private final eu.cloudnetservice.driver.provider.CloudServiceFactory serviceFactory
    • wrapperConfiguration

      private final eu.cloudnetservice.wrapper.configuration.WrapperConfiguration wrapperConfiguration
  • Constructor Details

    • BridgeServiceHelper

      @Inject public BridgeServiceHelper(@NonNull @NonNull eu.cloudnetservice.driver.provider.ServiceTaskProvider taskProvider, @NonNull @NonNull eu.cloudnetservice.driver.provider.CloudServiceFactory serviceFactory, @NonNull @NonNull eu.cloudnetservice.wrapper.configuration.WrapperConfiguration wrapperConfiguration)
  • Method Details

    • guessStateFromServiceInfoSnapshot

      @NonNull public static @NonNull BridgeServiceHelper.ServiceInfoState guessStateFromServiceInfoSnapshot(@NonNull @NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Tries to guess the BridgeServiceHelper.ServiceInfoState from the lifecycle and BridgeDocProperties of the given service.
      1. If the service is not running or not in-game BridgeServiceHelper.ServiceInfoState.STOPPED is guessed.
      2. If the service is empty BridgeServiceHelper.ServiceInfoState.EMPTY_ONLINE is guessed.
      3. If the service is full BridgeServiceHelper.ServiceInfoState.FULL_ONLINE is guessed.
      4. If the service is starting BridgeServiceHelper.ServiceInfoState.STARTING is guessed.
      5. If the service is just connected BridgeServiceHelper.ServiceInfoState.ONLINE is guessed.
      6. If none of the above apply BridgeServiceHelper.ServiceInfoState.STOPPED is used as fallback.
      Parameters:
      service - the service to guess the state of.
      Returns:
      the guessed service info state.
      Throws:
      NullPointerException - if the given service is null.
      See Also:
    • fillCommonPlaceholders

      @NonNull public static @NonNull String fillCommonPlaceholders(@NonNull @NonNull String value, @Nullable @Nullable String group, @Nullable @Nullable eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Replaces commonly used placeholders in the given input string using the given service as the information source. If no service is given only the group property is replaced.
      Parameters:
      value - the string to replace the placeholders in.
      group - the group to replace %group% with.
      service - the service to use as source for the placeholder values.
      Returns:
      the String with the placeholders replaced.
      Throws:
      NullPointerException - if the given input string is null.
    • emptyService

      public static boolean emptyService(@NonNull @NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Checks if the given service is empty. This is only the case if all following conditions apply:
      • the lifecycle is running
      • the service is connected
      • the service is marked as online BridgeDocProperties.IS_ONLINE
      • the service has a present online count as it is 0
      Parameters:
      service - the service to check.
      Returns:
      true if the service is empty, false otherwise.
      Throws:
      NullPointerException - if the given service is null.
    • fullService

      public static boolean fullService(@NonNull @NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Checks if the given service is full. This is only the case if all following conditions apply:
      • the lifecycle is running
      • the service is connected
      • the service is marked as online BridgeDocProperties.IS_ONLINE
      • the service has both an online and max player count
      • the online count is equal or higher than the max player count
      Parameters:
      service - the service to check.
      Returns:
      true if the service is full, false otherwise.
      Throws:
      NullPointerException - if the given service is null.
    • startingService

      public static boolean startingService(@NonNull @NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Checks if the given service is starting. This is only the case if all following conditions apply:
      Parameters:
      service - the service to check.
      Returns:
      true if the service is starting, false otherwise.
      Throws:
      NullPointerException - if the given service is null.
    • inGameService

      public static boolean inGameService(@NonNull @NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service)
      Checks if the given service is in-game. This is only the case if all following conditions apply:
      Parameters:
      service - the service to check.
      Returns:
      true if the service is in-game, false otherwise.
      Throws:
      NullPointerException - if the given service is null.
    • matchesInGameString

      private static boolean matchesInGameString(@Nullable @Nullable String value)
      Checks if the given value matches either ingame, running or playing.
      Parameters:
      value - the value to check against.
      Returns:
      true if the value contains an in-game indicator, false otherwise.
    • changeToIngame

      public void changeToIngame()
      Sets the state of the service this bridge instance is running on to ingame and starts a new service of the task. The method is equivalent to calling BridgeServiceHelper.changeToIngame(true).
    • maxPlayers

      @NonNull public @NonNull AtomicInteger maxPlayers()
    • motd

    • extra

    • state

    • changeToIngame

      public void changeToIngame(boolean autoStartService)
      Sets the state of the service this bridge instance is running on to ingame. A new service from the same task is started if the given auto start option is true.

      Note: The service is started asynchronously.

      Parameters:
      autoStartService - whether a new service should be started or not.