Class TabCompletionManager
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBuilt-in completer prefix for blocks.static final StringBuilt-in completer prefix for boolean values.private final Map<String, TabCompleter> private final ThreadLocal<String> The owner currently attributed to registrations made viaregister(String, TabCompleter)-- set bybeginRegistrationScope(String), cleared byendRegistrationScope().private static TabCompletionManagerstatic final StringBuilt-in completer prefix for items.Key -> owner (05-06 / D-08, T-05-24).static final StringBuilt-in completer prefix for materials.private final MethodInvocationCompleterstatic final StringBuilt-in completer prefix for players.static final StringBuilt-in completer prefix for toggle values.static final StringBuilt-in completer prefix for worlds. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor - use getInstance(). -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginRegistrationScope(String owner) Marks the beginning of a registration scope attributed toowner-- every completer key registered viaregister(String, TabCompleter)while this scope is active is recorded as owned byowner, sounregisterByOwner(String)can sweep it later without requiring caller code to pass an owner explicitly (05-06 / D-08's "explicit owner parameter on an internal registration path" -- the parameter is ambient rather than a new argument on the publishedregister(String, TabCompleter)signature, which stays frozen).createContext(org.bukkit.entity.Player player, org.bukkit.command.Command command, String[] args) Creates a context for tab completion with common defaults.voidEnds the current registration scope started bybeginRegistrationScope(String).filterByInput(List<String> suggestions, String input) Helper method to filter suggestions by current input.getCompleter(String key) Gets a registered completer by key.static TabCompletionManagerGets the singleton instance.voidregister(String key, TabCompleter completer) Registers a custom completer with a key.private voidRegisters all built-in completers.static StringresolveSuggestValue(Method matchedMethod, String parameterName) ResolvesmatchedMethod's@CmdParam.suggest()value for the parameter whose@CmdParam.value()equalsparameterName-- i.e.suggest(TabCompletionContext context) Generates suggestions using the given context.suggest(TabCompletionContext context, String resolvedSuggest) Resolves suggestions using an explicitly-resolved@CmdParam.suggest()value, rather thancontext'sTabCompletionContext.parameterName-- which carries@CmdParam.value(), the parameter's DISPLAY NAME, not its suggestion (05-06 / D-07 Pitfall 2, T-05-28).Generates suggestions using the appropriate completer.suggestFirstArgs(Map<String, Method> mappings, TabCompletionContext context) Suggests command format first arguments from mappings.suggestWith(TabCompletionContext context, String completerKey) Suggests completions for a specific parameter type.voidunregister(String key) Unregisters a completer.intunregisterByOwner(String owner) Bulk-unregisters every completer key currently attributed toownerby an earlierbeginRegistrationScope(String)/endRegistrationScope()window, built entirely from the already-publicunregister(String)-- so removal semantics are identical to a caller unregistering each key by hand, just batched by owner (D-08: "No new public method is needed:unregister(String)already exists -- the bulk sweep can be built from it").
-
Field Details
-
PLAYERS
Built-in completer prefix for players.- See Also:
-
WORLDS
Built-in completer prefix for worlds.- See Also:
-
MATERIALS
Built-in completer prefix for materials.- See Also:
-
BLOCKS
Built-in completer prefix for blocks.- See Also:
-
ITEMS
Built-in completer prefix for items.- See Also:
-
BOOLEAN
Built-in completer prefix for boolean values.- See Also:
-
TOGGLE
Built-in completer prefix for toggle values.- See Also:
-
instance
-
completers
-
methodCompleter
-
keyOwners
Key -> owner (05-06 / D-08, T-05-24). Populated only while abeginRegistrationScope(String)/endRegistrationScope()window is active, so a completer registered through the plain publicregister(String, TabCompleter)by a caller unaware of ownership is simply never recorded here -- "unowned", never swept byunregisterByOwner(String). Keyed by the completer KEY (aString), not by the completer'sClass-- Phase 1 D-35/D-38 forbids staticClass-keyed maps because they pin a plugin's ClassLoader; a String key holds nothing that does. -
currentOwner
The owner currently attributed to registrations made viaregister(String, TabCompleter)-- set bybeginRegistrationScope(String), cleared byendRegistrationScope().ThreadLocalrather than a plain field becausegetInstance()is one process-wide singleton and PluginManager's own module loading, while sequential today, should not silently corrupt ownership if that ever changes.
-
-
Constructor Details
-
TabCompletionManager
private TabCompletionManager()Private constructor - use getInstance().
-
-
Method Details
-
getInstance
Gets the singleton instance.- Returns:
- the tab completion manager instance
-
registerBuiltInCompleters
private void registerBuiltInCompleters()Registers all built-in completers. -
register
Registers a custom completer with a key.- Parameters:
key- the key to register with (e.g., "@custom")completer- the completer to register
-
unregister
Unregisters a completer.- Parameters:
key- the key to unregister
-
beginRegistrationScope
Marks the beginning of a registration scope attributed toowner-- every completer key registered viaregister(String, TabCompleter)while this scope is active is recorded as owned byowner, sounregisterByOwner(String)can sweep it later without requiring caller code to pass an owner explicitly (05-06 / D-08's "explicit owner parameter on an internal registration path" -- the parameter is ambient rather than a new argument on the publishedregister(String, TabCompleter)signature, which stays frozen).ClassLoader-derived ownership was considered and rejected for this codebase. Every internal
UltiToolsPluginmodule is loaded through ONE sharedURLClassLoadercovering the wholeplugins/folder (seePluginManager.init(ClassLoader)) -- the identical structural finding already recorded atPluginManager.validateAdditionalEntity's javadoc for D-19 -- so a completer instance'sgetClass().getClassLoader()cannot distinguish between two different modules here. An explicit scope is the only mechanism reachable from a module's only registration entry point (the publicregister(String, TabCompleter)) that still correctly separates two modules' completers.Not part of the frozen 6.2.5 singleton shape (
getInstance(),register(String, TabCompleter),unregister(String)) -- new in 6.3.0, intended forPluginManager's own module load/unload sequence, not for module authors.Scopes do not nest: a second
beginRegistrationScopecall while one is already active simply replaces the current owner.UltiTools' own module loading is sequential -- one module's container is fully assembled (including itspluginContext.refresh(), where@PostConstructruns) before the next module's load begins -- so nesting has never been required; this is a stated assumption, not an enforced invariant.- Parameters:
owner- the identifier (the framework uses the plugin's name) to attribute subsequent registrations to- Since:
- 6.3.0
-
endRegistrationScope
public void endRegistrationScope()Ends the current registration scope started bybeginRegistrationScope(String). Registrations made after this call (and before another scope begins) are unowned and never swept byunregisterByOwner(String)-- the same as every registration made before this mechanism existed.- Since:
- 6.3.0
-
unregisterByOwner
Bulk-unregisters every completer key currently attributed toownerby an earlierbeginRegistrationScope(String)/endRegistrationScope()window, built entirely from the already-publicunregister(String)-- so removal semantics are identical to a caller unregistering each key by hand, just batched by owner (D-08: "No new public method is needed:unregister(String)already exists -- the bulk sweep can be built from it"). A key registered outside any scope (core built-ins, or any caller that never callsbeginRegistrationScope(String)) has no recorded owner and is never matched here, regardless ofowner's value.- Parameters:
owner- the owner identifier to sweep;nullmatches nothing and is a no-op- Returns:
- the number of keys unregistered
- Since:
- 6.3.0
-
getCompleter
Gets a registered completer by key.- Parameters:
key- the completer key- Returns:
- the completer or null if not found
-
suggest
public List<String> suggest(org.bukkit.entity.Player player, org.bukkit.command.Command command, String[] args) Generates suggestions using the appropriate completer.- Parameters:
player- the player requesting completioncommand- the commandargs- the current arguments- Returns:
- list of suggestions
-
suggest
Generates suggestions using the given context.- Parameters:
context- the completion context- Returns:
- list of suggestions
-
suggest
Resolves suggestions using an explicitly-resolved@CmdParam.suggest()value, rather thancontext'sTabCompletionContext.parameterName-- which carries@CmdParam.value(), the parameter's DISPLAY NAME, not its suggestion (05-06 / D-07 Pitfall 2, T-05-28).suggest(TabCompletionContext)above is left untouched for existing callers; this overload is the dual-notation entry point a caller that has already resolved the realsuggest()value (seeresolveSuggestValue(Method, String)) should use instead.A
resolvedSuggestbeginning with@resolves as a built-in or registered completer key. Any other value -- includingnullor empty -- falls through to the existing method-invocation completer (and its i18n hint-text fallback), unchanged.- Parameters:
context- the completion contextresolvedSuggest- the already-resolved@CmdParam.suggest()string for the parameter being completed; may benullor empty- Returns:
- the suggestions; never null
- Since:
- 6.3.0
-
resolveSuggestValue
ResolvesmatchedMethod's@CmdParam.suggest()value for the parameter whose@CmdParam.value()equalsparameterName-- i.e. it keys the lookup off the parameter's DISPLAY NAME to find the right parameter, then returns that parameter's suggestion, never the display name itself (05-06 / D-07). This mirrorsMethodInvocationCompleter.getSuggestName's existing lookup shape so the two stay consistent, without depending on that private method directly.- Parameters:
matchedMethod- the matched@CmdMappingmethod, ornullparameterName- the parameter's display name (@CmdParam.value()) to look up- Returns:
- the resolved
suggest()value, ornullifmatchedMethodisnullor no parameter'svalue()matchesparameterName - Since:
- 6.3.0
-
suggestWith
Suggests completions for a specific parameter type.- Parameters:
context- the completion contextcompleterKey- the key of the completer to use- Returns:
- list of suggestions
-
createContext
public TabCompletionContext createContext(org.bukkit.entity.Player player, org.bukkit.command.Command command, String[] args) Creates a context for tab completion with common defaults.- Parameters:
player- the playercommand- the commandargs- the arguments- Returns:
- a tab completion context
-
filterByInput
Helper method to filter suggestions by current input.- Parameters:
suggestions- the suggestions to filterinput- the current input- Returns:
- filtered suggestions
-
suggestFirstArgs
Suggests command format first arguments from mappings.- Parameters:
mappings- the command mappings (format -> method)context- the completion context- Returns:
- list of first argument suggestions
-