diff --git a/gradle.properties b/gradle.properties index 290df9e..06a7b25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.18 - yarn_mappings=1.18+build.1 - loader_version=0.12.6 + minecraft_version=1.18.1 + yarn_mappings=1.18.1+build.1 + loader_version=0.12.12 #Fabric api - fabric_version=0.43.1+1.18 + fabric_version=0.45.0+1.18 # Mod Properties - mod_version = 1.2.2+1.18 + mod_version = 1.2.3+1.18 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 20dfad3..802093c 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -112,6 +112,20 @@ public static Map getEmotes(MinecraftServer server) { return new FakeMapServer(server, ConfigManager.getConfig().getEmotes(server.getCommandSource())); } + public static Text formatFor(ServerPlayerEntity player, String input) { + return PlaceholderAPI.parsePredefinedText( + TextParser.parse(StyledChatUtils.formatMessage(input, getHandlers(player))), + EMOTE_PATTERN, getEmotes(player) + ); + } + + public static Text formatFor(MinecraftServer server, String input) { + return PlaceholderAPI.parsePredefinedText( + TextParser.parse(StyledChatUtils.formatMessage(input, TextParser.getRegisteredTags())), + EMOTE_PATTERN, getEmotes(server) + ); + } + public static String formatMessage(String input, Map handlers) { var config = ConfigManager.getConfig(); if (handlers.containsKey(StyledChatUtils.LINK_TAG)) { diff --git a/src/main/java/eu/pb4/styledchat/command/Commands.java b/src/main/java/eu/pb4/styledchat/command/Commands.java index 26f91b7..95abd6e 100644 --- a/src/main/java/eu/pb4/styledchat/command/Commands.java +++ b/src/main/java/eu/pb4/styledchat/command/Commands.java @@ -3,23 +3,18 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; -import eu.pb4.placeholders.TextParser; import eu.pb4.styledchat.StyledChatMod; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.command.argument.TextArgumentType; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.text.Texts; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Util; -import java.util.Iterator; - import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -45,7 +40,13 @@ public static void register() { .then(argument("message", StringArgumentType.greedyString()) .executes((context) -> { int i = 0; - var parsed = TextParser.parse(StyledChatUtils.formatMessage(context.getArgument("message", String.class), TextParser.getRegisteredTags())); + Text parsed; + try { + parsed = StyledChatUtils.formatFor(context.getSource().getPlayer(), context.getArgument("message", String.class)); + } catch (Exception e) { + parsed = StyledChatUtils.formatFor(context.getSource().getServer(), context.getArgument("message", String.class)); + + } for (var player : EntityArgumentType.getPlayers(context, "targets")) { player.sendSystemMessage(parsed, Util.NIL_UUID); @@ -64,7 +65,7 @@ private static int reloadConfig(CommandContext context) { if (ConfigManager.loadConfig()) { context.getSource().sendFeedback(new LiteralText("Reloaded config!"), false); } else { - context.getSource().sendError(new LiteralText("Error accrued while reloading config!").formatted(Formatting.RED)); + context.getSource().sendError(new LiteralText("Error occurred while reloading config! Check console for more information!").formatted(Formatting.RED)); } return 1; diff --git a/src/main/java/eu/pb4/styledchat/config/ChatStyle.java b/src/main/java/eu/pb4/styledchat/config/ChatStyle.java index 2c6876c..521099a 100644 --- a/src/main/java/eu/pb4/styledchat/config/ChatStyle.java +++ b/src/main/java/eu/pb4/styledchat/config/ChatStyle.java @@ -73,7 +73,7 @@ public ChatStyle(ChatStyleData data) { public Text getDisplayName(ServerPlayerEntity player, Text vanillaDisplayName) { if (this.displayName == null) { return null; - } else if (this.advancementGoal == StyledChatUtils.IGNORED_TEXT) { + } else if (this.displayName == StyledChatUtils.IGNORED_TEXT) { return vanillaDisplayName; } @@ -81,6 +81,8 @@ public Text getDisplayName(ServerPlayerEntity player, Text vanillaDisplayName) { PlaceholderAPI.parseText(this.displayName, player), PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN, Map.of("vanillaDisplayName", vanillaDisplayName, + "player", vanillaDisplayName, + "default", vanillaDisplayName, "name", player.getName()) ); } diff --git a/src/main/java/eu/pb4/styledchat/config/ConfigManager.java b/src/main/java/eu/pb4/styledchat/config/ConfigManager.java index 572a8ae..a9ed71f 100644 --- a/src/main/java/eu/pb4/styledchat/config/ConfigManager.java +++ b/src/main/java/eu/pb4/styledchat/config/ConfigManager.java @@ -10,26 +10,26 @@ import org.apache.commons.io.IOUtils; import java.io.*; +import java.nio.charset.StandardCharsets; public class ConfigManager { public static final int VERSION = 2; private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().setLenient().create(); - private static Config CONFIG; + private static Config CONFIG = null; public static Config getConfig() { return CONFIG; } public static boolean loadConfig() { - CONFIG = null; try { ConfigData config; File configFile = new File(FabricLoader.getInstance().getConfigDir().toFile(), "styled-chat.json"); if (configFile.exists()) { - String json = IOUtils.toString(new InputStreamReader(new FileInputStream(configFile), "UTF-8")); + String json = IOUtils.toString(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)); VersionConfigData versionConfigData = GSON.fromJson(json, VersionConfigData.class); config = ConfigData.transform(switch (versionConfigData.CONFIG_VERSION_DONT_TOUCH_THIS) { @@ -42,18 +42,19 @@ public static boolean loadConfig() { config = new ConfigData(); } - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8")); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8)); writer.write(GSON.toJson(config)); writer.close(); CONFIG = new Config(config); return true; - } - catch(IOException exception) { - StyledChatMod.LOGGER.error("Something went wrong while reading config!"); + } catch(Exception exception) { + StyledChatMod.LOGGER.error("Something went wrong while reading config! Make sure format is correct!"); exception.printStackTrace(); - CONFIG = new Config(new ConfigData()); + if (CONFIG == null) { + CONFIG = new Config(new ConfigData()); + } return false; } } diff --git a/src/main/java/eu/pb4/styledchat/config/data/ChatStyleData.java b/src/main/java/eu/pb4/styledchat/config/data/ChatStyleData.java index abbd06f..1a297b7 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ChatStyleData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ChatStyleData.java @@ -26,14 +26,14 @@ public class ChatStyleData { private static ChatStyleData getDefault() { ChatStyleData data = new ChatStyleData(); - data.displayName = "${vanillaDisplayName}"; + data.displayName = "${default}"; data.chat = "<${player}> ${message}"; data.join = ""; data.joinRenamed = ""; data.joinFirstTime = ""; data.left = ""; data.death = "${default_message}"; - data.advancementTask = "<>"; + data.advancementTask = ""; data.advancementGoal = ""; data.advancementChallenge = ""; data.teamChatSent = "\\'>${team}':'${displayName}':'${message}'>"; @@ -51,6 +51,7 @@ public void fillMissing() { this.chat = Objects.requireNonNullElse(this.chat, DEFAULT.chat); this.join = Objects.requireNonNullElse(this.join, DEFAULT.join); this.joinRenamed = Objects.requireNonNullElse(this.joinRenamed, DEFAULT.joinRenamed); + this.joinFirstTime = Objects.requireNonNullElse(this.joinFirstTime, DEFAULT.joinFirstTime); this.left = Objects.requireNonNullElse(this.left, DEFAULT.left); this.death = Objects.requireNonNullElse(this.death, DEFAULT.death); this.advancementTask = Objects.requireNonNullElse(this.advancementTask, DEFAULT.advancementTask); diff --git a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java index 7e0146a..6aa1687 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java @@ -1,13 +1,9 @@ package eu.pb4.styledchat.config.data; -import com.mojang.serialization.RecordBuilder; import eu.pb4.placeholders.TextParser; -import eu.pb4.placeholders.util.GeneralUtils; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; -import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.text.MutableText; -import net.minecraft.util.Hand; +import net.minecraft.util.Formatting; import java.util.*; @@ -22,18 +18,17 @@ public class ConfigData { public List permissionEmoticons = new ArrayList<>(); - public boolean legacyChatFormatting = false; + public boolean legacyChatFormatting = true; public boolean parseLinksInChat = true; public boolean enableMarkdown = true; public boolean formattingInPrivateMessages = true; public boolean formattingInTeamMessages = true; - public String linkStyle = "${link}"; + public String linkStyle = "${link}"; public String spoilerStyle = "${spoiler}"; public String spoilerSymbol = "▌"; public HashMap defaultEnabledFormatting = getDefaultFormatting(); - private static HashMap getDefaultFormatting() { HashMap map = new HashMap<>(); for (String string : TextParser.getRegisteredSafeTags().keySet()) { @@ -49,6 +44,13 @@ private static HashMap getDefaultFormatting() { map.put("strikethrough", true); map.put("st", true); map.put("underline", true); + + for (var formatting : Formatting.values()) { + if (formatting.isColor()) { + map.put(formatting.getName(), true); + } + } + return map; } diff --git a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java index 9af8e1f..e7fba5f 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java @@ -49,13 +49,7 @@ private static void styledChat_formatText(CommandContext co } if (emotes.size() != 0) { - message = PlaceholderAPI.parsePredefinedText(message, StyledChatUtils.EMOTE_PATTERN, new AbstractMap() { - @NotNull - @Override - public Set> entrySet() { - return null; - } - }); + message = PlaceholderAPI.parsePredefinedText(message, StyledChatUtils.EMOTE_PATTERN, emotes); } diff --git a/src/main/resources/assets/icon.png b/src/main/resources/assets/icon.png new file mode 100644 index 0000000..f13ec8f Binary files /dev/null and b/src/main/resources/assets/icon.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 57462a5..98a59ab 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -14,7 +14,7 @@ }, "license": "LGPLv3", - + "icon": "./assets/icon.png", "environment": "*", "entrypoints": { "main": [ @@ -27,5 +27,12 @@ "depends": { "minecraft": ">=1.18-rc.1" + }, + "custom": { + "modmenu": { + "links": { + "modmenu.discord": "https://pb4.eu/discord" + } + } } }