From 7d90c43a58b313942c7f26e2494b88f4dad64f4c Mon Sep 17 00:00:00 2001 From: Wesley1808 <74668381+Wesley1808@users.noreply.github.com> Date: Sat, 27 Jan 2024 12:48:00 +0100 Subject: [PATCH] Improve player ping support --- build.gradle | 2 +- gradle.properties | 6 +++--- .../java/me/wesley1808/advancedchat/impl/utils/Util.java | 4 ++++ .../mixins/ServerGamePacketListenerImplMixin.java | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index e3dd986..656b599 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 7bc8f78..94e0b23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties minecraft_version=1.20.4 -loader_version=0.15.3 +loader_version=0.15.6 # Mod Properties mod_version=1.4 @@ -11,7 +11,7 @@ maven_group=me.wesley1808 archives_base_name=advancedchat # API dependencies -fabric_version=0.91.3+1.20.4 +fabric_version=0.96.0+1.20.4 placeholder_api_version=2.3.0+1.20.3 playerdata_api_version=0.4.0+1.20.3 predicate_api_version=0.3.0+1.20.2 @@ -19,4 +19,4 @@ permission_api_version=0.3-SNAPSHOT # Other dependencies styledchat_version=2.4.0+1.20.3 -vanish_version=1.5.0+1.20.3-rc1 +vanish_version=1.5.1+1.20.4 diff --git a/src/main/java/me/wesley1808/advancedchat/impl/utils/Util.java b/src/main/java/me/wesley1808/advancedchat/impl/utils/Util.java index b83defc..5dfd1ad 100644 --- a/src/main/java/me/wesley1808/advancedchat/impl/utils/Util.java +++ b/src/main/java/me/wesley1808/advancedchat/impl/utils/Util.java @@ -217,6 +217,10 @@ public static List map(Collection collection, Function functi return result; } + public static boolean isWhiteSpace(String string, int index) { + return index < 0 || index >= string.length() || Character.isWhitespace(string.charAt(index)); + } + public static CompletableFuture suggest(SuggestionsBuilder builder, Collection suggestions) { if (suggestions.isEmpty()) { return Suggestions.empty(); diff --git a/src/main/java/me/wesley1808/advancedchat/mixins/ServerGamePacketListenerImplMixin.java b/src/main/java/me/wesley1808/advancedchat/mixins/ServerGamePacketListenerImplMixin.java index b3429c6..e2fb543 100644 --- a/src/main/java/me/wesley1808/advancedchat/mixins/ServerGamePacketListenerImplMixin.java +++ b/src/main/java/me/wesley1808/advancedchat/mixins/ServerGamePacketListenerImplMixin.java @@ -36,8 +36,11 @@ public ServerGamePacketListenerImplMixin(MinecraftServer minecraftServer, Connec @Inject(method = "sendPlayerChatMessage", at = @At("HEAD")) private void advancedchat$onChatMessage(PlayerChatMessage message, ChatType.Bound bound, CallbackInfo ci) { - String pingName = '@' + this.player.getScoreboardName(); - if (message.signedContent().contains(pingName)) { + String playerName = this.player.getScoreboardName(); + String content = message.signedContent(); + int index = content.indexOf(playerName); + + if (index >= 0 && Util.isWhiteSpace(content, index - 1) && Util.isWhiteSpace(content, index + playerName.length())) { Util.playSound(this.player, Config.instance().chatPingSound); } }