Class HytaleBanProvider

java.lang.Object
com.hypixel.hytale.server.core.util.io.BlockingDiskFile
com.hypixel.hytale.server.core.modules.accesscontrol.provider.HytaleBanProvider
All Implemented Interfaces:
AccessProvider, BanProvider

public class HytaleBanProvider extends BlockingDiskFile implements BanProvider
A BanProvider that stores the bans in a JSON file.
Since:
06.08.2016
  • Field Details

    • BAN_FILE_PATH

      @Nonnull public static final String BAN_FILE_PATH
      The file the server keeps its bans in unless the configuration names another.
      See Also:
  • Constructor Details

    • HytaleBanProvider

      public HytaleBanProvider(@Nonnull Path path)
      Creates a provider for the ban list in the given file.

      The server already runs one over the file its configuration names. Get it from AccessControlModule.getBanProvider(). Two providers over one file each hold their own copy of it, so the one that saves last discards the bans of the other.

      Parameters:
      path - the file to store the bans in
  • Method Details

    • hasBan

      public boolean hasBan(@Nonnull UUID uuid)
      Description copied from interface: BanProvider
      A ban that has run out, as Ban.isInEffect() reports, counts as no ban.

      This asks whether the player is kept out, so it counts a ban the provider holds but cannot describe, which BanProvider.getBan(UUID) returns nothing for.

      Specified by:
      hasBan in interface BanProvider
      Parameters:
      uuid - the UUID of the player to check
      Returns:
      true if the player has a ban, or an entry that denies them
    • getDisconnectReason

      @Nonnull public CompletableFuture<Optional<Message>> getDisconnectReason(@Nonnull UUID uuid)
      Description copied from interface: AccessProvider
      Returns an Optional of type Message that provides a disconnect reason.

      If the Optional contains a Message, the connection will be terminated with that message as the reason. An empty Optional will be ignored and the connection proceeds.

      Specified by:
      getDisconnectReason in interface AccessProvider
      Specified by:
      getDisconnectReason in interface BanProvider
      Parameters:
      uuid - The UUID of the player to check.
      Returns:
      the disconnect reason, Optional.empty() for no reason.
    • getBan

      @Nullable public Ban getBan(@Nonnull UUID uuid)
      Description copied from interface: BanProvider
      A ban that has run out, as Ban.isInEffect() reports, counts as no ban.

      A provider that holds a ban it cannot describe returns null here and true from BanProvider.hasBan(UUID), so use that to ask whether a player is kept out.

      Specified by:
      getBan in interface BanProvider
      Parameters:
      uuid - the UUID of the player to look up
      Returns:
      the ban on the player, or null if the player has none this provider can read
    • addBan

      public boolean addBan(@Nonnull Ban ban)
      Description copied from interface: BanProvider
      Adds the ban and stores it. A player who already has a ban keeps it, unless that ban has run out, in which case the new ban replaces it.

      A return of true means the ban is stored. If the store fails, throw, and leave the provider as it was.

      Specified by:
      addBan in interface BanProvider
      Parameters:
      ban - the ban to add
      Returns:
      true if the ban was added
    • removeBan

      public boolean removeBan(@Nonnull UUID uuid)
      Description copied from interface: BanProvider
      Removes any ban on the player and stores the change.

      A return of true means the removal is stored. If the store fails, throw, and leave the provider as it was.

      Specified by:
      removeBan in interface BanProvider
      Parameters:
      uuid - the UUID of the player to unban
      Returns:
      true if the player had a ban
    • getBans

      @Nonnull public Collection<Ban> getBans()
      Specified by:
      getBans in interface BanProvider
      Returns:
      a snapshot of every ban that is in effect and that this provider can read
    • load

      public void load()
      Description copied from interface: BanProvider
      Reads the bans from storage. The module calls this when the server starts, and again on a provider that replaces this one.
      Specified by:
      load in interface BanProvider
    • save

      public void save()
      Description copied from interface: BanProvider
      Writes the bans to storage. The module calls this when the server stops, and again on this provider when another replaces it.

      This is a flush of state that is already stored, never the point at which a change becomes durable. A provider stores each change as that change is made, so it does not need to do anything here.

      Specified by:
      save in interface BanProvider
    • modify

      public boolean modify(@Nonnull Function<Map<UUID,Ban>, Boolean> function)
      Applies the change and stores it. If the store fails, the bans go back to what they were and the failure reaches the caller, so a change is either stored or dropped, never held in memory alone.
      Parameters:
      function - makes the change and reports whether it changed anything. A return of null counts as no change, and a throw puts the bans back as well.
      Returns:
      true if the change was made and stored