Merge pull request #54 from qu1ckplay/master

Experimental logless chat messages
This commit is contained in:
cattyn
2026-03-25 01:53:43 +03:00
committed by GitHub
11 changed files with 105 additions and 33 deletions
@@ -0,0 +1,9 @@
package me.alpha432.oyvey.ducks.render;
import net.minecraft.client.GuiMessage;
import net.minecraft.network.chat.MessageSignature;
public interface IChatComponent {
void oyvey$addMessage(GuiMessage message);
void oyvey$removeMessage(MessageSignature signature);
}
@@ -9,6 +9,7 @@ import me.alpha432.oyvey.util.TextUtil;
import me.alpha432.oyvey.util.player.ChatUtil;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static me.alpha432.oyvey.features.commands.MessageIdentifiers.*;
public abstract class Command extends Feature {
public static final int NO_OP = -1;
@@ -25,7 +26,7 @@ public abstract class Command extends Feature {
public abstract void createArgumentBuilder(LiteralArgumentBuilder<CommandManager> builder);
protected int success(String message, Object... format) {
sendMessage(message, format);
sendMessage(message, SUCCESS, format);
return NO_OP;
}
@@ -34,7 +35,7 @@ public abstract class Command extends Feature {
}
protected int fail(String message, Object... format) {
sendMessage("{red} " + message, format);
sendMessage("{red} " + message, FAIL, format);
return NO_OP;
}
@@ -58,11 +59,14 @@ public abstract class Command extends Feature {
return true;
}
public static void sendMessage(String message, Object... format) {
if (message == null) {
return;
}
ChatUtil.sendMessage(TextUtil.text(message, format));
public static void sendMessage(String message, String identifier) {
if (message == null) return;
ChatUtil.sendMessage(TextUtil.text(message), identifier);
}
public static void sendMessage(String message, String identifier, Object... format) {
if (message == null) return;
ChatUtil.sendMessage(TextUtil.text(message, format), identifier);
}
public static LiteralArgumentBuilder<CommandManager> literal(String literal) {
@@ -72,4 +76,4 @@ public abstract class Command extends Feature {
public static <T> RequiredArgumentBuilder<CommandManager, T> argument(String name, ArgumentType<T> type) {
return RequiredArgumentBuilder.argument(name, type);
}
}
}
@@ -0,0 +1,7 @@
package me.alpha432.oyvey.features.commands;
public class MessageIdentifiers {
public static final String GENERAL = "general";
public static final String SUCCESS = "success";
public static final String FAIL = "fail";
}
@@ -40,7 +40,7 @@ public class BindCommand extends Command {
if (event.getKey() == GLFW_KEY_ESCAPE) {
module = null;
sendMessage("Operation canceled.");
sendMessage("Operation canceled.", "fail");
return;
}
@@ -66,7 +66,7 @@ public class HelpCommand extends Command {
List<Command> paginated = commands.subList((pageIndex - 1) * ITEMS_PER_PAGE,
Math.min(commands.size(), pageIndex * ITEMS_PER_PAGE));
sendMessage("Commands (%s):", commands.size());
sendMessage("Commands (%s):", "general", commands.size());
for (Command command : paginated) {
StringJoiner joiner = new StringJoiner(", ");
@@ -74,7 +74,7 @@ public class HelpCommand extends Command {
joiner.add(alias);
}
sendMessage("{dark_gray} %s: {reset}\n %s",
sendMessage("{dark_gray} %s: {reset}\n %s", "general",
joiner, command.getDescription());
}
@@ -88,11 +88,11 @@ public class Module extends Feature implements Jsonable, Toggleable {
Module module = OyVey.moduleManager.getModuleByDisplayName(name);
Module originalModule = OyVey.moduleManager.getModuleByName(name);
if (module == null && originalModule == null) {
Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name);
Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name, "general");
this.displayName.setValue(name);
return;
}
Command.sendMessage("{red} A module of this name already exists.");
Command.sendMessage("{red} A module of this name already exists.", "general");
}
@Override
@@ -28,6 +28,6 @@ public class NotificationsModule extends Module {
ChatUtil.sendMessage(TextUtil.text(MODULE_FORMAT,
event.getFeature().getName(),
moduleState ? "{green}" : "{red}",
moduleState ? "on" : "off"));
moduleState ? "on" : "off"), event.getFeature().getName());
}
}
@@ -17,6 +17,7 @@ import java.util.*;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static me.alpha432.oyvey.features.commands.Command.SINGLE_FAILURE;
import static me.alpha432.oyvey.features.commands.MessageIdentifiers.GENERAL;
public class CommandManager extends Feature implements Jsonable {
private static final Logger LOGGER = LogManager.getLogger("Commands");
@@ -45,16 +46,16 @@ public class CommandManager extends Feature implements Jsonable {
public void onChatSent(String message) {
try {
int result = dispatcher.execute(message.substring(
commandPrefix.length()).trim(), this);
int result = dispatcher.execute(message.substring(commandPrefix.length()).trim(), this);
if (result == SINGLE_SUCCESS) {
Command.sendMessage("{green} Command executed successfully");
Command.sendMessage("{green} Command executed successfully", GENERAL);
} else if (result == SINGLE_FAILURE) {
Command.sendMessage("{red} Failed to execute command");
Command.sendMessage("{red} Failed to execute command", GENERAL);
}
} catch (CommandSyntaxException e) {
LOGGER.error("Failed to execute command", e);
Command.sendMessage("{red} %s", e.getMessage());
Command.sendMessage("{red} %s", GENERAL, e.getMessage());
}
}
@@ -101,10 +102,10 @@ public class CommandManager extends Feature implements Jsonable {
@Override
public void fromJson(JsonElement element) {
if (element == null || !element.isJsonObject()) {
return;
}
if (element == null || !element.isJsonObject()) return;
JsonObject object = element.getAsJsonObject();
if (object.has("prefix")) {
setCommandPrefix(object.get("prefix").getAsString());
}
@@ -114,4 +115,4 @@ public class CommandManager extends Feature implements Jsonable {
public String getFileName() {
return "commands.json";
}
}
}
@@ -0,0 +1,32 @@
package me.alpha432.oyvey.mixin.render;
import me.alpha432.oyvey.ducks.render.IChatComponent;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.network.chat.MessageSignature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
@Mixin(ChatComponent.class)
public abstract class MixinChatComponent implements IChatComponent {
@Shadow
private List<GuiMessage> allMessages;
@Shadow
private void refreshTrimmedMessages() {}
@Override
public void oyvey$addMessage(GuiMessage message) {
this.allMessages.addFirst(message);
this.refreshTrimmedMessages();
}
@Override
public void oyvey$removeMessage(MessageSignature signature) {
this.allMessages.removeIf(message -> signature.equals(message.signature()));
this.refreshTrimmedMessages();
}
}
@@ -1,33 +1,51 @@
package me.alpha432.oyvey.util.player;
import me.alpha432.oyvey.OyVey;
import me.alpha432.oyvey.ducks.render.IChatComponent;
import me.alpha432.oyvey.features.commands.Command;
import net.minecraft.ChatFormatting;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSignature;
import net.minecraft.network.chat.Style;
import java.nio.charset.StandardCharsets;
import static me.alpha432.oyvey.util.traits.Util.mc;
public class ChatUtil {
public static void sendMessage(Component message) {
sendSilentMessage(Component.empty()
public static void sendMessage(Component message, String identifier) {
sendClientSideMessage(Component.empty()
.setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))
.append("<")
.append(getClientNameComponent())
.append(">")
.append(" ")
.append(message));
.append(message), identifier);
}
public static void sendSilentMessage(Component message) {
if (Command.nullCheck()) {
return;
}
// TODO add silent support ig
mc.gui.getChat().addMessage(message);
public static void sendClientSideMessage(Component message, String identifier) {
if (Command.nullCheck()) return;
IChatComponent chat = (IChatComponent) mc.gui.getChat();
MessageSignature signature = new MessageSignature(get256Bytes(identifier));
chat.oyvey$removeMessage(signature);
chat.oyvey$addMessage(new GuiMessage(mc.gui.getGuiTicks(), message, signature, getMessageTag()));
}
public static Component getClientNameComponent() {
return Component.empty().withColor(OyVey.colorManager.getColorAsInt()).append("OyVey");
}
private static GuiMessageTag getMessageTag() {
return new GuiMessageTag(OyVey.colorManager.getColorAsInt(), null, null, null);
}
private static byte[] get256Bytes(String identifier) {
byte[] bytes = new byte[256];
byte[] identifierBytes = identifier.getBytes(StandardCharsets.UTF_8);
System.arraycopy(identifierBytes, 0, bytes, 0, Math.min(bytes.length, identifierBytes.length));
return bytes;
}
}
+1
View File
@@ -11,6 +11,7 @@
"input.MixinKeyboard",
"input.MixinMouse",
"network.MixinClientPlayNetworkHandler",
"render.MixinChatComponent",
"render.MixinLevelRenderer",
"render.MixinRenderTickCounter",
"render.MixinWorldRenderer",