Skip to content

Commit

Permalink
Add destination and debug mode tab completion for /mv config
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Feb 28, 2025
1 parent f46449f commit 74e595b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mvplugins.multiverse.core.configuration.migration.InvertBoolMigratorAction;
import org.mvplugins.multiverse.core.configuration.migration.MoveMigratorAction;
import org.mvplugins.multiverse.core.configuration.migration.VersionMigrator;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;

@Service
public class MVCoreConfig {
Expand All @@ -39,10 +40,11 @@ public class MVCoreConfig {
MVCoreConfig(
@NotNull MultiverseCore core,
@NotNull PluginManager pluginManager,
@NotNull Provider<MVCommandManager> commandManager // config needs to be instantiated before the command manager
@NotNull Provider<MVCommandManager> commandManager, // config needs to be instantiated before the command manager
@NotNull Provider<DestinationsProvider> destinationsProvider
) {
this.configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME);
this.configNodes = new MVCoreConfigNodes(pluginManager, commandManager);
this.configNodes = new MVCoreConfigNodes(pluginManager, commandManager, destinationsProvider);
this.configHandle = CommentedConfigurationHandle.builder(configPath, configNodes.getNodes())
.logger(Logging.getLogger())
.migrator(ConfigMigrator.builder(configNodes.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Try;
import jakarta.inject.Provider;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;

import org.jetbrains.annotations.NotNull;
Expand All @@ -12,21 +13,30 @@
import org.mvplugins.multiverse.core.configuration.node.ConfigNode;
import org.mvplugins.multiverse.core.configuration.node.Node;
import org.mvplugins.multiverse.core.configuration.node.NodeGroup;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.core.WorldDestination;
import org.mvplugins.multiverse.core.event.MVDebugModeEvent;
import org.mvplugins.multiverse.core.exceptions.MultiverseException;
import org.mvplugins.multiverse.core.permissions.PermissionUtils;

import java.util.Collection;
import java.util.List;
import java.util.Locale;

final class MVCoreConfigNodes {

private final NodeGroup nodes = new NodeGroup();
private PluginManager pluginManager;
private Provider<MVCommandManager> commandManager;
private final Provider<DestinationsProvider> destinationsProvider;

MVCoreConfigNodes(@NotNull PluginManager pluginManager, @NotNull Provider<MVCommandManager> commandManager) {
MVCoreConfigNodes(
@NotNull PluginManager pluginManager,
@NotNull Provider<MVCommandManager> commandManager,
@NotNull Provider<DestinationsProvider> destinationsProvider) {
this.pluginManager = pluginManager;
this.commandManager = commandManager;
this.destinationsProvider = destinationsProvider;
}

NodeGroup getNodes() {
Expand Down Expand Up @@ -167,6 +177,7 @@ private <N extends Node> N node(N node) {
.comment("This only applies if first-spawn-override is set to true.")
.defaultValue("")
.name("first-spawn-location")
.suggester(this::suggestDestinations)
.build());

final ConfigNode<Boolean> enableJoinDestination = node(ConfigNode.builder("spawn.enable-join-destination", Boolean.class)
Expand All @@ -182,6 +193,7 @@ private <N extends Node> N node(N node) {
.comment("Set the above enable-join-destination to false to disable")
.defaultValue("")
.name("join-destination")
.suggester(this::suggestDestinations)
.build());

final ConfigNode<Boolean> defaultRespawnWithinSameWorld = node(ConfigNode.builder("spawn.default-respawn-within-same-world", Boolean.class)
Expand Down Expand Up @@ -345,6 +357,7 @@ private <N extends Node> N node(N node) {
.comment(" 3 = finest")
.defaultValue(0)
.name("global-debug")
.suggester(input -> List.of("0", "1", "2", "3"))
.validator(value -> (value < 0 || value > 3)
? Try.failure(new MultiverseException("Debug level must be between 0 and 3."))
: Try.success(null))
Expand Down Expand Up @@ -389,6 +402,17 @@ private <N extends Node> N node(N node) {
.name(null)
.build());

// todo: Maybe combine with the similar method in MVCommandCompletion but that has permission checking
private Collection<String> suggestDestinations(String input) {
return destinationsProvider.get().getDestinations().stream()
.flatMap(destination -> destination.suggestDestinations(Bukkit.getConsoleSender(), null)
.stream()
.map(packet -> destination instanceof WorldDestination
? packet.destinationString()
: destination.getIdentifier() + ":" + packet.destinationString()))
.toList();
}

// END CHECKSTYLE-SUPPRESSION: Javadoc
// END CHECKSTYLE-SUPPRESSION: MemberName
// END CHECKSTYLE-SUPPRESSION: Abbreviation
Expand Down

0 comments on commit 74e595b

Please sign in to comment.