Class BridgeServiceHelper
java.lang.Object
eu.cloudnetservice.modules.bridge.BridgeServiceHelper
The bridge service helper is designed to facilitate working with individual states of services. In addition, these
properties are stored here:
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe service info state allows a better separation of a service state than a service lifecycle. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<String> private final AtomicIntegerprivate final AtomicReference<String> private final eu.cloudnetservice.driver.provider.CloudServiceFactoryprivate final AtomicReference<String> private final eu.cloudnetservice.driver.provider.ServiceTaskProviderprivate final eu.cloudnetservice.wrapper.configuration.WrapperConfiguration -
Constructor Summary
ConstructorsConstructorDescriptionBridgeServiceHelper(@NonNull eu.cloudnetservice.driver.provider.ServiceTaskProvider taskProvider, @NonNull eu.cloudnetservice.driver.provider.CloudServiceFactory serviceFactory, @NonNull eu.cloudnetservice.wrapper.configuration.WrapperConfiguration wrapperConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the state of the service this bridge instance is running on toingameand starts a new service of the task.voidchangeToIngame(boolean autoStartService) Sets the state of the service this bridge instance is running on toingame.static booleanemptyService(@NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Checks if the given service is empty.extra()fillCommonPlaceholders(@NonNull String value, @Nullable String group, @Nullable eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Replaces commonly used placeholders in the given input string using the given service as the information source.static booleanfullService(@NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Checks if the given service is full.guessStateFromServiceInfoSnapshot(@NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Tries to guess theBridgeServiceHelper.ServiceInfoStatefrom the lifecycle andBridgeDocPropertiesof the given service.static booleaninGameService(@NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Checks if the given service is in-game.private static booleanmatchesInGameString(@Nullable String value) Checks if the given value matches eitheringame,runningorplaying.motd()static booleanstartingService(@NonNull eu.cloudnetservice.driver.service.ServiceInfoSnapshot service) Checks if the given service is starting.state()
-
Field Details
-
maxPlayers
-
motd
-
extra
-
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 theBridgeServiceHelper.ServiceInfoStatefrom the lifecycle andBridgeDocPropertiesof the given service.- If the service is not running or not in-game
BridgeServiceHelper.ServiceInfoState.STOPPEDis guessed. - If the service is empty
BridgeServiceHelper.ServiceInfoState.EMPTY_ONLINEis guessed. - If the service is full
BridgeServiceHelper.ServiceInfoState.FULL_ONLINEis guessed. - If the service is starting
BridgeServiceHelper.ServiceInfoState.STARTINGis guessed. - If the service is just connected
BridgeServiceHelper.ServiceInfoState.ONLINEis guessed. - If none of the above apply
BridgeServiceHelper.ServiceInfoState.STOPPEDis 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:
- If the service is not running or not in-game
-
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:- the lifecycle is running
- the service is NOT marked as online
BridgeDocProperties.IS_ONLINE
- 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:- the lifecycle is running
- the service is connected
- the service is marked as online
BridgeDocProperties.IS_ONLINE - the motd, the state or the extra matches any value representing the in-game state
matchesInGameString(String)
- 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
-
changeToIngame
public void changeToIngame()Sets the state of the service this bridge instance is running on toingameand starts a new service of the task. The method is equivalent to callingBridgeServiceHelper.changeToIngame(true). -
maxPlayers
-
motd
-
extra
-
state
-
changeToIngame
public void changeToIngame(boolean autoStartService) Sets the state of the service this bridge instance is running on toingame. 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.
-