diff options
6 files changed, 80 insertions, 11 deletions
diff --git a/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java b/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java index b11804a..cedb25e 100644 --- a/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java +++ b/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java @@ -145,7 +145,7 @@ public class Chat { } private static void sendPrivateMessageToSelfBase(String message) { - EnvironmentCore.chat.sendClientSideMessage(Message.of(message)); + EnvironmentCore.chat.sendClientSideMessage(Message.of(message), false); } public static void sendPrivateMessageToSelfText(Message message) { diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/common/client/Config.java index 455df36..50f898d 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/Config.java @@ -48,6 +48,10 @@ public class Config implements Serializable { public boolean autoSplashStatusUpdates; public String nickname; public String notifForMessagesType; + // trols + public boolean swapActionBarChat = false; + public boolean swapOnlyNormal = true; + public boolean swapOnlyBBsentials = false; // Set default attribute values private void setDefaults() { diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java index eeb89fe..08cbff8 100644 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java +++ b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java @@ -6,4 +6,8 @@ public interface MCChat { void init(); void sendChatMessage(String message); void sendClientSideMessage(Message message); + + void sendClientSideMessage(Message message, boolean actionbar); + + void showActionBar(Message message); } diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java index a723284..5cfcbe3 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java @@ -133,6 +133,29 @@ public class BBsentialsConfigScreemFactory { .setTooltip(Text.of("Do you want that whenever someone sends you a msg ending with 'bb:party me' to send them a party invite automatically?")) .setSaveConsumer(newValue -> BBsentials.config.allowBBinviteMe = newValue) .build()); + SubCategoryBuilder trolls = entryBuilder.startSubCategory(Text.of("Trolls")).setExpanded(false); + BooleanListEntry swapActionBarAndChat = (entryBuilder.startBooleanToggle(Text.of("Actionbar-Chat switch"), BBsentials.config.swapActionBarChat) + .setDefaultValue(false) + .setTooltip(Text.of("Swap that chat messages are shown in actionbar and reverse")) + .setSaveConsumer(newValue -> BBsentials.config.swapActionBarChat = newValue) + .build()); + Requirement trollSwapEnabled = swapActionBarAndChat::getValue; + BooleanListEntry swapActionBarAndChatOnlyNormal = (entryBuilder.startBooleanToggle(Text.of("Only normal messages"), BBsentials.config.swapOnlyNormal) + .setDefaultValue(false) + .setRequirement(trollSwapEnabled) + .setTooltip(Text.of("Swap only the default messages (→ everything not from BBsentials)")) + .setSaveConsumer(newValue -> BBsentials.config.swapOnlyNormal = newValue) + .build()); + BooleanListEntry swapActionBarAndChatOnlyBB = (entryBuilder.startBooleanToggle(Text.of("Only BBsentials messages"), BBsentials.config.swapOnlyBBsentials) + .setDefaultValue(false) + .setRequirement(trollSwapEnabled) + .setTooltip(Text.of("Swap only the messages from BBsentials")) + .setSaveConsumer(newValue -> BBsentials.config.swapOnlyBBsentials = newValue) + .build()); + trolls.add(swapActionBarAndChat); + trolls.add(swapActionBarAndChatOnlyNormal); + trolls.add(swapActionBarAndChatOnlyBB); + other.addEntry(trolls.build()); ConfigCategory chChestItems = builder.getOrCreateCategory(Text.of("Ch Chest Items")); { BooleanListEntry allItems = entryBuilder.startBooleanToggle(Text.of("All Chest Items"), BBsentials.config.toDisplayConfig.allChChestItem) diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java index d4fefd3..e78df68 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java @@ -2,6 +2,7 @@ package de.hype.bbsentials.fabric; import de.hype.bbsentials.common.chat.Chat; import de.hype.bbsentials.common.chat.Message; +import de.hype.bbsentials.common.client.BBsentials; import de.hype.bbsentials.common.mclibraries.MCChat; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents; @@ -21,10 +22,7 @@ public class FabricChat implements MCChat { chat.onEvent(new Message(Text.Serializer.toJson(message), message.getString())); }); ClientReceiveMessageEvents.MODIFY_GAME.register((message, actionbar) -> { - if (!actionbar) { - return prepareOnEvent(message, actionbar); - } - return message; + return prepareOnEvent(message, actionbar); }); ClientSendMessageEvents.CHAT.register(message -> { if (message.startsWith("/")) { @@ -36,8 +34,19 @@ public class FabricChat implements MCChat { public Text prepareOnEvent(Text text, boolean actionbar) { String json = Text.Serializer.toJson(text); Message message = new Message(json, text.getString(), actionbar); - Message returned = chat.onEvent(message); - Text toReturn = Text.Serializer.fromJson(returned.getJson()); + if (!actionbar) { + message = chat.onEvent(message); + } + Text toReturn = Text.Serializer.fromJson(message.getJson()); + if (BBsentials.config.swapActionBarChat && !BBsentials.config.swapOnlyBBsentials) { + if (!actionbar) { + showActionBar(message); + } + else { + sendClientSideMessage(message); + } + return null; + } return toReturn; } @@ -49,6 +58,9 @@ public class FabricChat implements MCChat { } public void sendClientSideMessage(Message message, boolean actionbar) { + if (BBsentials.config.swapActionBarChat && !BBsentials.config.swapOnlyNormal) { + actionbar = !actionbar; + } if (actionbar) { showActionBar(message); } @@ -56,7 +68,6 @@ public class FabricChat implements MCChat { sendClientSideMessage(message); } } - public void showActionBar(Message message) { MinecraftClient client = MinecraftClient.getInstance(); if (client.player != null) { diff --git a/forge/src/main/java/de/hype/bbsentials/forge/ForgeChat.java b/forge/src/main/java/de/hype/bbsentials/forge/ForgeChat.java index f84d760..7764d7b 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/ForgeChat.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/ForgeChat.java @@ -2,9 +2,11 @@ package de.hype.bbsentials.forge; import de.hype.bbsentials.common.chat.Chat; import de.hype.bbsentials.common.chat.Message; +import de.hype.bbsentials.common.client.BBsentials; import de.hype.bbsentials.common.mclibraries.MCChat; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.ChatStyle; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.common.MinecraftForge; @@ -26,10 +28,11 @@ public class ForgeChat implements MCChat { if (!(event.type == 2)) { //2 means action bar // Chat.sendPrivateMessageToSelfDebug(String.valueOf(((int) event.type))); - Message newMessage = chat.onEvent(new Message(IChatComponent.Serializer.componentToJson(event.message), event.message.getUnformattedText())); - if (!newMessage.equals(event.message)) { + Message message = new Message(IChatComponent.Serializer.componentToJson(event.message), event.message.getUnformattedText()); + Message newMessage = chat.onEvent(message); + if (!newMessage.equals(message)) { event.setCanceled(true); - Chat.sendPrivateMessageToSelfText(newMessage); + sendClientSideMessage(newMessage); } } } @@ -43,7 +46,31 @@ public class ForgeChat implements MCChat { } } + + public void sendClientSideMessage(Message message, boolean actionbar) { + if (BBsentials.config.swapActionBarChat && !BBsentials.config.swapOnlyNormal) { + actionbar = !actionbar; + } + if (actionbar) { + showActionBar(message); + } + else { + sendClientSideMessage(message); + } + } + public void sendChatMessage(String message) { Minecraft.getMinecraft().thePlayer.sendChatMessage(message); } + + public void showActionBar(Message message) { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (player != null) { + String json = message.getJson(); + IChatComponent text = IChatComponent.Serializer.jsonToComponent(json); + // Display the text in the action bar + Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text); + } + } + } |