Skip to content

Commit

Permalink
Fix up/down arrows in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed May 17, 2024
1 parent c31c2cb commit 08fc672
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/java/net/wurstclient/mixin/ChatScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,36 @@ protected void onInit(CallbackInfo ci)
public void onSendMessage(String message, boolean addToHistory,
CallbackInfoReturnable<Boolean> cir)
{
// Ignore empty messages just like vanilla
if((message = normalize(message)).isEmpty())
return;

// Create and fire the chat output event
ChatOutputEvent event = new ChatOutputEvent(message);
EventManager.fire(event);

if(event.isCancelled())
{
cir.setReturnValue(true);
// If the event hasn't been modified or cancelled,
// let the vanilla method handle the message
boolean cancelled = event.isCancelled();
if(!cancelled && !event.isModified())
return;
}

if(!event.isModified())
return;
// Otherwise, cancel the vanilla method and handle the message here
cir.setReturnValue(true);

// Add the message to history, even if it was cancelled
// Otherwise the up/down arrows won't work correctly
String newMessage = event.getMessage();
if(addToHistory)
client.inGameHud.getChatHud().addToMessageHistory(newMessage);

if(newMessage.startsWith("/"))
client.player.networkHandler
.sendChatCommand(newMessage.substring(1));
else
client.player.networkHandler.sendChatMessage(newMessage);

cir.setReturnValue(true);
// If the event isn't cancelled, send the modified message
if(!cancelled)
if(newMessage.startsWith("/"))
client.player.networkHandler
.sendChatCommand(newMessage.substring(1));
else
client.player.networkHandler.sendChatMessage(newMessage);
}

@Shadow
Expand Down

0 comments on commit 08fc672

Please sign in to comment.