diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48f6c91..f7478a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: matrix: # Use these Java versions java: [ - 16 # Minimum supported by Minecraft + 17 # Minimum supported by Minecraft ] # and run on both Linux and Windows os: [ubuntu-20.04, windows-latest] @@ -32,7 +32,7 @@ jobs: - name: build run: ./gradlew build - name: capture build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '16' }} # Only upload artifacts built from latest java on one OS + if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS uses: actions/upload-artifact@v2 with: name: Artifacts diff --git a/build.gradle b/build.gradle index 342859a..bdf9eba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '0.8-SNAPSHOT' + id 'fabric-loom' version '0.10-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 archivesBaseName = project.archives_base_name version = project.mod_version @@ -34,10 +34,10 @@ dependencies { 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.1.1+1.17.1") + modImplementation include("eu.pb4:placeholder-api:1.1.3+1.17.1") modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT") - modRuntime "supercoder79:databreaker:0.2.7" + //modRuntime "supercoder79:databreaker:0.2.7" // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. } @@ -58,7 +58,7 @@ tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 16 + it.options.release = 17 } java { diff --git a/gradle.properties b/gradle.properties index 77e7b2f..c396ea4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.17.1 - yarn_mappings=1.17.1+build.1 - loader_version=0.11.3 + minecraft_version=1.18-rc1 + yarn_mappings=1.18-rc1+build.1 + loader_version=0.12.5 + + #Fabric api + fabric_version=0.43.1+1.18 # Mod Properties - mod_version = 1.2.0 + mod_version = 1.2.1+1.18 maven_group = eu.pb4 archives_base_name = styled-chat # Dependencies - fabric_version=0.40.1+1.17 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 0730fe6..0a1ea99 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -7,14 +7,19 @@ import eu.pb4.styledchat.config.Config; import eu.pb4.styledchat.config.ConfigManager; import me.lucko.fabric.api.permissions.v0.Permissions; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; public final class StyledChatUtils { @@ -62,14 +67,8 @@ public static Map getHandlers(ServerPla } } - if (config.defaultFormattingCodes.getBoolean(ITEM_TAG) || - Permissions.check(source, FORMAT_PERMISSION_BASE + ITEM_TAG, 2)) { - handlers.put(ITEM_TAG, (tag, data, input, buildInHandlers, endAt) -> new GeneralUtils.TextLengthPair((MutableText) player.getStackInHand(Hand.MAIN_HAND).toHoverableText(), 0)); - } - - if (config.defaultFormattingCodes.getBoolean(SPOILER_TAG) || - Permissions.check(source, FORMAT_PERMISSION_BASE + SPOILER_TAG, 2)) { - handlers.put(SPOILER_TAG, SPOILER_TAG_HANDLER); + if (handlers.containsKey("light_purple")) { + handlers.put("pink", handlers.get("light_purple")); } if (config.defaultFormattingCodes.getBoolean(POS_TAG) || @@ -96,6 +95,17 @@ public static Map getHandlers(ServerPla return handlers; } + /** + * I need to rework things within Placeholder API, but I'm too lazy to do it rn. + * Whatever I will do it this thing will be replaced with proper thing (I might keep it for sake of backwards compatibility) + */ + public static Map getEmotes(ServerPlayerEntity player) { + return new FakeMapPlayer(player, ConfigManager.getConfig().getEmotes(player.getCommandSource())); + } + + public static Map getEmotes(MinecraftServer server) { + return new FakeMapServer(server, ConfigManager.getConfig().getEmotes(server.getCommandSource())); + } public static String formatMessage(String input, Map handlers) { var config = ConfigManager.getConfig(); @@ -131,7 +141,6 @@ public static String formatMessage(String input, Map$2"); - input = input.replaceAll(getMarkdownRegex("_", "_"), "$2"); } } } catch (Exception e) { @@ -144,4 +153,62 @@ public static String formatMessage(String input, Map[^" + base +"]+)(" + sides + ")"; } + + public static abstract class FakeMap extends AbstractMap { + private final Map texts; + private final Map cache = new HashMap<>(); + + public FakeMap(Map texts) { + this.texts = texts; + } + + @Override + public Text get(Object key) { + var text = this.cache.get(key); + if (text != null) { + return text; + } + + text = this.texts.get(key); + return text != null ? this.cache.put((String) key, this.getParsed(text)) : null; + } + + @NotNull + @Override + public Set> entrySet() { + return texts.entrySet(); + } + + public abstract Text getParsed(Text text); + } + + + public static class FakeMapPlayer extends FakeMap { + + private final ServerPlayerEntity player; + + public FakeMapPlayer(ServerPlayerEntity player, Map texts) { + super(texts); + this.player = player; + } + + @Override + public Text getParsed(Text text) { + return PlaceholderAPI.parseText(text, this.player); + } + } + + public static class FakeMapServer extends FakeMap { + private final MinecraftServer server; + + public FakeMapServer(MinecraftServer server, Map texts) { + super(texts); + this.server = server; + } + + @Override + public Text getParsed(Text text) { + return PlaceholderAPI.parseText(text, this.server); + } + } } 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 1024cdd..dc1140e 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java @@ -2,8 +2,12 @@ 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 java.util.*; @@ -63,6 +67,8 @@ private static Map getDefaultEmoticons() { map.put("shears", "✂"); map.put("bucket", "\uD83E\uDEA3"); map.put("bell", "\uD83D\uDD14"); + map.put(StyledChatUtils.ITEM_TAG, "[%player:equipment_slot/mainhand%]"); + map.put(StyledChatUtils.POS_TAG, "%player:pos_x% %player:pos_y% %player:pos_z%"); return map; } @@ -71,6 +77,18 @@ public static ConfigData transform(ConfigData configData) { for (Map.Entry entry : getDefaultFormatting().entrySet()) { configData.defaultEnabledFormatting.putIfAbsent(entry.getKey(), entry.getValue()); } + + if (configData.defaultEnabledFormatting.get(StyledChatUtils.ITEM_TAG)) { + configData.defaultEnabledFormatting.remove(StyledChatUtils.ITEM_TAG); + configData.emoticons.put(StyledChatUtils.ITEM_TAG, "[%player:equipment_slot/mainhand%]"); + } + + if (configData.defaultEnabledFormatting.get(StyledChatUtils.POS_TAG)) { + configData.defaultEnabledFormatting.remove(StyledChatUtils.POS_TAG); + configData.emoticons.put(StyledChatUtils.POS_TAG, "%player:pos_x% %player:pos_y% %player:pos_z%"); + } + + return configData; } diff --git a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java index b2f51cb..9af8e1f 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java @@ -9,12 +9,15 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.AbstractMap; import java.util.Map; +import java.util.Set; @Mixin(MeCommand.class) public class MeCommandMixin { @@ -25,14 +28,16 @@ private static void styledChat_formatText(CommandContext co Text message; Map formatting; + Map emotes; try { var player = source.getPlayer(); formatting = StyledChatUtils.getHandlers(player); + emotes = StyledChatUtils.getEmotes(player); } catch (Exception e) { formatting = TextParser.getRegisteredSafeTags(); + emotes = StyledChatUtils.getEmotes(context.getSource().getServer()); } - var emotes = config.getEmotes(source); if (formatting.size() != 0) { @@ -44,7 +49,13 @@ private static void styledChat_formatText(CommandContext co } if (emotes.size() != 0) { - message = PlaceholderAPI.parsePredefinedText(message, StyledChatUtils.EMOTE_PATTERN, emotes); + message = PlaceholderAPI.parsePredefinedText(message, StyledChatUtils.EMOTE_PATTERN, new AbstractMap() { + @NotNull + @Override + public Set> entrySet() { + return null; + } + }); } diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java index faa0c25..5f0935a 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java @@ -25,14 +25,16 @@ private static Text styledChat_formatText(Text message, ServerCommandSource sour var config = ConfigManager.getConfig(); if (config.configData.formattingInPrivateMessages) { Map formatting; + Map emotes; try { var player = source.getPlayer(); formatting = StyledChatUtils.getHandlers(player); + emotes = StyledChatUtils.getEmotes(player); } catch (Exception e) { formatting = TextParser.getRegisteredSafeTags(); + emotes = StyledChatUtils.getEmotes(source.getServer()); } - var emotes = config.getEmotes(source); if (formatting.size() != 0) { var ogMessage = message.getString(); diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java index 75e2c0c..47ec081 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java @@ -16,7 +16,7 @@ public class PlayerAdvancementTrackerMixin { @Shadow private ServerPlayerEntity owner; - @ModifyArg(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + @ModifyArg(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) private Text styledChat_changeAdvancementMessage(Text text) { TranslatableText translatableText = (TranslatableText) text; diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java index b7d9a77..b3291d6 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java @@ -35,7 +35,7 @@ private void styledChat_removeStoredPlayer(ClientConnection connection, ServerPl this.temporaryPlayer = null; } - @ModifyArg(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + @ModifyArg(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) private Text styledChat_updatePlayerNameAfterMessage(Text text) { if (this.temporaryPlayer.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.LEAVE_GAME)) == 0) { return ConfigManager.getConfig().getJoinFirstTime(this.temporaryPlayer); @@ -49,7 +49,7 @@ private Text styledChat_updatePlayerNameAfterMessage(Text text) { } } - @Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true) + @Inject(method = "broadcast", at = @At("HEAD"), cancellable = true) private void styledChat_excludeSendingOfHiddenMessages(Text message, MessageType type, UUID sender, CallbackInfo ci) { if (message instanceof TranslatableText text && text.getKey().equals(StyledChatUtils.IGNORED_TEXT_KEY)) { ci.cancel(); diff --git a/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java index 464ed80..605b184 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java @@ -33,14 +33,16 @@ private static Text styledChat_formatText(Text inputX, CommandContext formatting; + Map emotes; try { var player = source.getPlayer(); formatting = StyledChatUtils.getHandlers(player); + emotes = StyledChatUtils.getEmotes(player); } catch (Exception e) { formatting = TextParser.getRegisteredSafeTags(); + emotes = StyledChatUtils.getEmotes(context.getSource().getServer()); } - var emotes = config.getEmotes(source); if (formatting.size() != 0) { var formattedMessage = StyledChatUtils.formatMessage(inputAsString, formatting); diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java index a63d9a6..bff8231 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java @@ -31,7 +31,7 @@ public class ServerPlayNetworkManagerMixin { @Shadow public ServerPlayerEntity player; - @ModifyArg(method = "onDisconnected", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + @ModifyArg(method = "onDisconnected", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) private Text styledChat_replaceDisconnectMessage(Text text) { return ConfigManager.getConfig().getLeft(this.player); } @@ -40,7 +40,7 @@ private Text styledChat_replaceDisconnectMessage(Text text) { private void styledChat_replaceChatMessage(PlayerManager playerManager, Text serverMessage, Function playerMessageFactory, MessageType playerMessageType, UUID sender, TextStream.Message message) { var handlers = StyledChatUtils.getHandlers(this.player); Config config = ConfigManager.getConfig(); - var emotes = config.getEmotes(this.player.getCommandSource()); + var emotes = StyledChatUtils.getEmotes(this.player); String rawMessage = message.getRaw(); String filteredMessage = message.getFiltered(); diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java index 43cc179..f1702c5 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java @@ -18,7 +18,7 @@ @Mixin(ServerPlayerEntity.class) public class ServerPlayerEntityMixin { - @ModifyArg(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + @ModifyArg(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) private Text styledChat_replaceDeathMessage(Text text) { return ConfigManager.getConfig().getDeath((ServerPlayerEntity) (Object) this, text); } diff --git a/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java index 7e77818..71f75e9 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java @@ -28,16 +28,17 @@ private static Text styledChat_formatText(Text message, ServerCommandSource sour var config = ConfigManager.getConfig(); if (config.configData.formattingInTeamMessages) { Map formatting; + Map emotes; try { var player = source.getPlayer(); formatting = StyledChatUtils.getHandlers(player); + emotes = StyledChatUtils.getEmotes(player); } catch (Exception e) { formatting = TextParser.getRegisteredSafeTags(); + emotes = StyledChatUtils.getEmotes(source.getServer()); } - var emotes = config.getEmotes(source); - if (formatting.size() != 0) { var ogMessage = message.getString(); var parsed = PlaceholderAPI.parsePredefinedText(TextParser.parse(StyledChatUtils.formatMessage(ogMessage, formatting), formatting), StyledChatUtils.EMOTE_PATTERN, emotes); ; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7edd0b6..57462a5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,6 +26,6 @@ ], "depends": { - "minecraft": ">=1.17.x" + "minecraft": ">=1.18-rc.1" } }