Skip to content

Commit

Permalink
Util index rename
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuilder1961 committed Dec 22, 2023
1 parent ba45abd commit 05de3c2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.client.network.message.MessageHandler;
import net.minecraft.network.message.MessageSignatureData;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.text.Text;
Expand All @@ -29,7 +27,7 @@
/**
* A mixin used to cache the metadata of the most recent message
* received by the client. This is used in
* {@link ChatHudMixin#modifyMessage(Text, Text, MessageSignatureData, int, MessageIndicator, boolean)}
* {@link ChatHudMixin#modifyMessage(Text, boolean)}
* to provide more accurate timestamp data, the correct player
* name, and the player's UUID.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.List;

import static obro1961.chatpatches.ChatPatches.config;
import static obro1961.chatpatches.util.ChatUtils.OG_MSG_INDEX;
import static obro1961.chatpatches.util.ChatUtils.MSG_INDEX;
import static obro1961.chatpatches.util.SharedVariables.lastMsg;

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ private Text addCounter(Text incoming, boolean refreshing) {
// exclude the first message, already checked above
messages.subList(1, attemptDistance)
.stream()
.filter( hudLine -> hudLine.content().getSiblings().get(OG_MSG_INDEX).getString().equalsIgnoreCase( incoming.getSiblings().get(OG_MSG_INDEX).getString() ) )
.filter( hudLine -> hudLine.content().getSiblings().get(MSG_INDEX).getString().equalsIgnoreCase( incoming.getSiblings().get(MSG_INDEX).getString() ) )
.findFirst()
.ifPresent( hudLine -> ChatUtils.getCondensedMessage(incoming, messages.indexOf(hudLine)) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ protected void initSearchStuff(CallbackInfo ci) {
return "";
}));
hoverButtons.put(COPY_NAME, of(1, COPY_NAME, () -> {
Text message = selectedLine.content().getSiblings().get(ChatUtils.OG_MSG_INDEX);
Text message = selectedLine.content().getSiblings().get(ChatUtils.MSG_INDEX);
Text text = message.getSiblings().size() > ChatUtils.MSG_NAME_INDEX ? message.getSiblings().get(ChatUtils.MSG_NAME_INDEX) : Text.empty();
HoverEvent.EntityContent player = text.getStyle().getHoverEvent() != null ? text.getStyle().getHoverEvent().getValue(SHOW_ENTITY) : null;
return player != null ? player.name.getString() : text.getString();
}));
hoverButtons.put(COPY_UUID, of(1, COPY_UUID, () -> {
Text message = selectedLine.content().getSiblings().get(ChatUtils.OG_MSG_INDEX);
Text message = selectedLine.content().getSiblings().get(ChatUtils.MSG_INDEX);
Text text = message.getSiblings().size() > ChatUtils.MSG_NAME_INDEX ? message.getSiblings().get(ChatUtils.MSG_NAME_INDEX) : Text.empty();
HoverEvent.EntityContent player = text.getStyle().getHoverEvent() != null ? text.getStyle().getHoverEvent().getValue(SHOW_ENTITY) : null;
return player != null ? player.uuid.toString() : text.getString();
Expand Down Expand Up @@ -620,7 +620,7 @@ so i switched it to a startsWith() bc the first one never has extra spaces. /!\
mainButtons.get(COPY_UNIX).readyToRender(true);

// add player data and reply buttons
Text originalMessage = selectedLine.content().getSiblings().size() > ChatUtils.OG_MSG_INDEX ? selectedLine.content().getSiblings().get(ChatUtils.OG_MSG_INDEX) : Text.empty();
Text originalMessage = selectedLine.content().getSiblings().size() > ChatUtils.MSG_INDEX ? selectedLine.content().getSiblings().get(ChatUtils.MSG_INDEX) : Text.empty();
Style style = originalMessage.getSiblings().size() > 0 ? originalMessage.getSiblings().get(ChatUtils.MSG_NAME_INDEX).getStyle() : Style.EMPTY;
if( !style.equals(Style.EMPTY) && style.getHoverEvent() != null && style.getHoverEvent().getAction() == HoverEvent.Action.SHOW_ENTITY ) {
PlayerListEntry player = client.getNetworkHandler().getPlayerListEntry( UUID.fromString(hoverButtons.get(COPY_UUID).copySupplier.get()) );
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/obro1961/chatpatches/util/ChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
public class ChatUtils {
public static final UUID NIL_UUID = new UUID(0, 0);
public static final MessageData NIL_MSG_DATA = new MessageData(new GameProfile(ChatUtils.NIL_UUID, ""), Date.from(Instant.EPOCH), false);
public static final int TIMESTAMP_INDEX = 0, OG_MSG_INDEX = 1, DUPE_COUNTER_INDEX = 2; // indices of all main (modified message) components
public static final int MSG_NAME_INDEX = 0, MSG_MSG_INDEX = 1, MSG_FORMATTED_TEXT_INDEX = 2; // indices of all OG_MSG_INDEX components
public static final int TIMESTAMP_INDEX = 0, MSG_INDEX = 1, DUPE_COUNTER_INDEX = 2; // indices of all main (modified message) components
public static final int MSG_NAME_INDEX = 0, MSG_MSG_INDEX = 1, MSG_FORMATTED_TEXT_INDEX = 2; // indices of all MSG_INDEX components
/**
* Matches a vanilla message, with captures for the playername and message.
* Considers a message invalid if {@link net.minecraft.SharedConstants#isValidChar(char)}
Expand Down Expand Up @@ -75,7 +75,7 @@ public static Text getCondensedMessage(Text incoming, int index) {


// IF the last and incoming message bodies are equal, continue
if( incomingParts.get(OG_MSG_INDEX).getString().equalsIgnoreCase(comparingParts.get(OG_MSG_INDEX).getString()) ) {
if( incomingParts.get(MSG_INDEX).getString().equalsIgnoreCase(comparingParts.get(MSG_INDEX).getString()) ) {

// info: according to some limited testing, incoming messages (incomingParts) will never contain a dupe counter, so it's been omitted from this check
int dupes = (
Expand Down

0 comments on commit 05de3c2

Please sign in to comment.