-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from TheNextLvl-net/wildcard
Wildcard support
- Loading branch information
Showing
11 changed files
with
178 additions
and
41 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
api/src/main/java/net/thenextlvl/commander/CommandFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.thenextlvl.commander; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* The CommandFinder interface defines methods for finding commands based on a given input. | ||
*/ | ||
public interface CommandFinder { | ||
/** | ||
* Finds commands based on the given input. | ||
* | ||
* @param input The input used to search for commands. | ||
* @return A set of strings representing the found commands. | ||
*/ | ||
Set<String> findCommands(String input); | ||
|
||
/** | ||
* This method finds commands based on a given input. | ||
* | ||
* @param commands The stream of commands to search for. | ||
* @param input The input used to search for commands. | ||
* @return A set of strings representing the found commands. | ||
*/ | ||
Set<String> findCommands(Stream<String> commands, String input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
paper/src/main/java/net/thenextlvl/commander/paper/implementation/PaperCommandFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.thenextlvl.commander.paper.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.CommandFinder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public class PaperCommandFinder implements CommandFinder { | ||
private final CommanderPlugin plugin; | ||
|
||
public Set<String> findCommands(String input) { | ||
return findCommands(plugin.getServer().getCommandMap().getKnownCommands().entrySet() | ||
.stream().mapMulti((entry, consumer) -> { | ||
consumer.accept(entry.getKey()); | ||
entry.getValue().getAliases().forEach(consumer); | ||
}), input); | ||
} | ||
|
||
public Set<String> findCommands(Stream<String> commands, String input) { | ||
var pattern = Pattern.compile(input.replace("*", ".*")); | ||
return commands.filter(command -> | ||
pattern.matcher(command).matches() | ||
).collect(Collectors.toSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ty/src/main/java/net/thenextlvl/commander/velocity/implementation/ProxyCommandFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.thenextlvl.commander.velocity.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.CommandFinder; | ||
import net.thenextlvl.commander.velocity.CommanderPlugin; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public class ProxyCommandFinder implements CommandFinder { | ||
private final CommanderPlugin plugin; | ||
|
||
@Override | ||
public Set<String> findCommands(String input) { | ||
return findCommands(plugin.server().getCommandManager().getAliases().stream(), input); | ||
} | ||
|
||
@Override | ||
public Set<String> findCommands(Stream<String> commands, String input) { | ||
var pattern = Pattern.compile(input.replace("*", ".*")); | ||
return commands.filter(command -> | ||
pattern.matcher(command).matches() | ||
).collect(Collectors.toSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.