Class SimpleBefehlMappe

java.lang.Object
de.eimmer.befehl.SimpleBefehlMappe
All Implemented Interfaces:
BefehlMappe

public class SimpleBefehlMappe extends Object implements BefehlMappe
  • Field Details

  • Constructor Details

    • SimpleBefehlMappe

      public SimpleBefehlMappe(@NotNull Server server)
  • Method Details

    • setFallbackCommands

      public void setFallbackCommands()
    • registerAll

      public void registerAll(@NotNull String fallbackPrefix, @NotNull List<Befehl> befehls)
      Registers all the befehls belonging to a certain zusatzmodul.

      Caller can use:-

      • befehl.getName() to determine the label registered for this befehl
      • befehl.getAliases() to determine the aliases which where registered
      Specified by:
      registerAll in interface BefehlMappe
      Parameters:
      fallbackPrefix - a prefix which is prepended to each befehl with a ':' one or more times to make the befehl unique
      befehls - a list of befehls to register
    • register

      public boolean register(@NotNull String fallbackPrefix, @NotNull Befehl befehl)
      Registers a befehl. Returns true on success; false if name is already taken and fallback had to be used.

      Caller can use:-

      • befehl.getName() to determine the label registered for this befehl
      • befehl.getAliases() to determine the aliases which where registered
      Specified by:
      register in interface BefehlMappe
      Parameters:
      fallbackPrefix - a prefix which is prepended to the befehl with a ':' one or more times to make the befehl unique
      befehl - the befehl to register, from which label is determined from the befehl name
      Returns:
      true if befehl was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
    • register

      public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Befehl befehl)
      Registers a befehl. Returns true on success; false if name is already taken and fallback had to be used.

      Caller can use:-

      • befehl.getName() to determine the label registered for this befehl
      • befehl.getAliases() to determine the aliases which where registered
      Specified by:
      register in interface BefehlMappe
      Parameters:
      label - the label of the befehl, without the '/'-prefix.
      fallbackPrefix - a prefix which is prepended to the befehl with a ':' one or more times to make the befehl unique
      befehl - the befehl to register
      Returns:
      true if befehl was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
    • dispatch

      public boolean dispatch(@NotNull BefehlAbsender sender, @NotNull String commandLine) throws BefehlAusnahme
      Looks for the requested befehl and executes it if found.
      Specified by:
      dispatch in interface BefehlMappe
      Parameters:
      sender - The befehl's sender
      commandLine - befehl + arguments. Example: "/test abc 123"
      Returns:
      returns false if no target is found, true otherwise.
      Throws:
      BefehlAusnahme - Thrown when the executor for the given befehl fails with an unhandled exception
    • clearCommands

      public void clearCommands()
      Description copied from interface: BefehlMappe
      Clears all registered commands.
      Specified by:
      clearCommands in interface BefehlMappe
    • getCommand

      @Nullable public Befehl getCommand(@NotNull String name)
      Description copied from interface: BefehlMappe
      Gets the befehl registered to the specified name
      Specified by:
      getCommand in interface BefehlMappe
      Parameters:
      name - Name of the befehl to retrieve
      Returns:
      Befehl with the specified name or null if a befehl with that label doesn't exist
    • tabComplete

      @Nullable public List<String> tabComplete(@NotNull BefehlAbsender sender, @NotNull String cmdLine)
      Description copied from interface: BefehlMappe
      Looks for the requested befehl and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.
      Specified by:
      tabComplete in interface BefehlMappe
      Parameters:
      sender - The befehl's sender.
      cmdLine - The entire befehl string to tab-complete, excluding initial slash.
      Returns:
      a list of possible tab-completions. This list may be immutable. Will be null if no matching befehl of which sender has permission.
    • tabComplete

      @Nullable public List<String> tabComplete(@NotNull BefehlAbsender sender, @NotNull String cmdLine, @Nullable Ort ort)
      Description copied from interface: BefehlMappe
      Looks for the requested befehl and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.
      Specified by:
      tabComplete in interface BefehlMappe
      Parameters:
      sender - The befehl's sender.
      cmdLine - The entire befehl string to tab-complete, excluding initial slash.
      ort - The position looked at by the sender, or null if none
      Returns:
      a list of possible tab-completions. This list may be immutable. Will be null if no matching befehl of which sender has permission.
    • getCommands

      @NotNull public Collection<Befehl> getCommands()
    • registerServerAliases

      public void registerServerAliases()