Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe779cd
commit 8c46e3b
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/auioc/mcmod/arnicalib/utils/game/MessageHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.auioc.mcmod.arnicalib.utils.game; | ||
|
||
import org.auioc.mcmod.arnicalib.api.java.function.StringToStringFunction; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
|
||
public class MessageHelper { | ||
|
||
private final Component prefix; | ||
private final StringToStringFunction i18n; | ||
|
||
public MessageHelper(Component prefix, StringToStringFunction i18n) { | ||
this.prefix = prefix; | ||
this.i18n = i18n; | ||
} | ||
|
||
public MessageHelper(String modName, StringToStringFunction i18n) { | ||
this(TextUtils.literal("[" + modName + "] ").withStyle(ChatFormatting.AQUA), i18n); | ||
} | ||
|
||
public MessageHelper(StringToStringFunction i18n) { | ||
this(TextUtils.empty(), i18n); | ||
} | ||
|
||
|
||
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) { | ||
return create(TextUtils.translatable(this.i18n.apply(key), args), withPrefix); | ||
} | ||
|
||
public MutableComponent create(String key, boolean withPrefix) { | ||
return create(key, withPrefix, TextUtils.NO_ARGS); | ||
} | ||
|
||
} |