Skip to content

Commit 8a28bca

Browse files
committed
Expose MV's completion and context instances in CommandManager
1 parent 0cc1676 commit 8a28bca

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandCompletions.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.mvplugins.multiverse.core.world.WorldManager;
3636

3737
@Service
38-
class MVCommandCompletions extends PaperCommandCompletions {
38+
public class MVCommandCompletions extends PaperCommandCompletions {
3939

4040
private final MVCommandManager commandManager;
4141
private final WorldManager worldManager;
@@ -77,6 +77,20 @@ class MVCommandCompletions extends PaperCommandCompletions {
7777
setDefaultCompletion("mvworlds", LoadedMultiverseWorld.class);
7878
}
7979

80+
/**
81+
* Shortcut to suggest enums values
82+
*
83+
* @param enumClass The enum class with values
84+
* @return A collection of possible string values
85+
* @param <T> The enum type
86+
*/
87+
public <T extends Enum<T>> Collection<String> suggestEnums(Class<T> enumClass) {
88+
return EnumSet.allOf(enumClass).stream()
89+
.map(Enum::name)
90+
.map(String::toLowerCase)
91+
.toList();
92+
}
93+
8094
private Collection<String> suggestCommands(BukkitCommandCompletionContext context) {
8195
String rootCmdName = context.getConfig();
8296
if (rootCmdName == null) {
@@ -192,11 +206,4 @@ private Collection<String> suggestMVWorldPropsValue(BukkitCommandCompletionConte
192206
return world.getStringPropertyHandle().getSuggestedPropertyValue(propertyName, context.getInput(), action);
193207
}).getOrElse(Collections.emptyList());
194208
}
195-
196-
private <T extends Enum<T>> Collection<String> suggestEnums(Class<T> enumClass) {
197-
return EnumSet.allOf(enumClass).stream()
198-
.map(Enum::name)
199-
.map(String::toLowerCase)
200-
.toList();
201-
}
202209
}

src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandContexts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.mvplugins.multiverse.core.world.WorldManager;
2828

2929
@Service
30-
class MVCommandContexts extends PaperCommandContexts {
30+
public class MVCommandContexts extends PaperCommandContexts {
3131

3232
private final MVCommandManager mvCommandManager;
3333
private final DestinationsProvider destinationsProvider;

src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public PluginLocales getLocales() {
9191
* @return A not-null {@link CommandContexts}.
9292
*/
9393
@Override
94-
public synchronized @NotNull CommandContexts<BukkitCommandExecutionContext> getCommandContexts() {
94+
public synchronized @NotNull MVCommandContexts getCommandContexts() {
9595
if (this.contexts == null) {
9696
this.contexts = commandContextsProvider.get();
9797
}
98-
return this.contexts;
98+
return (MVCommandContexts) this.contexts;
9999
}
100100

101101
/**
@@ -104,11 +104,11 @@ public PluginLocales getLocales() {
104104
* @return A not-null {@link CommandCompletions}.
105105
*/
106106
@Override
107-
public synchronized @NotNull CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() {
107+
public synchronized @NotNull MVCommandCompletions getCommandCompletions() {
108108
if (this.completions == null) {
109109
this.completions = commandCompletionsProvider.get();
110110
}
111-
return this.completions;
111+
return (MVCommandCompletions) this.completions;
112112
}
113113

114114
/**

0 commit comments

Comments
 (0)