1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-01-18 23:23:19 +01:00

Fix unstable Suggestion comparison by sorting int suggestions before text ones ()

This commit is contained in:
Emily 2025-01-12 19:49:29 -03:00 committed by GitHub
parent ad74b673fa
commit 50c2c59c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 0 deletions
paper-server/patches/sources/com/mojang/brigadier/suggestion

View file

@ -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
}
}

View file

@ -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) {