Skip to content

Commit

Permalink
feat(utils): MessageHelper send message methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Aug 16, 2022
1 parent 5cc9fd1 commit 3a13cc8
Showing 1 changed file with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}

}

0 comments on commit 3a13cc8

Please sign in to comment.