Skip to content

Commit

Permalink
Fix a crash when trying to modify suggestions (Closes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
shurik204 committed May 18, 2024
1 parent 8840a2e commit cc007b2
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static me.shurik.bettersuggestions.ModConstants.CONFIG;
Expand Down Expand Up @@ -70,7 +71,16 @@ public class SuggestionWindowMixin {
void init(ChatInputSuggestor suggestor, int x, int y, int width, List<Suggestion> suggestions, boolean narrateFirstSuggestion, CallbackInfo info) {
ChatInputSuggestorAccessorMixin suggestorAccessor = (ChatInputSuggestorAccessorMixin) suggestor;
this.suggestions$textRenderer = suggestorAccessor.getTextRenderer();


// Try modifying the suggestions list
try {
// https://stackoverflow.com/questions/8364856/how-to-test-if-a-list-extends-object-is-an-unmodifablelist
this.suggestions.addAll(Collections.emptyList());
} catch (UnsupportedOperationException e) {
// Silently exit if the list is unmodifiable
return;
}

// TODO: add color customization for chat and cmd block input
// suggestor.owner instanceof ChatScreen and suggestor.owner instanceof AbstractCommandBlockScreen
// if (suggestorAccessor.getOwner() instanceof ChatScreen) {
Expand Down Expand Up @@ -119,7 +129,7 @@ else if (customSuggestion.isEntitySuggestion()) {
otherSuggestions.add(suggestion);
}
}

this.suggestions.clear();
this.suggestions.addAll(prioritizedSuggestions);
this.suggestions.addAll(otherSuggestions);
Expand Down

0 comments on commit cc007b2

Please sign in to comment.