Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.mvplugins.multiverse.core.config.node.functions.DefaultSuggesterProvider;
import org.mvplugins.multiverse.core.config.handle.PropertyModifyAction;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.destination.DestinationSuggestionPacket;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.core.WorldDestination;
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
import org.mvplugins.multiverse.core.utils.REPatterns;
import org.mvplugins.multiverse.core.utils.StringFormatter;
Expand Down Expand Up @@ -235,9 +235,7 @@ private Collection<String> suggestDestinationsWithPerms(CommandSender teleporter
return destinationsProvider.suggestDestinations(teleporter, deststring).stream()
.filter(packet -> corePermissionsChecker
.checkDestinationPacketPermission(teleporter, Arrays.asList(players), packet))
.map(packet -> packet.destination() instanceof WorldDestination
? packet.destinationString()
: packet.destination().getIdentifier() + ":" + packet.destinationString())
.map(DestinationSuggestionPacket::parsableString)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.mvplugins.multiverse.core.config.node.functions.NodeStringParser;
import org.mvplugins.multiverse.core.config.node.serializer.NodeSerializer;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.core.WorldDestination;
import org.mvplugins.multiverse.core.dynamiclistener.EventPriorityMapper;
import org.mvplugins.multiverse.core.event.MVDebugModeEvent;
import org.mvplugins.multiverse.core.exceptions.MultiverseException;
Expand Down Expand Up @@ -547,14 +546,8 @@ private <N extends Node> N node(N node) {
.hidden()
.build());

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

private static final class DimensionFormatNodeSerializer implements NodeSerializer<DimensionFormat> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.mvplugins.multiverse.core.destination;

import org.jetbrains.annotations.ApiStatus;
import org.mvplugins.multiverse.core.destination.core.WorldDestination;

Check warning on line 4 in src/main/java/org/mvplugins/multiverse/core/destination/DestinationSuggestionPacket.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'org.mvplugins.multiverse.core.destination.core.WorldDestination' should be separated from previous imports. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationSuggestionPacket.java:4:1: warning: 'org.mvplugins.multiverse.core.destination.core.WorldDestination' should be separated from previous imports. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)

/**
* Data of a possible destination for tab completion and permission checking
*
Expand All @@ -8,4 +11,19 @@
* @param finerPermissionSuffix The finer permission suffix
*/
public record DestinationSuggestionPacket(Destination<?, ?, ?> destination, String destinationString, String finerPermissionSuffix) {

/**
* Gets a parsable string representation of the destination that is most likely valid for
* {@link DestinationsProvider#parseDestination(String)}.
*
* @return The parsable string
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public String parsableString() {
return destination instanceof WorldDestination
? destinationString
: destination.getIdentifier() + ":" + destinationString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import co.aikar.locales.MessageKeyProvider;
import jakarta.inject.Inject;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;
Expand Down Expand Up @@ -95,12 +96,36 @@
return this.destinationMap.values();
}

/**
* Gets suggestions for possible parsable destinations.
*
* @param sender The target sender context.
* @param destinationParams The current user input.
* @return A collection of destination suggestions.
*/
public @NotNull Collection<DestinationSuggestionPacket> suggestDestinations(@NotNull CommandSender sender, @Nullable String destinationParams) {
return this.getDestinations().stream()
.flatMap(destination -> destination.suggestDestinations(sender, destinationParams).stream())
.toList();
}

/**
* Gets suggestions for possible parsable destinations.
*
* @param sender The target sender context.
* @param destinationParams The current user input.
* @return A collection of destination suggestions in parsable string format.
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public @NotNull Collection<String> suggestDestinationStrings(@NotNull CommandSender sender, @Nullable String destinationParams) {

Check warning on line 122 in src/main/java/org/mvplugins/multiverse/core/destination/DestinationsProvider.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 133). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationsProvider.java:122:0: warning: Line is longer than 120 characters (found 133). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
return suggestDestinations(sender, destinationParams)
.stream()
.map(DestinationSuggestionPacket::parsableString)
.toList();
}

public enum ParseFailureReason implements FailureReason {
INVALID_DESTINATION_ID(MVCorei18n.DESTINATION_PARSE_FAILUREREASON_INVALIDDESTINATIONID),
;
Expand Down