mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
More implementation, timed teleports, regex, etc
This commit is contained in:
1 parent
7ac52d747f
commit
e335a48888
25 files changed
+803
-157
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Utility for matching a username based on an input name
|
||||
*/
|
||||
public final class MatcherUtil {
|
||||
|
||||
/**
|
||||
* Match a player's username from a user-supplied input name
|
||||
*
|
||||
* @param inputName the user input name
|
||||
* @param plugin the implementing plugin
|
||||
* @return an optional, containing a matched username if one was found
|
||||
*/
|
||||
public static Optional<String> matchPlayerName(@NotNull String inputName, @NotNull HuskHomes plugin) {
|
||||
// Return an exact match if there is one present
|
||||
final Optional<String> exactPlayer = plugin.getCache().players.stream().filter(username ->
|
||||
username.equalsIgnoreCase(inputName)).findFirst();
|
||||
if (exactPlayer.isPresent()) {
|
||||
return exactPlayer;
|
||||
}
|
||||
|
||||
// Return most likely match, if present
|
||||
return plugin.getCache().players.stream().filter(username -> username.toLowerCase()
|
||||
.startsWith(inputName.toLowerCase())).min(Comparator.comparingInt(username ->
|
||||
username.length() - inputName.toLowerCase().length()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.william278.huskhomes.position.PositionMeta;
|
||||
|
||||
/**
|
||||
* Provides a number of utility regular expressions for checking home name patterns
|
||||
*/
|
||||
public final class RegexUtil {
|
||||
|
||||
/**
|
||||
* Pattern for checking home and warp {@link PositionMeta} description fields
|
||||
*/
|
||||
public static final Pattern DESCRIPTION_PATTERN = Pattern.compile("[a-zA-Z\\d\\-_\\s]+");
|
||||
|
||||
/**
|
||||
* Pattern for checking home and warp {@link PositionMeta} name fields
|
||||
*/
|
||||
public static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z\\d_\\-]+");
|
||||
|
||||
/**
|
||||
* Pattern for checking public home input fields
|
||||
* e.g. {@code ownerName.homeName}
|
||||
*/
|
||||
public static final Pattern OWNER_NAME_PATTERN = Pattern.compile("\\w+\\.[A-Za-z\\d_\\-]+");
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user