mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
When sorting commands for //help, ignore / characters.
This commit is contained in:
@ -19,7 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Compares the primary aliases of two {@link CommandMapping} using
|
||||
@ -30,14 +32,28 @@ public final class PrimaryAliasComparator implements Comparator<CommandMapping>
|
||||
/**
|
||||
* An instance of this class.
|
||||
*/
|
||||
public static final PrimaryAliasComparator INSTANCE = new PrimaryAliasComparator();
|
||||
public static final PrimaryAliasComparator INSTANCE = new PrimaryAliasComparator(null);
|
||||
private final @Nullable Pattern removalPattern;
|
||||
|
||||
private PrimaryAliasComparator() {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param removalPattern a regex to remove unwanted characters from the compared aliases
|
||||
*/
|
||||
public PrimaryAliasComparator(@Nullable Pattern removalPattern) {
|
||||
this.removalPattern = removalPattern;
|
||||
}
|
||||
|
||||
private String clean(String alias) {
|
||||
if (removalPattern != null) {
|
||||
return removalPattern.matcher(alias).replaceAll("");
|
||||
}
|
||||
return alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(CommandMapping o1, CommandMapping o2) {
|
||||
return o1.getPrimaryAlias().compareTo(o2.getPrimaryAlias());
|
||||
return clean(o1.getPrimaryAlias()).compareTo(clean(o2.getPrimaryAlias()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user