-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unstable Suggestion comparison by sorting int suggestions before …
…text ones (#11941)
- Loading branch information
1 parent
ad74b67
commit 50c2c59
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
paper-server/patches/sources/com/mojang/brigadier/suggestion/IntegerSuggestion.java.patch
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,19 @@ | ||
--- a/com/mojang/brigadier/suggestion/IntegerSuggestion.java | ||
+++ b/com/mojang/brigadier/suggestion/IntegerSuggestion.java | ||
@@ -53,7 +_,7 @@ | ||
|
||
@Override | ||
public int compareTo(final Suggestion o) { | ||
- if (o instanceof IntegerSuggestion) { | ||
+ if (false && o instanceof IntegerSuggestion) { // Paper - fix unstable Suggestion comparison | ||
return Integer.compare(value, ((IntegerSuggestion) o).value); | ||
} | ||
return super.compareTo(o); | ||
@@ -61,6 +_,6 @@ | ||
|
||
@Override | ||
public int compareToIgnoreCase(final Suggestion b) { | ||
- return compareTo(b); | ||
+ return super.compareToIgnoreCase(b); // Paper - fix unstable Suggestion comparison | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
paper-server/patches/sources/com/mojang/brigadier/suggestion/Suggestion.java.patch
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,32 @@ | ||
--- a/com/mojang/brigadier/suggestion/Suggestion.java | ||
+++ b/com/mojang/brigadier/suggestion/Suggestion.java | ||
@@ -76,13 +_,27 @@ | ||
'}'; | ||
} | ||
|
||
+ // Paper start - fix unstable Suggestion comparison | ||
+ private static int compare0(final Suggestion lhs, final Suggestion rhs, final java.util.Comparator<String> textComparator) { | ||
+ if (lhs instanceof final IntegerSuggestion lis && rhs instanceof final IntegerSuggestion ris) { | ||
+ return Integer.compare(lis.getValue(), ris.getValue()); | ||
+ } else if (lhs instanceof IntegerSuggestion) { | ||
+ return -1; | ||
+ } else if (rhs instanceof IntegerSuggestion) { | ||
+ return 1; | ||
+ } else { | ||
+ return textComparator.compare(lhs.text, rhs.text); | ||
+ } | ||
+ } | ||
+ // Paper end - fix unstable Suggestion comparison | ||
+ | ||
@Override | ||
public int compareTo(final Suggestion o) { | ||
- return text.compareTo(o.text); | ||
+ return compare0(this, o, java.util.Comparator.naturalOrder()); // Paper - fix unstable Suggestion comparison | ||
} | ||
|
||
public int compareToIgnoreCase(final Suggestion b) { | ||
- return text.compareToIgnoreCase(b.text); | ||
+ return compare0(this, b, String.CASE_INSENSITIVE_ORDER); // Paper - fix unstable Suggestion comparison | ||
} | ||
|
||
public Suggestion expand(final String command, final StringRange range) { |