- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- get()
- registerAccessProvider(AccessProvider)
- getBanProvider()
- setBanProvider(BanProvider)
- restoreBanProvider(BanProvider, BanProvider)
- isJoinPermissionRequired()
- setJoinPermissionRequired(boolean)
- allowJoin(UUID)
- allowJoin(Collection)
- disallowJoin(UUID)
- disallowAllJoins()
- isAllowedToJoin(UUID)
- getUsersWithJoinGrant()
- isBanned(UUID)
- ban(Ban)
- unban(UUID)
- getDisconnectReason(UUID)
Class AccessControlModule
- All Implemented Interfaces:
CommandOwner
- Since:
- 06.08.2016
-
Field Summary
FieldsFields inherited from class PluginBase
METRICS_REGISTRY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintallowJoin(Collection<UUID> uuids) Grants every player named the permission they need to connect, as one change.booleanGrants the player the permission they need to connect.booleanStores theBan, then disconnects the target if they are online.intTakes the permission back from every player that was granted it, as one change.booleandisallowJoin(UUID uuid) Takes back the permission the player needs to connect.static AccessControlModuleget()Returns the ban list the server itself uses, which the configuration names.getDisconnectReason(UUID uuid) Checks access providers in order and returns the first reason to refuse the account.A player who holds the permission through a group or a wildcard is not listed, because the grant belongs to the group rather than to them.booleanisAllowedToJoin(UUID uuid) Answers the question the server asks when a player connects, so it counts a permission the player holds through a group or a wildcard as well as one granted to them.booleanbooleanvoidregisterAccessProvider(AccessProvider provider) Registers a provider that the server asks when a player connects.booleanrestoreBanProvider(BanProvider banProvider, BanProvider previous) Puts a provider back, as theshutdownstep of a plugin that installed one does.setBanProvider(BanProvider banProvider) Replaces the ban list the server uses.setJoinPermissionRequired(boolean required) Sets whether a player needsHytalePermissions.SERVER_JOINto connect and stores the change in the server configuration.booleanRemoves any ban on the player.Methods inherited from class JavaPlugin
getClassLoader, getFile, getTypeMethods inherited from class PluginBase
getAssetRegistry, getBasePermission, getChunkStoreRegistry, getClientFeatureRegistry, getCodecRegistry, getCodecRegistry, getCodecRegistry, getCommandRegistry, getDataDirectory, getEntityRegistry, getEntityStoreRegistry, getEventRegistry, getIdentifier, getLogger, getManifest, getName, getState, getTaskRegistry, isDisabled, isEnabled, preLoad
-
Field Details
-
MANIFEST
-
-
Constructor Details
-
AccessControlModule
-
-
Method Details
-
get
-
registerAccessProvider
Registers a provider that the server asks when a player connects. The first provider with a reason refuses the connection, so the ones after it are never asked.A provider stays registered until the server stops, including across an unload of the plugin that registered it.
- Parameters:
provider- the provider to ask when a player connects
-
getBanProvider
Returns the ban list the server itself uses, which the configuration names.Never construct a second provider over the same storage. Both hold their own copy of it, so the one that saves last discards the bans of the other.
- Returns:
- the ban provider
- Throws:
IllegalStateException- if the server has yet to resolve it, which it does when it starts. Call this fromstartrather thansetup.
-
setBanProvider
Replaces the ban list the server uses. Call this from thesetupstep of a plugin that keeps the bans somewhere else, which wins over the list the configuration names. To let a server name the list instead, register aBanStorageProvidertype with its codec.If the server has started, the module writes the old provider and reads the new one before the new one goes live. If the read fails, the old provider stays in place. If the server has yet to start, the module reads the new provider when it does.
The module holds the installed provider until something replaces it, including across an unload of the plugin that installed it. Put the returned provider back with
restoreBanProvider(BanProvider, BanProvider)in theshutdownstep of that plugin.A failure to write the old provider does not stop the swap, because the provider you most need to replace is the one whose storage has gone. To swap only when the old provider writes cleanly, call
BanProvider.save()on it first and swap on success.- Parameters:
banProvider- the ban provider to use- Returns:
- the provider that was in place, which still holds the bans it read, or
nullif the server had yet to resolve one, which is the case in thesetupstep
-
restoreBanProvider
Puts a provider back, as theshutdownstep of a plugin that installed one does.Use this rather than
setBanProvider(BanProvider), because another plugin may have replaced your provider since you installed it. Putting yours back then would drop theirs, and putting theirs back when they unload would install yours after you have gone.- Parameters:
banProvider- the provider you installed, which must still be the one in useprevious- the provider to put back, whichsetBanProvider(BanProvider)returned. Pass thenullit returns in thesetupstep, and the module puts back the ban list the configuration names.- Returns:
trueif the provider was put back,falseif something else replaced yours in the meantime, in which case nothing changes
-
isJoinPermissionRequired
public boolean isJoinPermissionRequired()- Returns:
trueif a player needsHytalePermissions.SERVER_JOINto connect
-
setJoinPermissionRequired
Sets whether a player needsHytalePermissions.SERVER_JOINto connect and stores the change in the server configuration. A player who is online stays online, because the requirement only applies when a player connects.No group holds the permission, so a server that turns this on refuses every player it has yet to grant it to. An operator keeps their way in through the admin group.
- Parameters:
required- whether a player needs the permission to connect- Returns:
- a future that completes when the configuration has been written. If the write fails, the requirement goes back to what it was, so it is either stored or dropped.
-
allowJoin
-
allowJoin
Grants every player named the permission they need to connect, as one change.- Parameters:
uuids- theUUIDof each player to allow- Returns:
- the number of players that were granted the permission
-
disallowJoin
Takes back the permission the player needs to connect. A player who is online stays online, because the requirement only applies when a player connects.This takes back a grant made to the player. A player who holds the permission through a group or a wildcard keeps it, so check
isAllowedToJoin(UUID)to see whether the player can still connect.- Parameters:
uuid- theUUIDof the player to refuse- Returns:
trueif the player held the permission as a grant of their own
-
disallowAllJoins
public int disallowAllJoins()Takes the permission back from every player that was granted it, as one change.- Returns:
- the number of players the permission was taken from
-
isAllowedToJoin
Answers the question the server asks when a player connects, so it counts a permission the player holds through a group or a wildcard as well as one granted to them.- Parameters:
uuid- theUUIDof the player to check- Returns:
trueif the player may connect while the requirement is on
-
getUsersWithJoinGrant
A player who holds the permission through a group or a wildcard is not listed, because the grant belongs to the group rather than to them. AskisAllowedToJoin(UUID)for the answer that counts every way of holding it.- Returns:
- the players that were granted the permission they need to connect
-
isBanned
-
ban
Stores theBan, then disconnects the target if they are online. The store happens before this method returns, and can block, so call it off the world thread.- Parameters:
ban- the ban to apply- Returns:
trueif the ban was applied,falseif it has already run out or the target already has one
-
unban
Removes any ban on the player. The store happens before this method returns, and can block, so call it off the world thread. An online player is not affected, because a ban only applies when a player connects.- Parameters:
uuid- theUUIDof the player to unban- Returns:
trueif the player had a ban
-
getDisconnectReason
Checks access providers in order and returns the first reason to refuse the account. An empty result permits access.Connection types that bypass player setup must complete this check before serving requests. Providers can throw before this method returns or complete the returned future exceptionally. Both cases must refuse access. Do not block the channel thread while waiting for a result or cancel the returned future, which providers can share.
- Parameters:
uuid- the account to check- Returns:
- the first disconnect reason, or an empty result if all providers permit access
-