Skip to content

Commit

Permalink
1.2.0 aka quite big update
Browse files Browse the repository at this point in the history
- Added support for some basic markdown syntax
- Added support for emotes, you can add custom ones in config and use them by typing `:emote_name:`
- Added <spoiler> chat tag
- Added support for /msg, /teammsg, /say and /me
- Added /tellform command - It's like tellraw, but you use same formatting as StyledChat
- You can now style pets death message
- Enabled more tags by default
- You can enable formatting in /msg and /teammsg
- You can now hide some messages by empting their value (without removing them), example: `"join": ""`
- Updated bundled Placeholder API
- Changed default URL color
- Bundled required parts of fabric api so it's no longer required dependency
- Exposed some new events/methods for better mod compatibility
  • Loading branch information
Patbox committed Oct 18, 2021
1 parent c130fd2 commit 9f33f8d
Show file tree
Hide file tree
Showing 25 changed files with 1,200 additions and 145 deletions.
109 changes: 85 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Styled Chat
It's a simple mod that allows server owners to change how their chat looks!
It supports changing style per player with permissions (supports LuckPerms and PlayerRoles)
If you have any questions, you can ask them on my [Discord](https://discord.com/invite/AbqPPppgrd)

![Example image](https://i.imgur.com/y0KGyVT.png)
![Example image2](https://i.imgur.com/ObepOhW.png)
It adds support for [modern chat formatting](https://placeholders.pb4.eu/user/text-format/) supported by Minecraft,
but ignored by many chat mods/plugins.

It's also compatible with any mods using [Placeholder API](https://placeholders.pb4.eu/user/general/).

It also supports changing style per player with permissions (supports LuckPerms and PlayerRoles)

*This mod works only on Fabric Mod Loader and compatible!*

If you have any questions, you can ask them on my [Discord](https://pb4.eu/discord)

[Also check out my other mods and project, as you might find them useful!](https://pb4.eu)

![Example image](https://i.imgur.com/HPSMaS8.png)
![Example image2](https://i.imgur.com/mSWzIV4.png)


## Commands (and permissions):
Expand All @@ -13,8 +24,8 @@ If you have any questions, you can ask them on my [Discord](https://discord.com/

## Configuration:
You can find config file in `./config/styled-chat.json`.
[Formatting uses PlaceholderAPI's Text Parser for which docs you can find here](https://github.com/Patbox/FabricPlaceholderAPI/blob/1.17/TEXT_FORMATTING.md).
It supports usage of placeholders from [Placeholder API](https://github.com/Patbox/FabricPlaceholderAPI/wiki).
[Formatting uses Simplified Text Format](https://placeholders.pb4.eu/user/text-format/).
It supports usage of placeholders from [Placeholder API](https://placeholders.pb4.eu/user/general/).
Additionally, every message type has few own local variables.

```json5
Expand Down Expand Up @@ -66,61 +77,111 @@ It supports all default ones with addition of `<item>` tag.
"joinRenamed": "<gray>✚</gray> <color:#85ff8f><lang:multiplayer.player.joined.renamed:'${player}':'${old_name}'>",
"left": "<gray>☁</gray> <color:#ff8585><lang:multiplayer.player.left:'${player}'>",
"death": "<gray>☠</gray> <color:#d1d1d1>${default_message}",
"advancementTask": "<gray>✔</gray> <gold><lang:chat.type.advancement.task:'${player}':'${advancement}'>",
"advancementChallenge": "<gray>✔</gray> <gold><lang:chat.type.advancement.challenge:'${player}':'${advancement}'>",
"advancementGoal": "<gray>✔</gray> <gold><lang:chat.type.advancement.goal:'${player}':'${advancement}'>"
"advancementTask": "<lang:chat.type.advancement.task:'${player}':'${advancement}'>",
"advancementChallenge": "<lang:chat.type.advancement.challenge:'${player}':'${advancement}'>",
"advancementGoal": "<lang:chat.type.advancement.goal:'${player}':'${advancement}'>",
"teamChatSent": "<lang:'chat.type.team.sent':'<hover\\:\\'<lang\\:chat.type.team.hover>\\'><suggest_command\\:\\'/teammsg \\'>${team}':'${displayName}':'${message}'>",
"teamChatReceived": "<lang:'chat.type.team.text':'<hover\\:\\'<lang\\:chat.type.team.hover>\\'><suggest_command\\:\\'/teammsg \\'>${team}':'${displayName}':'${message}'>",
"privateMessageSent": "<gray>[<green>PM</green> → ${receiver}] <dark_gray>»<reset> ${message}",
"privateMessageReceived": "<gray>[<green>PM</green> ← ${sender}] <dark_gray>»<reset> ${message}",
"sayCommand": "<red>[${player}] ${message}",
"meCommand": "<green>* ${player} ${message}"
},
"permissionStyles": [
{
"permission": "group.test",
"permission": "group.admin",
"opLevel": 4,
"style": {
"displayName": "<dark_gray>[<dark_red>Admin</dark_red> | <yellow>%player:playtime%</yellow>]</dark_gray> <red>${vanillaDisplayName}</red>"
"displayName": "<dark_gray>[<red>Admin</red>]</dark_gray> <c:#ffe8a3>${vanillaDisplayName}</c>",
"chat": "${player} <dark_gray>»</dark_gray> <orange>${message}",
"death": ""
}
},
{
"permission": "group.admin",
"permission": "group.default",
"opLevel": 0,
"style": {
"displayName": "<dark_gray>[<dark_red>Admin</dark_red>]</dark_gray> <red>${vanillaDisplayName}</red>",
"chat": "${player} <dark_gray>»</dark_gray> <gold>${message}"
"displayName": "<dark_gray>[<aqua>Player</aqua>]</dark_gray> <dark_aqua>${vanillaDisplayName}</dark_aqua>"
}
}
],
"petDeathMessage": "Oh no! ${default_message}",
"emoticons": {
"bucket": "🪣",
"sword": "🗡",
"potion": "🧪",
"trident": "🔱",
"shears": "",
"rod": "🎣",
"fire": "🔥",
"shrug": "¯\\_(ツ)_/¯",
"bow": "🏹",
"bell": "<yellow>🔔",
"table": "<rb>(╯°□°)╯︵ ┻━┻",
"heart": "<red>❤"
},
"permissionEmoticons": [
{
"permission": "group.vip",
"opLevel": 3,
"emotes": {}
}
],
"legacyChatFormatting": true,
"parseLinksInChat": true,
"enableMarkdown": true,
"formattingInPrivateMessages": true,
"formattingInTeamMessages": true,
"linkStyle": "<underline><blue>${link}",
"spoilerStyle": "<dark_gray>${spoiler}",
"spoilerSymbol": "",
"defaultEnabledFormatting": {
"dark_red": true,
"dark_red": false,
"color": false,
"underline": true,
"yellow": false,
"insert": false,
"italic": false,
"italic": true,
"dark_blue": false,
"dark_purple": true,
"gold": true,
"dark_purple": false,
"gold": false,
"red": false,
"aqua": false,
"hover": false,
"gray": false,
"light_purple": false,
"white": false,
"pos": true,
"dark_gray": false,
"strikethrough": false,
"spoiler": true,
"strikethrough": true,
"lang": false,
"obfuscated": false,
"dark_grey": false,
"key": false,
"change_page": false,
"st": true,
"b": true,
"item": true,
"green": false,
"c": true,
"c": false,
"dark_green": false,
"gradient": false,
"black": false,
"bold": false,
"em": false,
"i": true,
"bold": true,
"gr": false,
"click": false,
"grey": false,
"orange": false,
"rb": false,
"rainbow": false,
"obf": false,
"colour": false,
"blue": false,
"dark_aqua": false,
"reset": true,
"underlined": false,
"reset": false,
"page": false,
"font": false
}
}
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation include(fabricApi.module("fabric-api-base", project.fabric_version))
modImplementation include(fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version))
modImplementation include(fabricApi.module("fabric-command-api-v1", project.fabric_version))


modImplementation include("eu.pb4:placeholder-api:1.0.0-rc2-1.17")
modImplementation include("eu.pb4:placeholder-api:1.1.1+1.17.1")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

modRuntime "supercoder79:databreaker:0.2.7"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.17
yarn_mappings=1.17+build.13
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.1
loader_version=0.11.3

# Mod Properties
mod_version = 1.1.0
mod_version = 1.2.0
maven_group = eu.pb4
archives_base_name = styled-chat

# Dependencies
fabric_version=0.34.9+1.17
fabric_version=0.40.1+1.17
69 changes: 69 additions & 0 deletions src/main/java/eu/pb4/styledchat/StyledChatEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package eu.pb4.styledchat;

import eu.pb4.placeholders.TextParser;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import java.util.function.BiConsumer;

public class StyledChatEvents {
/**
* Event ran for message content before they are formatted (Strings)
*/
public static final Event<PreMessageEvent> PRE_MESSAGE_CONTENT_SEND = EventFactory.createArrayBacked(PreMessageEvent.class, callbacks -> (message, player, filtered) -> {
for (var callback : callbacks) {
message = callback.onPreMessage(message, player, filtered);
}

return message;
});

/**
* Event ran for message content after it being formatted (Text)
*/
public static final Event<MessageEvent> MESSAGE_CONTENT_SEND = EventFactory.createArrayBacked(MessageEvent.class, callbacks -> (message, player, filtered) -> {
for (var callback : callbacks) {
message = callback.onMessage(message, player, filtered);
}

return message;
});

/**
* Event ran before message is send to someone, it is fully formatted (including template)
*/
public static final Event<MessageToEvent> MESSAGE_TO_SEND = EventFactory.createArrayBacked(MessageToEvent.class, callbacks -> (message, sender, receiver, filtered) -> {
for (var callback : callbacks) {
message = callback.onMessageTo(message, sender, receiver, filtered);
}

return message;
});

/**
* This event can be used to allow custom formatting
*/
public static final Event<FormattingCreationEvent> FORMATTING_CREATION_EVENT = EventFactory.createArrayBacked(FormattingCreationEvent.class, callbacks -> (player, builder) -> {
for (var callback : callbacks) {
callback.onFormattingBuild(player, builder);
}
});

public interface FormattingCreationEvent {
void onFormattingBuild(ServerPlayerEntity player, BiConsumer<String, TextParser.TextFormatterHandler> builder);
}

public interface PreMessageEvent {
String onPreMessage(String message, ServerPlayerEntity player, boolean filtered);
}

public interface MessageEvent {
Text onMessage(Text message, ServerPlayerEntity player, boolean filtered);
}

public interface MessageToEvent {
Text onMessageTo(Text message, ServerPlayerEntity sender, ServerPlayerEntity receiver, boolean filtered);
}
}
19 changes: 16 additions & 3 deletions src/main/java/eu/pb4/styledchat/StyledChatMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ public class StyledChatMod implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("Styled Chat");
public static String VERSION = FabricLoader.getInstance().getModContainer("styledchat").get().getMetadata().getVersion().getFriendlyString();

public static final String URL_REGEX = "(https?:\\/\\/[-a-zA-Z0-9@:%._\\+~#=]+\\.[^ ]+)";

@Override
public void onInitialize() {
this.crabboardDetection();
Commands.register();
ServerLifecycleEvents.SERVER_STARTING.register((s) -> ConfigManager.loadConfig());
ServerLifecycleEvents.SERVER_STARTING.register((s) -> {
this.crabboardDetection();
ConfigManager.loadConfig();
});
}

private void crabboardDetection() {
if (FabricLoader.getInstance().isModLoaded("cardboard")) {
LOGGER.error("");
LOGGER.error("Cardboard detected! This mod doesn't work with it!");
LOGGER.error("You won't get any support as long as it's present!");
LOGGER.error("");
LOGGER.error("Read more: https://gist.github.com/Patbox/e44844294c358b614d347d369b0fc3bf");
LOGGER.error("");
}
}
}
Loading

0 comments on commit 9f33f8d

Please sign in to comment.