Skip to content

Commit

Permalink
2.0.0! Fixes and improvements
Browse files Browse the repository at this point in the history
- New config format (v3), old (v2) configs will be automatically updated to it.
- Rewritten support for markdown and legacy formatting (aka &X) to make it more relable
- Replaced operator level/permission checks with more dynamic predicates, allowing way more flexibility, check https://github.com/Patbox/PredicateAPI for more info
- You can change styles via permission options (for LuckPerms it's Meta values), using `styled_chat.<path>`,
  where `<path>` is dot separated key names from style config (example `styled_chat.message_formats.chat`)
- You can now change style per player with `/styledchat set` command
- You can now enable chat formatting per style instead of it being only global + permission
- You can change style of pet death message, spoiler and urls with predicate-based styles (it was previously global)
- Fixed few bugs, including empty messages not working correctly
  • Loading branch information
Patbox committed Oct 16, 2022
1 parent e41352e commit a7c632f
Show file tree
Hide file tree
Showing 33 changed files with 1,687 additions and 697 deletions.
401 changes: 240 additions & 161 deletions README.md

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://maven.nucleoid.xyz' }
maven { url 'https://maven.gegy.dev' }

mavenLocal()
//mavenLocal()
}

dependencies {
Expand All @@ -43,11 +42,14 @@ dependencies {

modCompileOnly fabricApi.module("fabric-message-api-v1", project.fabric_version)

modImplementation include("eu.pb4:placeholder-api:2.0.0-beta.7+1.19")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")
modImplementation include("eu.pb4:predicate-api:0.1.0+1.19.2")
modImplementation include("eu.pb4:placeholder-api:2.0.0-pre.1+1.19.2")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
modImplementation include("eu.pb4:player-data-api:0.2.2+1.19.2")


modCompileOnly("fr.catcore:server-translations-api:1.4.16+1.19")
//modLocalRuntime("fr.catcore:server-translations-api:1.4.16+1.19")
modCompileOnly("fr.catcore:server-translations-api:1.4.17+1.19.2")
//modLocalRuntime("fr.catcore:server-translations-api:1.4.17+1.19.2")

//modRuntime "supercoder79:databreaker:0.2.7"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.14.8
fabric_version=0.59.0+1.19.2

# Mod Properties
mod_version = 1.4.1+1.19.2
mod_version = 2.0.0+1.19.2
maven_group = eu.pb4
archives_base_name = styled-chat

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/eu/pb4/styledchat/StyledChatMod.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package eu.pb4.styledchat;

import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.playerdata.api.PlayerDataApi;
import eu.pb4.styledchat.config.ConfigManager;
import eu.pb4.styledchat.other.GenericModInfo;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Decoration;
import net.minecraft.util.Identifier;
Expand All @@ -28,6 +29,8 @@ public class StyledChatMod implements ModInitializer {
@Override
public void onInitialize() {
this.crabboardDetection();
GenericModInfo.build(FabricLoader.getInstance().getModContainer("styledchat").get());
PlayerDataApi.register(StyledChatUtils.PLAYER_DATA);
Placeholders.registerChangeEvent((id, removed) -> ConfigManager.clearCached());
}

Expand Down
177 changes: 177 additions & 0 deletions src/main/java/eu/pb4/styledchat/StyledChatStyles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package eu.pb4.styledchat;

import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.styledchat.config.ConfigManager;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import java.util.Map;

public final class StyledChatStyles {
public static Text getDisplayName(ServerPlayerEntity player, Text vanillaDisplayName) {
var style = StyledChatUtils.getPersonalStyle(player).getDisplayName(player, vanillaDisplayName);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getDisplayName(player, vanillaDisplayName);
}

public static Text getChat(ServerPlayerEntity player, Text message) {
var style = StyledChatUtils.getPersonalStyle(player).getChat(player, message);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getChat(player, message);
}

public static Text getJoin(ServerPlayerEntity player) {
var style = StyledChatUtils.getPersonalStyle(player).getJoin(player);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getJoin(player);
}

public static Text getJoinFirstTime(ServerPlayerEntity player) {
var style = StyledChatUtils.getPersonalStyle(player).getJoinFirstTime(player);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getJoinFirstTime(player);
}

public static Text getJoinRenamed(ServerPlayerEntity player, String oldName) {
var style = StyledChatUtils.getPersonalStyle(player).getJoinRenamed(player, oldName);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getJoinRenamed(player, oldName);
}

public static Text getLeft(ServerPlayerEntity player) {
var style = StyledChatUtils.getPersonalStyle(player).getLeft(player);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getLeft(player);
}

public static Text getDeath(ServerPlayerEntity player, Text vanillaMessage) {
var style = StyledChatUtils.getPersonalStyle(player).getDeath(player, vanillaMessage);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getDeath(player, vanillaMessage);
}

public static Text getAdvancementTask(ServerPlayerEntity player, Text advancement) {
var style = StyledChatUtils.getPersonalStyle(player).getAdvancementTask(player, advancement);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getAdvancementTask(player, advancement);
}

public static Text getAdvancementGoal(ServerPlayerEntity player, Text advancement) {
var style = StyledChatUtils.getPersonalStyle(player).getAdvancementGoal(player, advancement);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getAdvancementGoal(player, advancement);
}

public static Text getAdvancementChallenge(ServerPlayerEntity player, Text advancement) {
var style = StyledChatUtils.getPersonalStyle(player).getAdvancementChallenge(player, advancement);
if (style != null) {
return style;
}

return ConfigManager.getConfig().getAdvancementChallenge(player, advancement);
}

public static Text getSayCommand(ServerCommandSource source, Text message) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getSayCommand(source, message);
if (style != null) {
return style;
}
}

return ConfigManager.getConfig().getSayCommand(source, message);
}

public static Text getMeCommand(ServerCommandSource source, Text message) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getMeCommand(source, message);
if (style != null) {
return style;
}
}

return ConfigManager.getConfig().getMeCommand(source, message);
}

public static Text getPrivateMessageSent(Text sender, Text receiver, Text message, ServerCommandSource source) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getPrivateMessageSent(sender, receiver, message, PlaceholderContext.of(source));
if (style != null) {
return style;
}
}

return ConfigManager.getConfig().getPrivateMessageSent(sender, receiver, message, source);
}

public static Text getPrivateMessageReceived(Text sender, Text receiver, Text message, ServerCommandSource source) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getPrivateMessageReceived(sender, receiver, message, PlaceholderContext.of(source));
if (style != null) {
return style;
}
}
return ConfigManager.getConfig().getPrivateMessageReceived(sender, receiver, message, source);
}

public static Text getTeamChatSent(Text team, Text displayName, Text message, ServerCommandSource source) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getTeamChatSent(team, displayName, message, source);
if (style != null) {
return style;
}
}

return ConfigManager.getConfig().getTeamChatSent(team, displayName, message, source);
}

public static Text getTeamChatReceived(Text team, Text displayName, Text message, ServerCommandSource source) {
if (source.isExecutedByPlayer()) {
var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getTeamChatReceived(team, displayName, message, source);
if (style != null) {
return style;
}
}

return ConfigManager.getConfig().getTeamChatReceived(team, displayName, message, source);
}

public static Text getPetDeath(TameableEntity entity, Text vanillaMessage) {
return ConfigManager.getConfig().getPetDeath(entity, vanillaMessage);
}

public static Map<String, TextNode> getEmotes(ServerCommandSource source) {
return ConfigManager.getConfig().getEmotes(source);

}
}
Loading

0 comments on commit a7c632f

Please sign in to comment.