Package de.eimmer.befehl
Class SimpleBefehlMappe
java.lang.Object
de.eimmer.befehl.SimpleBefehlMappe
- All Implemented Interfaces:
BefehlMappe
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears all registered commands.boolean
dispatch
(BefehlAbsender sender, String commandLine) Looks for the requested befehl and executes it if found.getCommand
(String name) Gets the befehl registered to the specified nameboolean
Registers a befehl.boolean
Registers a befehl.void
registerAll
(String fallbackPrefix, List<Befehl> befehls) Registers all the befehls belonging to a certain zusatzmodul.void
void
tabComplete
(BefehlAbsender sender, String cmdLine) Looks for the requested befehl and executes an appropriate tab-completer if found.tabComplete
(BefehlAbsender sender, String cmdLine, Ort ort) Looks for the requested befehl and executes an appropriate tab-completer if found.
-
Field Details
-
knownCommands
-
-
Constructor Details
-
SimpleBefehlMappe
-
-
Method Details
-
setFallbackCommands
public void setFallbackCommands() -
registerAll
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 interfaceBefehlMappe
- Parameters:
fallbackPrefix
- a prefix which is prepended to each befehl with a ':' one or more times to make the befehl uniquebefehls
- a list of befehls to register
-
register
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 interfaceBefehlMappe
- Parameters:
fallbackPrefix
- a prefix which is prepended to the befehl with a ':' one or more times to make the befehl uniquebefehl
- 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 interfaceBefehlMappe
- 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 uniquebefehl
- 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 interfaceBefehlMappe
- Parameters:
sender
- The befehl's sendercommandLine
- 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 interfaceBefehlMappe
-
getCommand
Description copied from interface:BefehlMappe
Gets the befehl registered to the specified name- Specified by:
getCommand
in interfaceBefehlMappe
- 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
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 interfaceBefehlMappe
- 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 interfaceBefehlMappe
- 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
-
registerServerAliases
public void registerServerAliases()
-