From 3a13cc884dbb740d2367fd0f372591bc385db709 Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Tue, 16 Aug 2022 17:17:16 +0800 Subject: [PATCH] feat(utils): MessageHelper send message methods --- .../arnicalib/utils/game/MessageHelper.java | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/MessageHelper.java b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/MessageHelper.java index b2c3ff8d..492b9958 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/MessageHelper.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/MessageHelper.java @@ -2,8 +2,11 @@ import org.auioc.mcmod.arnicalib.api.java.function.StringToStringFunction; import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.server.level.ServerPlayer; public class MessageHelper { @@ -28,12 +31,63 @@ public MutableComponent create(Component message, boolean withPrefix) { return withPrefix ? (TextUtils.empty()).append(this.prefix).append(message) : (TextUtils.empty()).append(message); } - public MutableComponent create(String key, boolean withPrefix, Object... args) { + public MutableComponent create(String key, Object[] args, boolean withPrefix) { return create(TextUtils.translatable(this.i18n.apply(key), args), withPrefix); } + @Deprecated + public MutableComponent create(String key, boolean withPrefix, Object... args) { + return create(key, args, withPrefix); + } + public MutableComponent create(String key, boolean withPrefix) { - return create(key, withPrefix, TextUtils.NO_ARGS); + return create(key, TextUtils.NO_ARGS, withPrefix); + } + + + public void send(ServerPlayer player, ChatType type, boolean withPrefix, Component message) { + player.sendMessage(create(message, withPrefix), type, Util.NIL_UUID); + } + + public void send(ServerPlayer player, ChatType type, boolean withPrefix, String key, Object... arg) { + player.sendMessage(create(key, arg, withPrefix), type, Util.NIL_UUID); + } + + + public void sendSystemMessage(ServerPlayer player, Component message) { + send(player, ChatType.SYSTEM, true, message); + } + + public void sendChatMessage(ServerPlayer player, Component message) { + send(player, ChatType.CHAT, true, message); + } + + public void sendGameInfo(ServerPlayer player, Component message) { + send(player, ChatType.GAME_INFO, false, message); + } + + public void sendSystemMessage(ServerPlayer player, String key, Object... args) { + send(player, ChatType.SYSTEM, true, key, args); + } + + public void sendChatMessage(ServerPlayer player, String key, Object... args) { + send(player, ChatType.CHAT, true, key, args); + } + + public void sendGameInfo(ServerPlayer player, String key, Object... args) { + send(player, ChatType.GAME_INFO, false, key, args); + } + + public void sendSystemMessage(ServerPlayer player, String key) { + sendSystemMessage(player, key, TextUtils.NO_ARGS); + } + + public void sendChatMessage(ServerPlayer player, String key) { + sendChatMessage(player, key, TextUtils.NO_ARGS); + } + + public void sendGameInfo(ServerPlayer player, String key) { + sendGameInfo(player, key, TextUtils.NO_ARGS); } }