aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-05-29 12:30:31 +0200
committerCow <cow@volloeko.de>2020-05-29 12:30:31 +0200
commitb9d6b75423ea24c4947b3a655f199c3b34aa167a (patch)
tree7df92efa2a2c4533326e9f37e9062db08cc13e51 /src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java
parent4d45e0bc9afacc8408295aef50b8fd6530f97104 (diff)
downloadCowlection-b9d6b75423ea24c4947b3a655f199c3b34aa167a.tar.gz
Cowlection-b9d6b75423ea24c4947b3a655f199c3b34aa167a.tar.bz2
Cowlection-b9d6b75423ea24c4947b3a655f199c3b34aa167a.zip
Added /moo stalkskyblock <playerName>
- Now using CommandExceptions instead of just red chat color for command error messages - Simplified creation of chat message
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java')
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java b/src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java
new file mode 100644
index 0000000..a489391
--- /dev/null
+++ b/src/main/java/eu/olli/cowmoonication/util/MooChatComponent.java
@@ -0,0 +1,186 @@
+package eu.olli.cowmoonication.util;
+
+import net.minecraft.event.ClickEvent;
+import net.minecraft.event.HoverEvent;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IChatComponent;
+
+public class MooChatComponent extends ChatComponentText {
+ public MooChatComponent(String msg) {
+ super(msg);
+ }
+
+ public MooChatComponent black() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.BLACK));
+ return this;
+ }
+
+ public MooChatComponent darkBlue() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_BLUE));
+ return this;
+ }
+
+ public MooChatComponent darkGreen() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_GREEN));
+ return this;
+ }
+
+ public MooChatComponent darkAqua() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_AQUA));
+ return this;
+ }
+
+ public MooChatComponent darkRed() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_RED));
+ return this;
+ }
+
+ public MooChatComponent darkPurple() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_PURPLE));
+ return this;
+ }
+
+ public MooChatComponent gold() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.GOLD));
+ return this;
+ }
+
+ public MooChatComponent gray() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.GRAY));
+ return this;
+ }
+
+ public MooChatComponent darkGray() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.DARK_GRAY));
+ return this;
+ }
+
+ public MooChatComponent blue() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.BLUE));
+ return this;
+ }
+
+ public MooChatComponent green() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.GREEN));
+ return this;
+ }
+
+ public MooChatComponent aqua() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.AQUA));
+ return this;
+ }
+
+ public MooChatComponent red() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.RED));
+ return this;
+ }
+
+ public MooChatComponent lightPurple() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE));
+ return this;
+ }
+
+ public MooChatComponent yellow() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.YELLOW));
+ return this;
+ }
+
+ public MooChatComponent white() {
+ setChatStyle(getChatStyle().setColor(EnumChatFormatting.WHITE));
+ return this;
+ }
+
+ public MooChatComponent obfuscated() {
+ setChatStyle(getChatStyle().setObfuscated(true));
+ return this;
+ }
+
+ public MooChatComponent bold() {
+ setChatStyle(getChatStyle().setBold(true));
+ return this;
+ }
+
+ public MooChatComponent strikethrough() {
+ setChatStyle(getChatStyle().setStrikethrough(true));
+ return this;
+ }
+
+ public MooChatComponent underline() {
+ setChatStyle(getChatStyle().setUnderlined(true));
+ return this;
+ }
+
+ public MooChatComponent italic() {
+ setChatStyle(getChatStyle().setItalic(true));
+ return this;
+ }
+
+ public MooChatComponent reset() {
+ setChatStyle(getChatStyle().setParentStyle(null).setBold(false).setItalic(false).setObfuscated(false).setUnderlined(false).setStrikethrough(false));
+ return this;
+ }
+
+ public MooChatComponent setHover(IChatComponent hover) {
+ setChatStyle(getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover)));
+ return this;
+ }
+
+ public MooChatComponent setUrl(String url) {
+ setUrl(url, new KeyValueTooltipComponent("Click to visit", url));
+ return this;
+ }
+
+ public MooChatComponent setUrl(String url, String hover) {
+ setUrl(url, new MooChatComponent(hover).yellow());
+ return this;
+ }
+
+ public MooChatComponent setUrl(String url, IChatComponent hover) {
+ setChatStyle(getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)));
+ setHover(hover);
+ return this;
+ }
+
+ public MooChatComponent setSuggestCommand(String command) {
+ setChatStyle(getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
+ setHover(new KeyValueChatComponent("Run", command, " "));
+ return this;
+ }
+
+ /**
+ * Appends the given component in a new line, without inheriting formatting of previous siblings.
+ *
+ * @see ChatComponentText#appendSibling appendSibling
+ */
+ public MooChatComponent appendFreshSibling(IChatComponent sibling) {
+ this.siblings.add(new ChatComponentText("\n").appendSibling(sibling));
+ return this;
+ }
+
+ @Deprecated
+ public MooChatComponent appendKeyValue(String key, String value) {
+ appendSibling(new MooChatComponent("\n").appendFreshSibling(new KeyValueChatComponent(key, value)));
+ return this;
+ }
+
+ public static class KeyValueChatComponent extends MooChatComponent {
+ public KeyValueChatComponent(String key, String value) {
+ this(key, value, ": ");
+ }
+
+ public KeyValueChatComponent(String key, String value, String separator) {
+ super(key);
+ appendText(separator);
+ gold().appendSibling(new MooChatComponent(value).yellow());
+ }
+ }
+
+ public static class KeyValueTooltipComponent extends MooChatComponent {
+ public KeyValueTooltipComponent(String key, String value) {
+ super(key);
+ appendText(": ");
+ gray().appendSibling(new MooChatComponent(value).yellow());
+ }
+ }
+}